Skip to content

Commit

Permalink
[feature] Add ignore error mode (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
qequ authored Nov 21, 2023
1 parent 042f5db commit a807c15
Show file tree
Hide file tree
Showing 9 changed files with 980 additions and 39 deletions.
7 changes: 6 additions & 1 deletion src/python_inspector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def to_dict(self, generic_paths=False):
for file in files:
path = file["path"]
file["path"] = utils.remove_test_data_dir_variable_prefix(path=path)

return {
"files": files,
"packages": [package for package in self.packages],
Expand All @@ -90,6 +89,7 @@ def resolve_dependencies(
prefer_source=False,
printer=print,
generic_paths=False,
ignore_errors=False,
):
"""
Resolve the dependencies for the package requirements listed in one or
Expand Down Expand Up @@ -284,6 +284,7 @@ def resolve_dependencies(
max_rounds=max_rounds,
pdt_output=pdt_output,
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
ignore_errors=ignore_errors,
)

packages = []
Expand Down Expand Up @@ -321,6 +322,7 @@ def resolve(
max_rounds=200000,
pdt_output=False,
analyze_setup_py_insecurely=False,
ignore_errors=False,
):
"""
Resolve dependencies given a ``direct_dependencies`` list of
Expand All @@ -346,6 +348,7 @@ def resolve(
max_rounds=max_rounds,
pdt_output=pdt_output,
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
ignore_errors=ignore_errors,
)

return resolved_dependencies, packages
Expand All @@ -359,6 +362,7 @@ def get_resolved_dependencies(
max_rounds: int = 200000,
pdt_output: bool = False,
analyze_setup_py_insecurely: bool = False,
ignore_errors: bool = False,
):
"""
Return resolved dependencies of a ``requirements`` list of Requirement for
Expand All @@ -373,6 +377,7 @@ def get_resolved_dependencies(
environment=environment,
repos=repos,
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
ignore_errors=ignore_errors,
),
reporter=BaseReporter(),
)
Expand Down
14 changes: 11 additions & 3 deletions src/python_inspector/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ def get_requirements_from_python_manifest(

class PythonInputProvider(AbstractProvider):
def __init__(
self, environment=DEFAULT_ENVIRONMENT, repos=tuple(), analyze_setup_py_insecurely=False
self,
environment=DEFAULT_ENVIRONMENT,
repos=tuple(),
analyze_setup_py_insecurely=True,
ignore_errors=False,
):
self.environment = environment
self.environment_marker = get_environment_marker_from_environment(self.environment)
Expand All @@ -361,6 +365,7 @@ def __init__(
self.dependencies_by_purl = {}
self.wheel_or_sdist_by_package = {}
self.analyze_setup_py_insecurely = analyze_setup_py_insecurely
self.ignore_errors = ignore_errors

def identify(self, requirement_or_candidate: Union[Candidate, Requirement]) -> str:
"""Given a requirement, return an identifier for it. Overridden."""
Expand Down Expand Up @@ -583,8 +588,11 @@ def _iter_matches(
versions.extend(self.get_versions_for_package(name=name, repo=repo))

if not versions:
raise NoVersionsFound(f"This package does not exist: {name}")

if self.ignore_errors:
yield from [Candidate("NonExistant", "0.0.0", "")]
return
else:
raise NoVersionsFound(f"This package does not exist: {name}")
yield from self.get_candidates(
all_versions=versions,
requirements=requirements,
Expand Down
5 changes: 5 additions & 0 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def print_version(ctx, param, value):
callback=print_version,
help="Show the version and exit.",
)
@click.option(
"--ignore-errors", is_flag=True, default=False, help="Ignore errors and continue execution."
)
@click.help_option("-h", "--help")
@click.option(
"--generic-paths",
Expand All @@ -199,6 +202,7 @@ def resolve_dependencies(
prefer_source=False,
verbose=TRACE,
generic_paths=False,
ignore_errors=False,
):
"""
Resolve the dependencies for the package requirements listed in one or
Expand Down Expand Up @@ -266,6 +270,7 @@ def resolve_dependencies(
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
printer=click.secho,
prefer_source=prefer_source,
ignore_errors=ignore_errors,
generic_paths=generic_paths,
)

Expand Down
36 changes: 19 additions & 17 deletions tests/data/azure-devops.req-310-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@
"type": "pypi",
"namespace": null,
"name": "azure-devops",
"version": "7.1.0b3",
"version": "7.1.0b4",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
"release_date": "2023-04-26T17:38:59",
"release_date": "2023-11-20T14:38:02",
"parties": [
{
"type": "person",
Expand All @@ -278,16 +278,17 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
"download_url": "https://files.pythonhosted.org/packages/2f/26/0be5efeeef498ac42b2c1c0d29dd9dc1917e19aab7e442a3f521122a7093/azure_devops-7.1.0b3-py3-none-any.whl",
"size": 1555021,
"download_url": "https://files.pythonhosted.org/packages/9a/30/067b9aba3cb146f4334afb737eb86c4f66e2b645fbca770377253550a9b3/azure_devops-7.1.0b4-py3-none-any.whl",
"size": 1554711,
"sha1": null,
"md5": "b9373f77e9cd0a737d0648e79062ff56",
"sha256": "ef082a59e79e7f5d979481c7737093cb54618f362b216292fcce7f26d9c452c3",
"md5": "5f916043df39453932e3214d309450d0",
"sha256": "f827e9fbc7c77bc6f2aaee46e5717514e9fe7d676c87624eccd0ca640b54f122",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -307,20 +308,20 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].0b3"
"purl": "pkg:pypi/[email protected].0b4"
},
{
"type": "pypi",
"namespace": null,
"name": "azure-devops",
"version": "7.1.0b3",
"version": "7.1.0b4",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
"release_date": "2023-04-26T17:39:02",
"release_date": "2023-11-20T14:38:06",
"parties": [
{
"type": "person",
Expand All @@ -345,16 +346,17 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
"download_url": "https://files.pythonhosted.org/packages/48/1b/a6198ee1d90aa9c8d23ff1b3a9f7ea680c445e42a810cb32f465990bcd01/azure-devops-7.1.0b3.tar.gz",
"size": 1336724,
"download_url": "https://files.pythonhosted.org/packages/e1/f9/495982345252dc7a15ac632e038be1f975ca0d2f25abfe8f8d908569141d/azure-devops-7.1.0b4.tar.gz",
"size": 1336261,
"sha1": null,
"md5": "aa3428f6ee9a66111e4002e9e1528c3e",
"sha256": "644e34d110f016e65c7b36647274c90c20223bf2ecca9be8806aa5a4c754b4e7",
"md5": "bf401acf6533d4a2dcfd2106ffcbc86a",
"sha256": "f04ba939112579f3d530cfecc044a74ef9e9339ba23c9ee1ece248241f07ff85",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -374,9 +376,9 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].0b3"
"purl": "pkg:pypi/[email protected].0b4"
},
{
"type": "pypi",
Expand Down Expand Up @@ -2489,7 +2491,7 @@
]
},
{
"package": "pkg:pypi/[email protected].0b3",
"package": "pkg:pypi/[email protected].0b4",
"dependencies": [
"pkg:pypi/[email protected]"
]
Expand Down
36 changes: 19 additions & 17 deletions tests/data/azure-devops.req-38-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@
"type": "pypi",
"namespace": null,
"name": "azure-devops",
"version": "7.1.0b3",
"version": "7.1.0b4",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
"release_date": "2023-04-26T17:38:59",
"release_date": "2023-11-20T14:38:02",
"parties": [
{
"type": "person",
Expand All @@ -278,16 +278,17 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
"download_url": "https://files.pythonhosted.org/packages/2f/26/0be5efeeef498ac42b2c1c0d29dd9dc1917e19aab7e442a3f521122a7093/azure_devops-7.1.0b3-py3-none-any.whl",
"size": 1555021,
"download_url": "https://files.pythonhosted.org/packages/9a/30/067b9aba3cb146f4334afb737eb86c4f66e2b645fbca770377253550a9b3/azure_devops-7.1.0b4-py3-none-any.whl",
"size": 1554711,
"sha1": null,
"md5": "b9373f77e9cd0a737d0648e79062ff56",
"sha256": "ef082a59e79e7f5d979481c7737093cb54618f362b216292fcce7f26d9c452c3",
"md5": "5f916043df39453932e3214d309450d0",
"sha256": "f827e9fbc7c77bc6f2aaee46e5717514e9fe7d676c87624eccd0ca640b54f122",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -307,20 +308,20 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].0b3"
"purl": "pkg:pypi/[email protected].0b4"
},
{
"type": "pypi",
"namespace": null,
"name": "azure-devops",
"version": "7.1.0b3",
"version": "7.1.0b4",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
"release_date": "2023-04-26T17:39:02",
"release_date": "2023-11-20T14:38:06",
"parties": [
{
"type": "person",
Expand All @@ -345,16 +346,17 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
"download_url": "https://files.pythonhosted.org/packages/48/1b/a6198ee1d90aa9c8d23ff1b3a9f7ea680c445e42a810cb32f465990bcd01/azure-devops-7.1.0b3.tar.gz",
"size": 1336724,
"download_url": "https://files.pythonhosted.org/packages/e1/f9/495982345252dc7a15ac632e038be1f975ca0d2f25abfe8f8d908569141d/azure-devops-7.1.0b4.tar.gz",
"size": 1336261,
"sha1": null,
"md5": "aa3428f6ee9a66111e4002e9e1528c3e",
"sha256": "644e34d110f016e65c7b36647274c90c20223bf2ecca9be8806aa5a4c754b4e7",
"md5": "bf401acf6533d4a2dcfd2106ffcbc86a",
"sha256": "f04ba939112579f3d530cfecc044a74ef9e9339ba23c9ee1ece248241f07ff85",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -374,9 +376,9 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].0b3"
"purl": "pkg:pypi/[email protected].0b4"
},
{
"type": "pypi",
Expand Down Expand Up @@ -2489,7 +2491,7 @@
]
},
{
"package": "pkg:pypi/[email protected].0b3",
"package": "pkg:pypi/[email protected].0b4",
"dependencies": [
"pkg:pypi/[email protected]"
]
Expand Down
2 changes: 2 additions & 0 deletions tests/data/error-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
noexistingpacjagee
Loading

0 comments on commit a807c15

Please sign in to comment.