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

Fix the show command #2967

Merged
merged 1 commit into from
Sep 25, 2020
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
41 changes: 27 additions & 14 deletions poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ class ShowCommand(EnvCommand):
def handle(self):
from clikit.utils.terminal import Terminal

from poetry.core.semver import Version
from poetry.io.null_io import NullIO
from poetry.puzzle.solver import Solver
from poetry.repositories.installed_repository import InstalledRepository
from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository
from poetry.utils.helpers import get_package_version_display_string

package = self.argument("package")
Expand All @@ -48,7 +51,7 @@ def handle(self):
self._args.set_option("latest", True)

include_dev = not self.option("no-dev")
locked_repo = self.poetry.locker.locked_repository(include_dev)
locked_repo = self.poetry.locker.locked_repository(True)

# Show tree view if requested
if self.option("tree") and not package:
Expand All @@ -65,6 +68,25 @@ def handle(self):
table = self.table(style="compact")
# table.style.line_vc_char = ""
locked_packages = locked_repo.packages
pool = Pool()
pool.add_repository(locked_repo)
solver = Solver(
self.poetry.package,
pool=pool,
installed=Repository(),
locked=locked_repo,
io=NullIO(),
)
solver.provider.load_deferred(False)
with solver.use_environment(self.env):
ops = solver.solve()

required_locked_packages = set([op.package for op in ops if not op.skipped])

if self.option("no-dev"):
required_locked_packages = [
p for p in locked_packages if p.category == "main"
]

if package:
pkg = None
Expand Down Expand Up @@ -110,20 +132,11 @@ def handle(self):
latest_packages = {}
latest_statuses = {}
installed_repo = InstalledRepository.load(self.env)
skipped = []

python = Version.parse(".".join([str(i) for i in self.env.version_info[:3]]))

# Computing widths
for locked in locked_packages:
python_constraint = locked.python_constraint
if not python_constraint.allows(python) or not self.env.is_valid_for_marker(
locked.marker
):
skipped.append(locked)

if not show_all:
continue
if locked not in required_locked_packages and not show_all:
continue

current_length = len(locked.pretty_name)
if not self._io.output.supports_ansi():
Expand Down Expand Up @@ -179,7 +192,7 @@ def handle(self):
color = "cyan"
name = locked.pretty_name
install_marker = ""
if locked in skipped:
if locked not in required_locked_packages:
if not show_all:
continue

Expand Down
29 changes: 17 additions & 12 deletions poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,12 @@ def _get_min(dependency):
# only has one version to choose from.
return 1

if dependency.name in self._locked:
locked = self._get_locked(dependency)
if locked and (
dependency.constraint.allows(locked.version)
or locked.is_prerelease()
and dependency.constraint.allows(locked.version.next_patch)
):
return 1

# VCS, URL, File or Directory dependencies
Expand Down Expand Up @@ -377,17 +382,17 @@ def _get_min(dependency):
version = packages[0]
except IndexError:
version = None
else:
version = locked

if version is None:
# If there are no versions that satisfy the constraint,
# add an incompatibility that indicates that.
self._add_incompatibility(
Incompatibility([Term(dependency, True)], NoVersionsCause())
)
if version is None:
# If there are no versions that satisfy the constraint,
# add an incompatibility that indicates that.
self._add_incompatibility(
Incompatibility([Term(dependency, True)], NoVersionsCause())
)

return dependency.complete_name
return dependency.complete_name
else:
version = locked

version = self._provider.complete_package(version)

Expand Down Expand Up @@ -451,10 +456,10 @@ def _add_incompatibility(self, incompatibility): # type: (Incompatibility) -> N
)

def _get_locked(self, dependency): # type: (Dependency) -> Union[Package, None]
if dependency.complete_name in self._use_latest:
if dependency.name in self._use_latest:
return

locked = self._locked.get(dependency.complete_name)
locked = self._locked.get(dependency.name)
if not locked:
return

Expand Down
25 changes: 15 additions & 10 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
self._in_progress = False
self._overrides = {}
self._deferred_cache = {}
self._load_deferred = True

@property
def pool(self): # type: () -> Pool
Expand All @@ -78,6 +79,9 @@ def is_debugging(self):
def set_overrides(self, overrides):
self._overrides = overrides

def load_deferred(self, load_deferred): # type: (bool) -> None
self._load_deferred = load_deferred

@contextmanager
def use_environment(self, env): # type: (Env) -> Provider
original_env = self._env
Expand Down Expand Up @@ -436,16 +440,17 @@ def complete_package(
else:
requires = package.requires

# Retrieving constraints for deferred dependencies
for r in requires:
if r.is_directory():
self.search_for_directory(r)
elif r.is_file():
self.search_for_file(r)
elif r.is_vcs():
self.search_for_vcs(r)
elif r.is_url():
self.search_for_url(r)
if self._load_deferred:
# Retrieving constraints for deferred dependencies
for r in requires:
if r.is_directory():
self.search_for_directory(r)
elif r.is_file():
self.search_for_file(r)
elif r.is_vcs():
self.search_for_vcs(r)
elif r.is_url():
self.search_for_url(r)

optional_dependencies = []
activated_extras = []
Expand Down
8 changes: 5 additions & 3 deletions poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@ def reachable(self):
continue

for pkg in self.packages:
if (
pkg.complete_name == dependency.complete_name
and dependency.constraint.allows(pkg.version)
if pkg.complete_name == dependency.complete_name and (
dependency.constraint.allows(pkg.version)
or dependency.allows_prereleases()
and pkg.version.is_prerelease()
and dependency.constraint.allows(pkg.version.stable)
):
# If there is already a child with this name
# we merge the requirements
Expand Down
7 changes: 5 additions & 2 deletions poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def find_packages(self, dependency):
if not isinstance(constraint, VersionConstraint):
constraint = parse_constraint(constraint)

allow_prereleases = dependency.allows_prereleases
allow_prereleases = dependency.allows_prereleases()
if isinstance(constraint, VersionRange):
if (
constraint.max is not None
Expand All @@ -68,7 +68,10 @@ def find_packages(self, dependency):
ignored_pre_release_packages.append(package)
continue

if constraint.allows(package.version):
if constraint.allows(package.version) or (
package.is_prerelease()
and constraint.allows(package.version.next_patch)
):
packages.append(package)

return packages or ignored_pre_release_packages
Expand Down
Loading