Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename repository modules #6803

Merged
merged 6 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def handle(self) -> int:

from poetry.factory import Factory
from poetry.puzzle.solver import Solver
from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.env import EnvManager

packages = self.argument("package")
Expand Down Expand Up @@ -107,7 +107,7 @@ def handle(self) -> int:

if self.option("install"):
env = EnvManager(self.poetry).get()
pool = Pool()
pool = RepositoryPool()
locked_repository = Repository("poetry-locked")
for op in ops:
locked_repository.add_package(op.package)
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from poetry.core.packages.package import Package
from tomlkit.items import InlineTable

from poetry.repositories import Pool
from poetry.repositories import RepositoryPool

Requirements = Dict[str, Union[str, Mapping[str, Any]]]

Expand Down Expand Up @@ -66,7 +66,7 @@ class InitCommand(Command):
def __init__(self) -> None:
super().__init__()

self._pool: Pool | None = None
self._pool: RepositoryPool | None = None

def handle(self) -> int:
from pathlib import Path
Expand Down Expand Up @@ -462,15 +462,15 @@ def _validate_package(package: str | None) -> str | None:

return package

def _get_pool(self) -> Pool:
from poetry.repositories import Pool
def _get_pool(self) -> RepositoryPool:
from poetry.repositories import RepositoryPool
from poetry.repositories.pypi_repository import PyPiRepository

if isinstance(self, EnvCommand):
return self.poetry.pool

if self._pool is None:
self._pool = Pool()
self._pool = RepositoryPool()
self._pool.add_repository(PyPiRepository())

