diff --git a/poetry/factory.py b/poetry/factory.py index 144bfe35871..afefabb99f9 100644 --- a/poetry/factory.py +++ b/poetry/factory.py @@ -4,7 +4,6 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Dict -from typing import List from typing import Optional from cleo.io.io import IO @@ -25,6 +24,7 @@ if TYPE_CHECKING: from .repositories.legacy_repository import LegacyRepository + from .repositories.pool import Pool class Factory(BaseFactory): @@ -80,11 +80,18 @@ def create_poetry( config, ) - # Configuring sources - self.configure_sources( - poetry, poetry.local_config.get("source", []), config, io + config.merge( + { + "sources": { + source["name"]: source + for source in poetry.local_config.get("source", []) + } + } ) + # Configuring sources + poetry.set_pool(self.create_pool(config, io)) + plugin_manager = PluginManager("plugin", disable_plugins=disable_plugins) plugin_manager.load_plugins() poetry.set_plugin_manager(plugin_manager) @@ -133,10 +140,15 @@ def create_config(cls, io: Optional[IO] = None) -> Config: return config @classmethod - def configure_sources( - cls, poetry: "Poetry", sources: List[Dict[str, str]], config: "Config", io: "IO" - ) -> None: - for source in sources: + def create_pool(cls, config: "Config", io: Optional["IO"] = None) -> "Pool": + from poetry.repositories.pool import Pool + + if io is None: + io = NullIO() + + pool = Pool() + + for source_name, source in config.get("sources").items(): repository = cls.create_legacy_repository(source, config) is_default = source.get("default", False) is_secondary = source.get("secondary", False) @@ -151,17 +163,19 @@ def configure_sources( io.write_line(message) - poetry.pool.add_repository(repository, is_default, secondary=is_secondary) + pool.add_repository(repository, is_default, secondary=is_secondary) # Put PyPI last to prefer private repositories # unless we have no default source AND no primary sources # (default = false, secondary = false) - if poetry.pool.has_default(): + if pool.has_default(): if io.is_debug(): io.write_line("Deactivating the PyPI repository") else: - default = not poetry.pool.has_primary_repositories() - poetry.pool.add_repository(PyPiRepository(), default, not default) + default = not pool.has_primary_repositories() + pool.add_repository(PyPiRepository(), default, not default) + + return pool @classmethod def create_legacy_repository( diff --git a/poetry/installation/chef.py b/poetry/installation/chef.py index e4567357fc2..7e07d4f1561 100644 --- a/poetry/installation/chef.py +++ b/poetry/installation/chef.py @@ -23,15 +23,15 @@ if TYPE_CHECKING: - from poetry.config.config import Config from poetry.utils.env import Env from poetry.utils.env import EnvManager class IsolatedEnv(BaseIsolatedEnv): - def __init__(self, env: "Env") -> None: + def __init__(self, env: "Env", config: "Config") -> None: self._env = env + self._config = config @property def executable(self) -> str: @@ -50,8 +50,6 @@ def install(self, requirements) -> None: from poetry.installation.installer import Installer from poetry.packages.locker import NullLocker from poetry.repositories.installed_repository import InstalledRepository - from poetry.repositories.pool import Pool - from poetry.repositories.pypi_repository import PyPiRepository # We build Poetry dependencies from the requirements package = ProjectPackage("__root__", "0.0.0") @@ -60,8 +58,7 @@ def install(self, requirements) -> None: dependency = Dependency.create_from_pep_508(requirement) package.add_dependency(dependency) - pool = Pool() - pool.add_repository(PyPiRepository()) + pool = Factory.create_pool(self._config) installer = Installer( NullIO(), self._env, @@ -134,7 +131,7 @@ def _prepare(self, directory: Path, destination: Path) -> Path: with temporary_directory() as tmp_dir: EnvManager.build_venv(tmp_dir, executable=self._env.python, with_pip=True) venv = VirtualEnv(Path(tmp_dir)) - env = IsolatedEnv(venv) + env = IsolatedEnv(venv, self._config) builder = ProjectBuilder( directory, python_executable=env.executable, diff --git a/tests/console/commands/plugin/conftest.py b/tests/console/commands/plugin/conftest.py index 84509c81172..b916c73b159 100644 --- a/tests/console/commands/plugin/conftest.py +++ b/tests/console/commands/plugin/conftest.py @@ -17,19 +17,18 @@ def installed(): return repository -def configure_sources_factory(repo): - def _configure_sources(poetry, sources, config, io): # noqa +def create_pool_factory(repo): + def _create_pool(config, io): # noqa pool = Pool() pool.add_repository(repo) - poetry.set_pool(pool) - return _configure_sources + return pool + + return _create_pool @pytest.fixture(autouse=True) def setup_mocks(mocker, env, repo, installed): mocker.patch.object(EnvManager, "get_system_env", return_value=env) mocker.patch.object(InstalledRepository, "load", return_value=installed) - mocker.patch.object( - Factory, "configure_sources", side_effect=configure_sources_factory(repo) - ) + mocker.patch.object(Factory, "create_pool", side_effect=create_pool_factory(repo)) diff --git a/tests/fixtures/distributions/demo-0.1.0.tar.gz b/tests/fixtures/distributions/demo-0.1.0.tar.gz index 133b64421f8..42e4933130e 100644 Binary files a/tests/fixtures/distributions/demo-0.1.0.tar.gz and b/tests/fixtures/distributions/demo-0.1.0.tar.gz differ diff --git a/tests/installation/test_chef.py b/tests/installation/test_chef.py index 7fa45752653..136081b131b 100644 --- a/tests/installation/test_chef.py +++ b/tests/installation/test_chef.py @@ -1,11 +1,30 @@ from pathlib import Path +import pytest + from packaging.tags import Tag from poetry.core.packages.utils.link import Link +from poetry.factory import Factory from poetry.installation.chef import Chef +from poetry.repositories import Pool from poetry.utils.env import EnvManager from poetry.utils.env import MockEnv +from tests.repositories.test_pypi_repository import MockRepository + + +@pytest.fixture() +def pool(): + pool = Pool() + + pool.add_repository(MockRepository()) + + return pool + + +@pytest.fixture(autouse=True) +def setup(mocker, pool): + mocker.patch.object(Factory, "create_pool", return_value=pool) def test_get_cached_archive_for_link(config, mocker): @@ -99,7 +118,7 @@ def test_prepare_sdist(config, config_cache_dir): wheel = chef.prepare(archive) assert wheel.parent == destination - assert wheel.name == "demo-0.1.0-py3-none-any.whl" + assert wheel.name == "demo-0.1.0-py2.py3-none-any.whl" def test_prepare_directory(config, config_cache_dir): diff --git a/tests/repositories/fixtures/pypi.org/dists/poetry_core-1.0.3-py2.py3-none-any.whl b/tests/repositories/fixtures/pypi.org/dists/poetry_core-1.0.3-py2.py3-none-any.whl new file mode 100644 index 00000000000..dc468143f43 Binary files /dev/null and b/tests/repositories/fixtures/pypi.org/dists/poetry_core-1.0.3-py2.py3-none-any.whl differ diff --git a/tests/repositories/fixtures/pypi.org/json/poetry-core.json b/tests/repositories/fixtures/pypi.org/json/poetry-core.json new file mode 100644 index 00000000000..51eb4dbd135 --- /dev/null +++ b/tests/repositories/fixtures/pypi.org/json/poetry-core.json @@ -0,0 +1,143 @@ +{ + "info": { + "author": "Sébastien Eustace", + "author_email": "sebastien@eustace.io", + "bugtrack_url": null, + "classifiers": [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules" + ], + "description": "", + "description_content_type": "text/markdown", + "docs_url": null, + "download_url": "", + "downloads": { + "last_day": -1, + "last_month": -1, + "last_week": -1 + }, + "home_page": "https://github.com/python-poetry/poetry-core", + "keywords": "packaging,dependency,poetry", + "license": "MIT", + "maintainer": "", + "maintainer_email": "", + "name": "poetry-core", + "package_url": "https://pypi.org/project/poetry-core/", + "platform": "", + "project_url": "https://pypi.org/project/poetry-core/", + "project_urls": { + "Bug Tracker": "https://github.com/python-poetry/poetry/issues", + "Homepage": "https://github.com/python-poetry/poetry-core", + "Repository": "https://github.com/python-poetry/poetry-core" + }, + "release_url": "https://pypi.org/project/poetry-core/1.0.3/", + "requires_dist": [ + "importlib-metadata (>=1.7.0,<2.0.0); python_version >= \"2.7\" and python_version < \"2.8\" or python_version >= \"3.5\" and python_version < \"3.8\"", + "pathlib2 (>=2.3.5,<3.0.0); python_version >= \"2.7\" and python_version < \"2.8\"", + "typing (>=3.7.4.1,<4.0.0.0); python_version >= \"2.7\" and python_version < \"2.8\"", + "enum34 (>=1.1.10,<2.0.0); python_version >= \"2.7\" and python_version < \"2.8\"", + "functools32 (>=3.2.3-2,<4.0.0); python_version >= \"2.7\" and python_version < \"2.8\"" + ], + "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + "summary": "Poetry PEP 517 Build Backend", + "version": "1.0.3", + "yanked": false, + "yanked_reason": null + }, + "last_serial": 10427564, + "releases": { + "1.0.3": [ + { + "comment_text": "", + "digests": { + "md5": "16ce2526c342c1305d541425d406e35e", + "sha256": "c6bde46251112de8384013e1ab8d66e7323d2c75172f80220aba2bc07e208e9a" + }, + "downloads": -1, + "filename": "poetry_core-1.0.3-py2.py3-none-any.whl", + "has_sig": false, + "md5_digest": "16ce2526c342c1305d541425d406e35e", + "packagetype": "bdist_wheel", + "python_version": "py2.py3", + "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + "size": 424184, + "upload_time": "2021-04-09T15:44:41", + "upload_time_iso_8601": "2021-04-09T15:44:41.970294Z", + "url": "https://files.pythonhosted.org/packages/bf/e1/08c7478df1e93dea47b06c9d9a80dbb54af7421462e1b22c280d063df807/poetry_core-1.0.3-py2.py3-none-any.whl", + "yanked": false, + "yanked_reason": null + }, + { + "comment_text": "", + "digests": { + "md5": "dc82606f54a984a99daf8864cca1f028", + "sha256": "2315c928249fc3207801a81868b64c66273077b26c8d8da465dccf8f488c90c5" + }, + "downloads": -1, + "filename": "poetry-core-1.0.3.tar.gz", + "has_sig": false, + "md5_digest": "dc82606f54a984a99daf8864cca1f028", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + "size": 345626, + "upload_time": "2021-04-09T15:44:40", + "upload_time_iso_8601": "2021-04-09T15:44:40.639806Z", + "url": "https://files.pythonhosted.org/packages/d0/b3/1017f2f6d801f1e3e4ffee3f058a10d20df1a9560aba9c5b49e92cdd9912/poetry-core-1.0.3.tar.gz", + "yanked": false, + "yanked_reason": null + } + ] + }, + "urls": [ + { + "comment_text": "", + "digests": { + "md5": "16ce2526c342c1305d541425d406e35e", + "sha256": "c6bde46251112de8384013e1ab8d66e7323d2c75172f80220aba2bc07e208e9a" + }, + "downloads": -1, + "filename": "poetry_core-1.0.3-py2.py3-none-any.whl", + "has_sig": false, + "md5_digest": "16ce2526c342c1305d541425d406e35e", + "packagetype": "bdist_wheel", + "python_version": "py2.py3", + "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + "size": 424184, + "upload_time": "2021-04-09T15:44:41", + "upload_time_iso_8601": "2021-04-09T15:44:41.970294Z", + "url": "https://files.pythonhosted.org/packages/bf/e1/08c7478df1e93dea47b06c9d9a80dbb54af7421462e1b22c280d063df807/poetry_core-1.0.3-py2.py3-none-any.whl", + "yanked": false, + "yanked_reason": null + }, + { + "comment_text": "", + "digests": { + "md5": "dc82606f54a984a99daf8864cca1f028", + "sha256": "2315c928249fc3207801a81868b64c66273077b26c8d8da465dccf8f488c90c5" + }, + "downloads": -1, + "filename": "poetry-core-1.0.3.tar.gz", + "has_sig": false, + "md5_digest": "dc82606f54a984a99daf8864cca1f028", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + "size": 345626, + "upload_time": "2021-04-09T15:44:40", + "upload_time_iso_8601": "2021-04-09T15:44:40.639806Z", + "url": "https://files.pythonhosted.org/packages/d0/b3/1017f2f6d801f1e3e4ffee3f058a10d20df1a9560aba9c5b49e92cdd9912/poetry-core-1.0.3.tar.gz", + "yanked": false, + "yanked_reason": null + } + ] +}