Skip to content

Commit

Permalink
Merge branch 'master' into pool_maxsize
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Oct 31, 2022
2 parents 2462e4d + 6096ac5 commit ba1686d
Show file tree
Hide file tree
Showing 50 changed files with 1,000 additions and 712 deletions.
2 changes: 1 addition & 1 deletion .flake8
Expand Up @@ -6,7 +6,7 @@ ban-relative-imports = true
format-greedy = 1
inline-quotes = double
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
type-checking-strict = true
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E203: Whitespace before ':' (pycqa/pycodestyle#373)
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/main.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
os: [Ubuntu, macOS, Windows]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
include:
- os: Ubuntu
image: ubuntu-22.04
Expand Down Expand Up @@ -83,11 +83,6 @@ jobs:
# Using `timeout` is a safeguard against the Poetry command hanging for some reason.
timeout 10s poetry run pip --version || rm -rf .venv
# XXX: https://github.com/pypa/pip/issues/11352 causes random failures -- remove once fixed in a release.
- name: Upgrade pip on Python 3.11
if: ${{ matrix.python-version == '3.11-dev' }}
run: poetry run pip install git+https://github.com/pypa/pip.git@f8a25921e5c443b07483017b0ffdeb08b9ba2fdf

- name: Install dependencies
run: poetry install --with github-actions

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -40,7 +40,7 @@ repos:
- flake8-quotes==3.3.1
- flake8-simplify==0.19.3
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.1.2
- flake8-type-checking==2.2.0
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.4
- pep8-naming==0.13.1
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2018 Sébastien Eustace
Copyright (c) 2018-present Sébastien Eustace

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
4 changes: 2 additions & 2 deletions docs/dependency-specification.md
Expand Up @@ -247,7 +247,7 @@ for extras in your project refer to [`extras`]({{< relref "pyproject#extras" >}}

## `source` dependencies

To depend on a package from an [alternate repository]({{< relref "repositories/#install-dependencies-from-a-private-repository" >}}),
To depend on a package from an [alternate repository]({{< relref "repositories#installing-from-private-package-sources" >}}),
you can use the `source` property:

```toml
Expand All @@ -267,7 +267,7 @@ poetry add my-cool-package --source foo
```

{{% note %}}
In this example, we expect `foo` to be configured correctly. See [using a private repository](repositories.md#using-a-private-repository)
In this example, we expect `foo` to be configured correctly. See [using a private repository]({{< relref "repositories#installing-from-private-package-sources" >}})
for further information.
{{% /note %}}

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -65,7 +65,7 @@ pexpect = "^4.7.0"
pkginfo = "^1.5"
platformdirs = "^2.5.2"
requests = "^2.18"
requests-toolbelt = "^0.9.1"
requests-toolbelt = ">=0.9.1,<0.11.0"
shellingham = "^1.5"
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
tomlkit = ">=0.11.1,<1.0.0,!=0.11.2,!=0.11.3"
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/debug/resolve.py
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
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
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
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
3 changes: 2 additions & 1 deletion src/poetry/factory.py
Expand Up @@ -257,7 +257,8 @@ def create_pyproject_from_package(
constraint["optional"] = True

if len(constraint) == 1 and "version" in constraint:
constraint = cast(str, constraint["version"])
assert isinstance(constraint["version"], str)
constraint = constraint["version"]
elif not constraint:
constraint = "*"

Expand Down
6 changes: 4 additions & 2 deletions src/poetry/installation/chooser.py
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
8 changes: 4 additions & 4 deletions src/poetry/installation/executor.py
Expand Up @@ -13,7 +13,6 @@
from subprocess import CalledProcessError
from typing import TYPE_CHECKING
from typing import Any
from typing import cast

from cleo.io.null_io import NullIO
from poetry.core.packages.file_dependency import FileDependency
Expand Down Expand Up @@ -42,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 Expand Up @@ -772,7 +771,8 @@ def _save_url_reference(self, operation: Operation) -> None:
for dist in self._env.site_packages.distributions(
name=package.name, writable_only=True
):
dist_path = cast(Path, dist._path) # type: ignore[attr-defined]
dist_path = dist._path # type: ignore[attr-defined]
assert isinstance(dist_path, Path)
url = dist_path / "direct_url.json"
url.write_text(json.dumps(url_reference), encoding="utf-8")

Expand Down
14 changes: 10 additions & 4 deletions src/poetry/installation/installer.py
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 @@ -201,10 +201,16 @@ def _do_refresh(self) -> int:
self._io,
)

# Always re-solve directory dependencies, otherwise we can't determine
# if anything has changed (and the lock file contains an invalid version).
use_latest = [
p.name for p in locked_repository.packages if p.source_type == "directory"
]

with solver.provider.use_source_root(
source_root=self._env.path.joinpath("src")
):
ops = solver.solve(use_latest=[]).calculate_operations()
ops = solver.solve(use_latest=use_latest).calculate_operations()

lockfile_repo = LockfileRepository()
self._populate_lockfile_repo(lockfile_repo, ops)
Expand Down Expand Up @@ -294,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
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: 6 additions & 4 deletions src/poetry/mixology/failure.py
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import cast

from poetry.core.constraints.version import parse_constraint

Expand Down Expand Up @@ -114,7 +113,8 @@ def _visit(
conjunction = "So," if conclusion or incompatibility == self._root else "And"
incompatibility_string = str(incompatibility)

cause: ConflictCause = cast(ConflictCause, incompatibility.cause)
cause = incompatibility.cause
assert isinstance(cause, ConflictCause)

if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause
Expand Down Expand Up @@ -198,7 +198,8 @@ def _visit(
numbered=numbered,
)
elif self._is_collapsible(derived):
derived_cause: ConflictCause = cast(ConflictCause, derived.cause)
derived_cause = derived.cause
assert isinstance(derived_cause, ConflictCause)
if isinstance(derived_cause.conflict.cause, ConflictCause):
collapsed_derived = derived_cause.conflict
collapsed_ext = derived_cause.other
Expand Down Expand Up @@ -233,7 +234,8 @@ def _is_collapsible(self, incompatibility: Incompatibility) -> bool:
if self._derivations[incompatibility] > 1:
return False

cause: ConflictCause = cast(ConflictCause, incompatibility.cause)
cause = incompatibility.cause
assert isinstance(cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause
):
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/poetry.py
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

0 comments on commit ba1686d

Please sign in to comment.