return self._pool
4 changes: 2 additions & 2 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def _display_packages_information(

from poetry.puzzle.solver import Solver
from poetry.repositories.installed_repository import InstalledRepository
from poetry.repositories.pool import Pool
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.helpers import get_package_version_display_string

locked_packages = locked_repository.packages
pool = Pool(ignore_repository_names=True)
pool = RepositoryPool(ignore_repository_names=True)
pool.add_repository(locked_repository)
solver = Solver(
root,
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SourceAddCommand(Command):

def handle(self) -> int:
from poetry.factory import Factory
from poetry.repositories import Pool
from poetry.repositories import RepositoryPool
from poetry.utils.source import source_to_table

name = self.argument("name")
Expand Down Expand Up @@ -83,7 +83,7 @@ def handle(self) -> int:
sources.append(source_to_table(new_source))

# ensure new source is valid. eg: invalid name etc.
self.poetry._pool = Pool()
self.poetry._pool = RepositoryPool()
try:
Factory.configure_sources(
self.poetry, sources, self.poetry.config, NullIO()
Expand Down
6 changes: 4 additions & 2 deletions src/poetry/installation/chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from poetry.core.packages.package import Package
from poetry.core.packages.utils.link import Link

from poetry.repositories.pool import Pool
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.env import Env


Expand Down Expand Up @@ -61,7 +61,9 @@ class Chooser:
A Chooser chooses an appropriate release archive for packages.
"""

def __init__(self, pool: Pool, env: Env, config: Config | None = None) -> None:
def __init__(
self, pool: RepositoryPool, env: Env, config: Config | None = None
) -> None:
self._pool = pool
self._env = env
self._config = config or Config.create()
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

from poetry.config.config import Config
from poetry.installation.operations.operation import Operation
from poetry.repositories import Pool
from poetry.repositories import RepositoryPool
from poetry.utils.env import Env


class Executor:
def __init__(
self,
env: Env,
pool: Pool,
pool: RepositoryPool,
config: Config,
io: IO,
parallel: bool | None = None,
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from poetry.installation.operations import Uninstall
from poetry.installation.operations import Update
from poetry.installation.pip_installer import PipInstaller
from poetry.repositories import Pool
from poetry.repositories import Repository
from poetry.repositories import RepositoryPool
from poetry.repositories.installed_repository import InstalledRepository
from poetry.repositories.lockfile_repository import LockfileRepository
from poetry.utils.extras import get_extra_package_names
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(
env: Env,
package: ProjectPackage,
locker: Locker,
pool: Pool,
pool: RepositoryPool,
config: Config,
installed: Repository | None = None,
executor: Executor | None = None,
Expand Down Expand Up @@ -300,7 +300,7 @@ def _do_install(self) -> int:
)

# We resolve again by only using the lock file
pool = Pool(ignore_repository_names=True)
pool = RepositoryPool(ignore_repository_names=True)

# Making a new repo containing the packages
# newly resolved and the ones from the current lock file
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/installation/pip_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from poetry.core.pyproject.toml import PyProjectTOML

from poetry.installation.base_installer import BaseInstaller
from poetry.repositories.http import HTTPRepository
from poetry.repositories.http_repository import HTTPRepository
from poetry.utils._compat import encode
from poetry.utils.helpers import remove_directory
from poetry.utils.pip import pip_install
Expand All @@ -25,12 +25,12 @@
from poetry.core.masonry.builders.builder import Builder
from poetry.core.packages.package import Package

from poetry.repositories.pool import Pool
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.env import Env


class PipInstaller(BaseInstaller):
def __init__(self, env: Env, io: IO, pool: Pool) -> None:
def __init__(self, env: Env, io: IO, pool: RepositoryPool) -> None:
self._env = env
self._io = io
self._pool = pool
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from poetry.config.config import Config
from poetry.packages.locker import Locker
from poetry.plugins.plugin_manager import PluginManager
from poetry.repositories.pool import Pool
from poetry.repositories.repository_pool import RepositoryPool


class Poetry(BasePoetry):
Expand All @@ -32,13 +32,13 @@ def __init__(
config: Config,
disable_cache: bool = False,
) -> None:
from poetry.repositories.pool import Pool
from poetry.repositories.repository_pool import RepositoryPool

super().__init__(file, local_config, package)

self._locker = locker
self._config = config
self._pool = Pool()
self._pool = RepositoryPool()
self._plugin_manager: PluginManager | None = None
self._disable_cache = disable_cache

Expand All @@ -47,7 +47,7 @@ def locker(self) -> Locker:
return self._locker

@property
def pool(self) -> Pool:
def pool(self) -> RepositoryPool:
return self._pool

@property
Expand All @@ -63,7 +63,7 @@ def set_locker(self, locker: Locker) -> Poetry:

return self

def set_pool(self, pool: Pool) -> Poetry:
def set_pool(self, pool: RepositoryPool) -> Poetry:
self._pool = pool

return self
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.version.markers import BaseMarker

from poetry.repositories import Pool
from poetry.repositories import RepositoryPool
from poetry.utils.env import Env


Expand Down Expand Up @@ -124,7 +124,7 @@ class Provider:
def __init__(
self,
package: Package,
pool: Pool,
pool: RepositoryPool,
io: IO,
*,
installed: list[Package] | None = None,
Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(
)

@property
def pool(self) -> Pool:
def pool(self) -> RepositoryPool:
return self._pool

@property
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

from poetry.packages import DependencyPackage
from poetry.puzzle.transaction import Transaction
from poetry.repositories import Pool
from poetry.repositories import RepositoryPool
from poetry.utils.env import Env


class Solver:
def __init__(
self,
package: ProjectPackage,
pool: Pool,
pool: RepositoryPool,
installed: list[Package],
locked: list[Package],
io: IO,
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository
from poetry.repositories.repository_pool import RepositoryPool


__all__ = ["Pool", "Repository"]
__all__ = ["Pool", "Repository", "RepositoryPool"]
83 changes: 10 additions & 73 deletions src/poetry/repositories/cached.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,15 @@
from __future__ import annotations

from abc import ABC
from abc import abstractmethod
from typing import TYPE_CHECKING
from typing import Any
import warnings

from packaging.utils import canonicalize_name
from poetry.core.constraints.version import parse_constraint

from poetry.config.config import Config
from poetry.repositories.repository import Repository
from poetry.utils.cache import FileCache
from poetry.repositories.cached_repository import ( # isort: skip # nopycln: import # noqa: E501, F401
CachedRepository,
)


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core.constraints.version import Version
from poetry.core.packages.package import Package

from poetry.inspection.info import PackageInfo


class CachedRepository(Repository, ABC):
CACHE_VERSION = parse_constraint("1.1.0")

def __init__(
self, name: str, disable_cache: bool = False, config: Config | None = None
) -> None:
super().__init__(name)
self._disable_cache = disable_cache
self._cache_dir = (config or Config.create()).repository_cache_directory / name
self._release_cache: FileCache[dict[str, Any]] = FileCache(path=self._cache_dir)

@abstractmethod
def _get_release_info(
self, name: NormalizedName, version: Version
) -> dict[str, Any]:
...

def get_release_info(self, name: NormalizedName, version: Version) -> PackageInfo:
"""
Return the release information given a package name and a version.

The information is returned from the cache if it exists
or retrieved from the remote server.
"""
from poetry.inspection.info import PackageInfo

if self._disable_cache:
return PackageInfo.load(self._get_release_info(name, version))

cached = self._release_cache.remember(
f"{name}:{version}", lambda: self._get_release_info(name, version)
)

cache_version = cached.get("_cache_version", "0.0.0")
if parse_constraint(cache_version) != self.CACHE_VERSION:
# The cache must be updated
self._log(
f"The cache for {name} {version} is outdated. Refreshing.",
level="debug",
)
cached = self._get_release_info(name, version)

self._release_cache.put(f"{name}:{version}", cached)

return PackageInfo.load(cached)

def package(
self,
name: str,
version: Version,
extras: list[str] | None = None,
) -> Package:
return self.get_release_info(canonicalize_name(name), version).to_package(
name=name, extras=extras
)
warnings.warn(
"Module poetry.repositories.cached is renamed and scheduled for removal in poetry"
" release 1.4.0. Please migrate to poetry.repositories.cached_repository.",
DeprecationWarning,
stacklevel=2,
)
Loading