def _upload_env_from_venv( package_path: str, packer=packaging.PEX_PACKER, additional_packages: Dict[str, str] = {}, ignored_packages: Collection[str] = [], resolved_fs=None, force_upload: bool = False, ): current_packages = { package["name"]: package["version"] for package in packaging.get_non_editable_requirements() } _handle_packages(current_packages, additional_packages, ignored_packages) _logger.debug(f"Packaging current_packages={current_packages}") if force_upload or not _is_archive_up_to_date( package_path, current_packages, resolved_fs): _logger.info(f"Zipping and uploading your env to {package_path}") with tempfile.TemporaryDirectory() as tempdir: archive_local = packer.pack( output=f"{tempdir}/{packer.env_name}.{packer.extension}", reqs=current_packages, additional_packages=additional_packages, ignored_packages=ignored_packages) dir = os.path.dirname(package_path) if not resolved_fs.exists(dir): resolved_fs.mkdir(dir) resolved_fs.put(archive_local, package_path) _dump_archive_metadata(package_path, current_packages, resolved_fs) else: _logger.info(f"{package_path} already exists")
def test_get_non_editable_requirements(): with tempfile.TemporaryDirectory() as tempdir: _create_venv(tempdir) _pip_install(tempdir) non_editable_requirements = packaging.get_non_editable_requirements( f"{tempdir}/bin/python") assert len(non_editable_requirements) == 1 assert list(non_editable_requirements.keys())[0] == "cloudpickle"
def test_get_empty_non_editable_requirements(): with tempfile.TemporaryDirectory() as tempdir: _create_venv(tempdir) subprocess.check_call([ f"{tempdir}/bin/python", "-m", "pip", "install", "-e", _get_editable_package_name(), "pip==18.1" ]) non_editable_requirements = packaging.get_non_editable_requirements( f"{tempdir}/bin/python") assert len(non_editable_requirements) == 0