def test_executor_should_delete_incomplete_downloads(config, io, tmp_dir, mocker, pool, mock_file_downloads): fixture = Path(__file__).parent.parent.joinpath( "fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl") destination_fixture = Path(tmp_dir) / "tomlkit-0.5.3-py2.py3-none-any.whl" shutil.copyfile(str(fixture), str(destination_fixture)) mocker.patch( "poetry.installation.executor.Executor._download_archive", side_effect=Exception("Download error"), ) mocker.patch( "poetry.installation.chef.Chef.get_cached_archive_for_link", side_effect=lambda link: link, ) mocker.patch( "poetry.installation.chef.Chef.get_cache_directory_for_link", return_value=Path(tmp_dir), ) config = Config() config.merge({"cache-dir": tmp_dir}) env = MockEnv(path=Path(tmp_dir)) executor = Executor(env, pool, config, io) with pytest.raises(Exception, match="Download error"): executor._download(Install(Package("tomlkit", "0.5.3"))) assert not destination_fixture.exists()
def test_execute_works_with_ansi_output(mocker, config, pool, io_decorated, tmp_dir, mock_file_downloads, env): config = Config() config.merge({"cache-dir": tmp_dir}) executor = Executor(env, pool, config, io_decorated) install_output = ( "some string that does not contain a keyb0ard !nterrupt or cance11ed by u$er" ) mocker.patch.object(env, "_run", return_value=install_output) return_code = executor.execute([ Install(Package("pytest", "3.5.2")), ]) env._run.assert_called_once() expected = [ "\x1b[39;1mPackage operations\x1b[39;22m: \x1b[34m1\x1b[39m install, \x1b[34m0\x1b[39m updates, \x1b[34m0\x1b[39m removals", "\x1b[34;1m•\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mpytest\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m3.5.2\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mPending...\x1b[39m", "\x1b[34;1m•\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mpytest\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m3.5.2\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mDownloading...\x1b[39m", "\x1b[34;1m•\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mpytest\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m3.5.2\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mInstalling...\x1b[39m", "\x1b[32;1m•\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mpytest\x1b[39m\x1b[39m (\x1b[39m\x1b[32m3.5.2\x1b[39m\x1b[39m)\x1b[39m", # finished ] output = io_decorated.fetch_output() # hint: use print(repr(output)) if you need to debug this for line in expected: assert line in output assert 0 == return_code
def test_execute_works_with_no_ansi_output(mocker, config, pool, io_not_decorated, tmp_dir, mock_file_downloads, env): config = Config() config.merge({"cache-dir": tmp_dir}) executor = Executor(env, pool, config, io_not_decorated) install_output = ( "some string that does not contain a keyb0ard !nterrupt or cance11ed by u$er" ) mocker.patch.object(env, "_run", return_value=install_output) return_code = executor.execute([ Install(Package("pytest", "3.5.2")), ]) env._run.assert_called_once() expected = """ Package operations: 1 install, 0 updates, 0 removals • Installing pytest (3.5.2) """ expected = set(expected.splitlines()) output = set(io_not_decorated.fetch_output().splitlines()) assert expected == output assert 0 == return_code
def create_config(cls, io: Optional["IO"] = None) -> Config: if io is None: io = NullIO() config = Config() # Load global config config_file = TOMLFile(Path(CONFIG_DIR) / "config.toml") if config_file.exists(): if io.is_debug(): io.write_line( f"<debug>Loading configuration file {config_file.path}</debug>" ) config.merge(config_file.read()) config.set_config_source(FileConfigSource(config_file)) # Load global auth config auth_config_file = TOMLFile(Path(CONFIG_DIR) / "auth.toml") if auth_config_file.exists(): if io.is_debug(): io.write_line( f"<debug>Loading configuration file {auth_config_file.path}</debug>" ) config.merge(auth_config_file.read()) config.set_auth_config_source(FileConfigSource(auth_config_file)) return config
def _update_with_new_method(self, version): from poetry.config.config import Config from poetry.core.packages.dependency import Dependency from poetry.core.packages.project_package import ProjectPackage from poetry.installation.installer import Installer from poetry.packages.locker import NullLocker from poetry.repositories.installed_repository import InstalledRepository from poetry.utils.env import EnvManager env = EnvManager.get_system_env(naive=True) installed = InstalledRepository.load(env) root = ProjectPackage("poetry-updater", "0.0.0") root.python_versions = ".".join(str(c) for c in env.version_info[:3]) root.add_dependency(Dependency("poetry", version.text)) installer = Installer( self.io, env, root, NullLocker(self.data_dir.joinpath("poetry.lock"), {}), self.pool, Config(), installed=installed, ) installer.update(True) installer.run()
def test_execute_executes_a_batch_of_operations( config, pool, io, tmp_dir, mock_file_downloads ): config = Config() config.merge({"cache-dir": tmp_dir}) env = MockEnv(path=Path(tmp_dir)) executor = Executor(env, pool, config, io) file_package = Package("demo", "0.1.0") file_package.source_type = "file" file_package.source_url = str( Path(__file__) .parent.parent.joinpath( "fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl" ) .resolve() ) directory_package = Package("simple-project", "1.2.3") directory_package.source_type = "directory" directory_package.source_url = str( Path(__file__).parent.parent.joinpath("fixtures/simple_project").resolve() ) git_package = Package("demo", "0.1.0") git_package.source_type = "git" git_package.source_reference = "master" git_package.source_url = "https://github.com/demo/demo.git" assert 0 == executor.execute( [ Install(Package("pytest", "3.5.2")), Uninstall(Package("attrs", "17.4.0")), Update(Package("requests", "2.18.3"), Package("requests", "2.18.4")), Uninstall(Package("clikit", "0.2.3")).skip("Not currently installed"), Install(file_package), Install(directory_package), Install(git_package), ] ) expected = """ Package operations: 4 installs, 1 update, 1 removal • Installing pytest (3.5.2) • Removing attrs (17.4.0) • Updating requests (2.18.3 -> 2.18.4) • Installing demo (0.1.0 {}) • Installing simple-project (1.2.3 {}) • Installing demo (0.1.0 master) """.format( file_package.source_url, directory_package.source_url ) expected = set(expected.splitlines()) output = set(io.fetch_output().splitlines()) assert expected == output assert 5 == len(env.executed)
def __init__( self, name: str, url: str, config: Config | None = None, disable_cache: bool = False, cert: Path | None = None, client_cert: Path | None = None, ) -> None: if name == "pypi": raise ValueError("The name [pypi] is reserved for repositories") self._packages = [] self._name = name self._url = url.rstrip("/") self._client_cert = client_cert self._cert = cert self._cache_dir = REPOSITORY_CACHE_DIR / name self._cache = CacheManager({ "default": "releases", "serializer": "json", "stores": { "releases": { "driver": "file", "path": str(self._cache_dir) }, "packages": { "driver": "dict" }, "matches": { "driver": "dict" }, }, }) self._authenticator = Authenticator( config=config or Config(use_environment=True)) self._session = CacheControl(self._authenticator.session, cache=FileCache( str(self._cache_dir / "_http"))) username, password = self._authenticator.get_credentials_for_url( self._url) if username is not None and password is not None: self._authenticator.session.auth = requests.auth.HTTPBasicAuth( username, password) if self._cert: self._authenticator.session.verify = str(self._cert) if self._client_cert: self._authenticator.session.cert = str(self._client_cert) self._disable_cache = disable_cache
def test_execute_shows_skipped_operations_if_verbose(config, pool, io): config = Config() config.merge({"cache-dir": "/foo"}) env = MockEnv() executor = Executor(env, pool, config, io) executor.verbose() assert 0 == executor.execute([ Uninstall(Package("clikit", "0.2.3")).skip("Not currently installed") ]) expected = """ Package operations: 0 installs, 0 updates, 0 removals, 1 skipped • Removing clikit (0.2.3): Skipped for the following reason: Not currently installed """ assert expected == io.fetch_output() assert 0 == len(env.executed)
def test_execute_executes_a_batch_of_operations(mocker, config, pool, io, tmp_dir, mock_file_downloads, env): pip_editable_install = mocker.patch( "poetry.installation.executor.pip_editable_install", unsafe=not PY36) config = Config() config.merge({"cache-dir": tmp_dir}) executor = Executor(env, pool, config, io) file_package = Package( "demo", "0.1.0", source_type="file", source_url=Path(__file__).parent.parent.joinpath( "fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl").resolve( ).as_posix(), ) directory_package = Package( "simple-project", "1.2.3", source_type="directory", source_url=Path(__file__).parent.parent.joinpath( "fixtures/simple_project").resolve().as_posix(), ) git_package = Package( "demo", "0.1.0", source_type="git", source_reference="master", source_url="https://github.com/demo/demo.git", develop=True, ) return_code = executor.execute([ Install(Package("pytest", "3.5.2")), Uninstall(Package("attrs", "17.4.0")), Update(Package("requests", "2.18.3"), Package("requests", "2.18.4")), Uninstall(Package("clikit", "0.2.3")).skip("Not currently installed"), Install(file_package), Install(directory_package), Install(git_package), ]) expected = """ Package operations: 4 installs, 1 update, 1 removal • Installing pytest (3.5.2) • Removing attrs (17.4.0) • Updating requests (2.18.3 -> 2.18.4) • Installing demo (0.1.0 {}) • Installing simple-project (1.2.3 {}) • Installing demo (0.1.0 master) """.format(file_package.source_url, directory_package.source_url) expected = set(expected.splitlines()) output = set(io.fetch_output().splitlines()) assert expected == output assert 5 == len(env.executed) assert 0 == return_code pip_editable_install.assert_called_once()
def __init__(self, config=None): # type: (Config) -> None if config is None: config = Config() self._config = config