diff --git a/src/python_inspector/resolution.py b/src/python_inspector/resolution.py index e37d18b1..116c7e4d 100644 --- a/src/python_inspector/resolution.py +++ b/src/python_inspector/resolution.py @@ -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 @@ -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) diff --git a/src/python_inspector/resolve_cli.py b/src/python_inspector/resolve_cli.py index 9babbe17..8d0d9e2c 100644 --- a/src/python_inspector/resolve_cli.py +++ b/src/python_inspector/resolve_cli.py @@ -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: @@ -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: @@ -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] @@ -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, @@ -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]