Skip to content

Commit

Permalink
Support constraints file when resolving versions
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Apr 29, 2021
1 parent 494dec2 commit f933cab
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 30 deletions.
54 changes: 31 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ def handle(self) -> Optional[int]:

pool = self.poetry.pool

solver = Solver(package, pool, Repository(), Repository(), self._io)
solver = Solver(
package,
pool,
Repository(),
Repository(),
self._io,
with_constranit_dependencies=True,
)

ops = solver.solve()

Expand Down
2 changes: 2 additions & 0 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def _do_refresh(self) -> int:
locked_repository,
locked_repository,
self._io,
with_constranit_dependencies=True,
)

ops = solver.solve(use_latest=[])
Expand Down Expand Up @@ -247,6 +248,7 @@ def _do_install(self, local_repo: Repository) -> int:
locked_repository,
self._io,
remove_untracked=self._remove_untracked,
with_constranit_dependencies=True,
)

ops = solver.solve(use_latest=self._whitelist)
Expand Down
9 changes: 7 additions & 2 deletions poetry/mixology/incompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,13 @@ def _terse(self, term: Term, allow_every: bool = False) -> str:
if term.dependency.is_root:
return term.dependency.pretty_name

return "{} ({})".format(
term.dependency.pretty_name, term.dependency.pretty_constraint
pretty_constraint_category = term.dependency.pretty_constraint_category
if pretty_constraint_category != "":
pretty_constraint_category = " " + pretty_constraint_category
return "{} ({}){}".format(
term.dependency.pretty_name,
term.dependency.pretty_constraint,
pretty_constraint_category,
)

def _single_term_where(self, callable: callable) -> Optional[Term]:
Expand Down
14 changes: 12 additions & 2 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ class Provider:
UNSAFE_PACKAGES = set()

def __init__(
self, package: Package, pool: Pool, io: Any, env: Optional[Env] = None
self,
package: Package,
pool: Pool,
io: Any,
env: Optional[Env] = None,
with_constranit_dependencies: bool = False,
) -> None:
self._package = package
self._pool = pool
self._io = io
self._env = env
self._with_constraint_dependencies = with_constranit_dependencies
self._python_constraint = package.python_constraint
self._search_for = {}
self._is_debugging = self._io.is_debug() or self._io.is_very_verbose()
Expand Down Expand Up @@ -366,7 +372,11 @@ def incompatibilities_for(
previous call to _incompatibilities_for().
"""
if package.is_root():
dependencies = package.all_requires
dependencies = package.all_requires + (
package.constraint_requires
if self._with_constraint_dependencies
else []
)
else:
dependencies = package.requires

Expand Down
13 changes: 12 additions & 1 deletion poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
locked: Repository,
io: IO,
remove_untracked: bool = False,
with_constranit_dependencies: bool = False,
provider: Optional[Provider] = None,
):
self._package = package
Expand All @@ -57,7 +58,12 @@ def __init__(
self._io = io

if provider is None:
provider = Provider(self._package, self._pool, self._io)
provider = Provider(
self._package,
self._pool,
self._io,
with_constranit_dependencies=with_constranit_dependencies,
)

self._provider = provider
self._overrides = []
Expand Down Expand Up @@ -268,6 +274,11 @@ def _solve(self, use_latest: List[str] = None) -> Tuple[List[Package], List[int]
final_packages = []
depths = []
for package in packages:
# The packages may contain constraint dependencies that won't be reachable,
# and in that case we don't consider them to be resolved packages
if package not in results:
continue

if package.features:
for _package in packages:
if (
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ generate-setup-file = false
[tool.poetry.dependencies]
python = "^3.6"

poetry-core = { git = "https://github.com/python-poetry/poetry-core.git", branch = "master"}
poetry-core = { git = "https://github.com/honnix/poetry-core.git", branch = "constraints"}
cleo = "^1.0.0a1"
crashtest = "^0.3.0"
requests = "^2.18"
Expand Down
15 changes: 15 additions & 0 deletions tests/installation/fixtures/lock-no-update.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[package]]
name = "A"
version = "1.0"
description = ""
category = "main"
optional = false
python-versions = "*"

[metadata]
python-versions = "*"
lock-version = "1.1"
content-hash = "123456789"

[metadata.files]
"A" = []
Loading

0 comments on commit f933cab

Please sign in to comment.