Skip to content

Commit

Permalink
fix: don't merge sources into config
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Feb 25, 2023
1 parent a3f6437 commit 76f332d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
6 changes: 1 addition & 5 deletions src/poetry/console/commands/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ def handle(self) -> int:
self.line(f"Adding source with name <c1>{name}</c1>.")
sources.append(source_to_table(new_source))

self.poetry.config.merge(
{"sources": {source["name"]: source for source in sources}}
)

# ensure new source is valid. eg: invalid name etc.
try:
pool = Factory.create_pool(self.poetry.config, NullIO())
pool = Factory.create_pool(self.poetry.config, sources, NullIO())
pool.repository(name)
except ValueError as e:
self.line_error(
Expand Down
24 changes: 12 additions & 12 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


if TYPE_CHECKING:
from collections.abc import Iterable
from pathlib import Path

from cleo.io.io import IO
Expand Down Expand Up @@ -89,16 +90,14 @@ def create_poetry(
disable_cache,
)

# Configuring sources
config.merge(
{
"sources": {
source["name"]: source
for source in poetry.local_config.get("source", [])
}
}
poetry.set_pool(
self.create_pool(
config,
poetry.local_config.get("source", []),
io,
disable_cache=disable_cache,
)
)
poetry.set_pool(self.create_pool(config, io, disable_cache=disable_cache))

plugin_manager = PluginManager(Plugin.group, disable_plugins=disable_plugins)
plugin_manager.load_plugins()
Expand All @@ -114,7 +113,8 @@ def get_package(cls, name: str, version: str) -> ProjectPackage:
@classmethod
def create_pool(
cls,
config: Config,
auth_config: Config,
sources: Iterable[dict[str, Any]] = (),
io: IO | None = None,
disable_cache: bool = False,
) -> RepositoryPool:
Expand All @@ -128,9 +128,9 @@ def create_pool(

pool = RepositoryPool()

for source in config.get("sources", {}).values():
for source in sources:
repository = cls.create_package_source(
source, config, disable_cache=disable_cache
source, auth_config, disable_cache=disable_cache
)
is_default = source.get("default", False)
is_secondary = source.get("secondary", False)
Expand Down
15 changes: 7 additions & 8 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from poetry.core.packages.utils.link import Link

from poetry.config.config import Config
from poetry.repositories import RepositoryPool
from poetry.utils.env import Env


Expand All @@ -42,9 +43,9 @@ class ChefBuildError(ChefError):


class IsolatedEnv(BaseIsolatedEnv):
def __init__(self, env: Env, config: Config) -> None:
def __init__(self, env: Env, pool: RepositoryPool) -> None:
self._env = env
self._config = config
self._pool = pool

@property
def executable(self) -> str:
Expand All @@ -60,7 +61,6 @@ def install(self, requirements: Collection[str]) -> None:
from poetry.core.packages.project_package import ProjectPackage

from poetry.config.config import Config
from poetry.factory import Factory
from poetry.installation.installer import Installer
from poetry.packages.locker import Locker
from poetry.repositories.installed_repository import InstalledRepository
Expand All @@ -72,13 +72,12 @@ def install(self, requirements: Collection[str]) -> None:
dependency = Dependency.create_from_pep_508(requirement)
package.add_dependency(dependency)

pool = Factory.create_pool(self._config)
installer = Installer(
NullIO(),
self._env,
package,
Locker(self._env.path.joinpath("poetry.lock"), {}),
pool,
self._pool,
Config.create(),
InstalledRepository.load(self._env),
)
Expand All @@ -87,9 +86,9 @@ def install(self, requirements: Collection[str]) -> None:


class Chef:
def __init__(self, config: Config, env: Env) -> None:
self._config = config
def __init__(self, config: Config, env: Env, pool: RepositoryPool) -> None:
self._env = env
self._pool = pool
self._cache_dir = (
Path(config.get("cache-dir")).expanduser().joinpath("artifacts")
)
Expand All @@ -113,7 +112,7 @@ def _prepare(
from subprocess import CalledProcessError

with ephemeral_environment(self._env.python) as venv:
env = IsolatedEnv(venv, self._config)
env = IsolatedEnv(venv, self._pool)
builder = ProjectBuilder(
directory,
python_executable=env.executable,
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
self._authenticator = Authenticator(
config, self._io, disable_cache=disable_cache, pool_size=self._max_workers
)
self._chef = Chef(config, self._env)
self._chef = Chef(config, self._env, pool)
self._chooser = Chooser(pool, self._env, config)

self._executor = ThreadPoolExecutor(max_workers=self._max_workers)
Expand Down
7 changes: 5 additions & 2 deletions tests/console/commands/self/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any
from typing import Callable

import pytest
Expand All @@ -14,6 +15,8 @@


if TYPE_CHECKING:
from collections.abc import Iterable

import httpretty

from cleo.io.io import IO
Expand Down Expand Up @@ -44,9 +47,9 @@ def pool(repo: TestRepository) -> RepositoryPool:

def create_pool_factory(
repo: Repository,
) -> Callable[[Config, IO, bool], RepositoryPool]:
) -> Callable[[Config, Iterable[str, Any], IO, bool], RepositoryPool]:
def _create_pool(
config: Config, io: IO, disable_cache: bool = False
config: Config, sources: Iterable[str, Any], io: IO, disable_cache: bool = False
) -> RepositoryPool:
pool = RepositoryPool()
pool.add_repository(repo)
Expand Down
11 changes: 7 additions & 4 deletions tests/installation/test_chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_get_cached_archive_for_link(
Tag("py3", "none", "any"),
],
),
Factory.create_pool(config),
)

mocker.patch.object(
Expand All @@ -87,6 +88,7 @@ def test_get_cached_archives_for_link(config: Config, mocker: MockerFixture):
MockEnv(
marker_env={"interpreter_name": "cpython", "interpreter_version": "3.8.3"}
),
Factory.create_pool(config),
)

distributions = Path(__file__).parent.parent.joinpath("fixtures/distributions")
Expand All @@ -110,6 +112,7 @@ def test_get_cache_directory_for_link(config: Config, config_cache_dir: Path):
MockEnv(
marker_env={"interpreter_name": "cpython", "interpreter_version": "3.8.3"}
),
Factory.create_pool(config),
)

directory = chef.get_cache_directory_for_link(
Expand All @@ -125,7 +128,7 @@ def test_get_cache_directory_for_link(config: Config, config_cache_dir: Path):


def test_prepare_sdist(config: Config, config_cache_dir: Path) -> None:
chef = Chef(config, EnvManager.get_system_env())
chef = Chef(config, EnvManager.get_system_env(), Factory.create_pool(config))

archive = (
Path(__file__)
Expand All @@ -142,7 +145,7 @@ def test_prepare_sdist(config: Config, config_cache_dir: Path) -> None:


def test_prepare_directory(config: Config, config_cache_dir: Path):
chef = Chef(config, EnvManager.get_system_env())
chef = Chef(config, EnvManager.get_system_env(), Factory.create_pool(config))

archive = Path(__file__).parent.parent.joinpath("fixtures/simple_project").resolve()

Expand All @@ -155,7 +158,7 @@ def test_prepare_directory_with_extensions(
config: Config, config_cache_dir: Path
) -> None:
env = EnvManager.get_system_env()
chef = Chef(config, env)
chef = Chef(config, env, Factory.create_pool(config))

archive = (
Path(__file__)
Expand All @@ -169,7 +172,7 @@ def test_prepare_directory_with_extensions(


def test_prepare_directory_editable(config: Config, config_cache_dir: Path):
chef = Chef(config, EnvManager.get_system_env())
chef = Chef(config, EnvManager.get_system_env(), Factory.create_pool(config))

archive = Path(__file__).parent.parent.joinpath("fixtures/simple_project").resolve()

Expand Down
10 changes: 5 additions & 5 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_execute_executes_a_batch_of_operations(
config.merge({"cache-dir": tmp_dir})

prepare_spy = mocker.spy(Chef, "_prepare")
chef = Chef(config, env)
chef = Chef(config, env, Factory.create_pool(config))
chef.set_directory_wheel([copy_wheel(), copy_wheel()])
chef.set_sdist_wheel(copy_wheel())

Expand Down Expand Up @@ -661,7 +661,7 @@ def test_executor_should_write_pep610_url_references_for_directories(
"demo", "0.1.2", source_type="directory", source_url=url.as_posix()
)

chef = Chef(config, tmp_venv)
chef = Chef(config, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)

executor = Executor(tmp_venv, pool, config, io)
Expand Down Expand Up @@ -692,7 +692,7 @@ def test_executor_should_write_pep610_url_references_for_editable_directories(
develop=True,
)

chef = Chef(config, tmp_venv)
chef = Chef(config, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)

executor = Executor(tmp_venv, pool, config, io)
Expand Down Expand Up @@ -756,7 +756,7 @@ def test_executor_should_write_pep610_url_references_for_git(
source_url="https://github.com/demo/demo.git",
)

chef = Chef(config, tmp_venv)
chef = Chef(config, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)

executor = Executor(tmp_venv, pool, config, io)
Expand Down Expand Up @@ -794,7 +794,7 @@ def test_executor_should_write_pep610_url_references_for_git_with_subdirectories
source_subdirectory="two",
)

chef = Chef(config, tmp_venv)
chef = Chef(config, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)

executor = Executor(tmp_venv, pool, config, io)
Expand Down

0 comments on commit 76f332d

Please sign in to comment.