"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "poetry/console/commands/debug/resolve.py" between
poetry-1.1.15.tar.gz and poetry-1.2.0.tar.gz

About: Poetry is a tool for dependency management and packaging in Python.

resolve.py  (poetry-1.1.15):resolve.py  (poetry-1.2.0)
from cleo import argument from __future__ import annotations
from cleo import option
from ..init import InitCommand from cleo.helpers import argument
from cleo.helpers import option
from cleo.io.outputs.output import Verbosity
class DebugResolveCommand(InitCommand): from poetry.console.commands.init import InitCommand
from poetry.console.commands.show import ShowCommand
name = "resolve" class DebugResolveCommand(InitCommand):
name = "debug resolve"
description = "Debugs dependency resolution." description = "Debugs dependency resolution."
arguments = [ arguments = [
argument("package", "The packages to resolve.", optional=True, multiple= True) argument("package", "The packages to resolve.", optional=True, multiple= True)
] ]
options = [ options = [
option( option(
"extras", "extras",
"E", "E",
"Extras to activate for the dependency.", "Extras to activate for the dependency.",
flag=False, flag=False,
multiple=True, multiple=True,
), ),
option("python", None, "Python version(s) to use for resolution.", flag= False), option("python", None, "Python version(s) to use for resolution.", flag= False),
option("tree", None, "Display the dependency tree."), option("tree", None, "Display the dependency tree."),
option("install", None, "Show what would be installed for the current sy stem."), option("install", None, "Show what would be installed for the current sy stem."),
] ]
loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"] loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"]
def handle(self): def handle(self) -> int:
from cleo.io.null_io import NullIO
from poetry.core.packages.project_package import ProjectPackage from poetry.core.packages.project_package import ProjectPackage
from poetry.factory import Factory from poetry.factory import Factory
from poetry.io.null_io import NullIO from poetry.puzzle.solver import Solver
from poetry.puzzle import Solver
from poetry.repositories.pool import Pool from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository from poetry.repositories.repository import Repository
from poetry.utils.env import EnvManager from poetry.utils.env import EnvManager
packages = self.argument("package") packages = self.argument("package")
if not packages: if not packages:
package = self.poetry.package package = self.poetry.package
else: else:
# Using current pool for determine_requirements() # Using current pool for determine_requirements()
self._pool = self.poetry.pool self._pool = self.poetry.pool
package = ProjectPackage( package = ProjectPackage(
self.poetry.package.name, self.poetry.package.version self.poetry.package.name, self.poetry.package.version
) )
# Silencing output # Silencing output
is_quiet = self.io.output.is_quiet() verbosity = self.io.output.verbosity
if not is_quiet: self.io.output.set_verbosity(Verbosity.QUIET)
self.io.output.set_quiet(True)
requirements = self._determine_requirements(packages) requirements = self._determine_requirements(packages)
if not is_quiet: self.io.output.set_verbosity(verbosity)
self.io.output.set_quiet(False)
for constraint in requirements: for constraint in requirements:
name = constraint.pop("name") name = constraint.pop("name")
assert isinstance(name, str)
extras = [] extras = []
for extra in self.option("extras"): for extra in self.option("extras"):
if " " in extra: if " " in extra:
extras += [e.strip() for e in extra.split(" ")] extras += [e.strip() for e in extra.split(" ")]
else: else:
extras.append(extra) extras.append(extra)
constraint["extras"] = extras constraint["extras"] = extras
package.add_dependency(Factory.create_dependency(name, constrain t)) package.add_dependency(Factory.create_dependency(name, constrain t))
package.python_versions = self.option("python") or ( package.python_versions = self.option("python") or (
self.poetry.package.python_versions self.poetry.package.python_versions
) )
pool = self.poetry.pool pool = self.poetry.pool
solver = Solver(package, pool, Repository(), Repository(), self._io) solver = Solver(package, pool, [], [], self.io)
ops = solver.solve() ops = solver.solve().calculate_operations()
self.line("") self.line("")
self.line("Resolution results:") self.line("Resolution results:")
self.line("") self.line("")
if self.option("tree"): if self.option("tree"):
show_command = self.application.find("show") show_command = self.application.find("show")
assert isinstance(show_command, ShowCommand)
show_command.init_styles(self.io) show_command.init_styles(self.io)
packages = [op.package for op in ops] packages = [op.package for op in ops]
repo = Repository(packages)
requires = package.requires + package.dev_requires requires = package.all_requires
for pkg in repo.packages: for pkg in packages:
for require in requires: for require in requires:
if pkg.name == require.name: if pkg.name == require.name:
show_command.display_package_tree(self.io, pkg, repo) show_command.display_package_tree(self.io, pkg, packages )
break break
return 0 return 0
table = self.table([], style="borderless") table = self.table(style="compact")
table.style.set_vertical_border_chars("", " ")
rows = [] rows = []
if self.option("install"): if self.option("install"):
env = EnvManager(self.poetry).get() env = EnvManager(self.poetry).get()
pool = Pool() pool = Pool()
locked_repository = Repository() locked_repository = Repository("poetry-locked")
for op in ops: for op in ops:
locked_repository.add_package(op.package) locked_repository.add_package(op.package)
pool.add_repository(locked_repository) pool.add_repository(locked_repository)
solver = Solver(package, pool, Repository(), Repository(), NullIO()) solver = Solver(package, pool, [], [], NullIO())
with solver.use_environment(env): with solver.use_environment(env):
ops = solver.solve() ops = solver.solve().calculate_operations()
for op in ops: for op in ops:
if self.option("install") and op.skipped: if self.option("install") and op.skipped:
continue continue
pkg = op.package pkg = op.package
row = [ row = [
"<c1>{}</c1>".format(pkg.complete_name), f"<c1>{pkg.complete_name}</c1>",
"<b>{}</b>".format(pkg.version), f"<b>{pkg.version}</b>",
"",
] ]
if not pkg.marker.is_any(): if not pkg.marker.is_any():
row[2] = str(pkg.marker) row[2] = str(pkg.marker)
rows.append(row) rows.append(row)
table.set_rows(rows) table.set_rows(rows)
table.render(self.io) table.render()
return 0
 End of changes. 22 change blocks. 
26 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)