Skip to content
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
21 changes: 14 additions & 7 deletions src/python_inspector/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def get_resolved_dependencies(
repos: Sequence[PypiSimpleRepository] = tuple(),
as_tree: bool = False,
max_rounds: int = 200000,
debug: bool = False,
):
"""
Return resolved dependencies of a ``requirements`` list of Requirement for
Expand All @@ -642,10 +643,16 @@ def get_resolved_dependencies(
Used the provided ``repos`` list of PypiSimpleRepository.
If empty, use instead the PyPI.org JSON API exclusively instead
"""
resolver = Resolver(
provider=PythonInputProvider(environment=environment, repos=repos),
reporter=BaseReporter(),
)
results = resolver.resolve(requirements=requirements, max_rounds=max_rounds)
results = format_resolution(results, as_tree=as_tree, environment=environment, repos=repos)
return results
try:
resolver = Resolver(
provider=PythonInputProvider(environment=environment, repos=repos),
reporter=BaseReporter(),
)
results = resolver.resolve(requirements=requirements, max_rounds=max_rounds)
results = format_resolution(results, as_tree=as_tree, environment=environment, repos=repos)
return results
except Exception as e:
if debug:
import click

click.secho(f"{e!r}", err=True)
13 changes: 9 additions & 4 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def resolve_dependencies(

dad --spec "flask==2.1.2" --json -
"""

click.secho(f"Resolving dependencies...")
if debug:
click.secho(f"Resolving dependencies...")

netrc = None
if netrc_file:
Expand All @@ -184,7 +184,8 @@ def resolve_dependencies(
direct_dependencies.append(dep)

if not direct_dependencies:
click.secho("Error: no requirements requested.")
if debug:
click.secho("Error: no requirements requested.")
sys.exit(1)

if debug:
Expand Down Expand Up @@ -235,6 +236,7 @@ def resolve_dependencies(
repos=repos,
as_tree=False,
max_rounds=max_rounds,
debug=debug,
)

cli_options = [f"--requirement {rf}" for rf in requirement_files]
Expand Down Expand Up @@ -271,7 +273,9 @@ def resolve_dependencies(
click.secho("done!")


def resolve(direct_dependencies, environment, repos=tuple(), as_tree=False, max_rounds=200000):
def resolve(
direct_dependencies, environment, repos=tuple(), as_tree=False, max_rounds=200000, debug=False
):
"""
Resolve dependencies given a ``direct_dependencies`` list of
DependentPackage and return a tuple of (initial_requirements,
Expand All @@ -288,6 +292,7 @@ def resolve(direct_dependencies, environment, repos=tuple(), as_tree=False, max_
repos=repos,
as_tree=as_tree,
max_rounds=max_rounds,
debug=debug,
)

initial_requirements = [d.to_dict() for d in direct_dependencies]
Expand Down