Skip to content

Commit a807c15

Browse files
authored
[feature] Add ignore error mode (#159)
1 parent 042f5db commit a807c15

9 files changed

+980
-39
lines changed

src/python_inspector/api.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def to_dict(self, generic_paths=False):
6565
for file in files:
6666
path = file["path"]
6767
file["path"] = utils.remove_test_data_dir_variable_prefix(path=path)
68-
6968
return {
7069
"files": files,
7170
"packages": [package for package in self.packages],
@@ -90,6 +89,7 @@ def resolve_dependencies(
9089
prefer_source=False,
9190
printer=print,
9291
generic_paths=False,
92+
ignore_errors=False,
9393
):
9494
"""
9595
Resolve the dependencies for the package requirements listed in one or
@@ -284,6 +284,7 @@ def resolve_dependencies(
284284
max_rounds=max_rounds,
285285
pdt_output=pdt_output,
286286
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
287+
ignore_errors=ignore_errors,
287288
)
288289

289290
packages = []
@@ -321,6 +322,7 @@ def resolve(
321322
max_rounds=200000,
322323
pdt_output=False,
323324
analyze_setup_py_insecurely=False,
325+
ignore_errors=False,
324326
):
325327
"""
326328
Resolve dependencies given a ``direct_dependencies`` list of
@@ -346,6 +348,7 @@ def resolve(
346348
max_rounds=max_rounds,
347349
pdt_output=pdt_output,
348350
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
351+
ignore_errors=ignore_errors,
349352
)
350353

351354
return resolved_dependencies, packages
@@ -359,6 +362,7 @@ def get_resolved_dependencies(
359362
max_rounds: int = 200000,
360363
pdt_output: bool = False,
361364
analyze_setup_py_insecurely: bool = False,
365+
ignore_errors: bool = False,
362366
):
363367
"""
364368
Return resolved dependencies of a ``requirements`` list of Requirement for
@@ -373,6 +377,7 @@ def get_resolved_dependencies(
373377
environment=environment,
374378
repos=repos,
375379
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
380+
ignore_errors=ignore_errors,
376381
),
377382
reporter=BaseReporter(),
378383
)

src/python_inspector/resolution.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ def get_requirements_from_python_manifest(
352352

353353
class PythonInputProvider(AbstractProvider):
354354
def __init__(
355-
self, environment=DEFAULT_ENVIRONMENT, repos=tuple(), analyze_setup_py_insecurely=False
355+
self,
356+
environment=DEFAULT_ENVIRONMENT,
357+
repos=tuple(),
358+
analyze_setup_py_insecurely=True,
359+
ignore_errors=False,
356360
):
357361
self.environment = environment
358362
self.environment_marker = get_environment_marker_from_environment(self.environment)
@@ -361,6 +365,7 @@ def __init__(
361365
self.dependencies_by_purl = {}
362366
self.wheel_or_sdist_by_package = {}
363367
self.analyze_setup_py_insecurely = analyze_setup_py_insecurely
368+
self.ignore_errors = ignore_errors
364369

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

585590
if not versions:
586-
raise NoVersionsFound(f"This package does not exist: {name}")
587-
591+
if self.ignore_errors:
592+
yield from [Candidate("NonExistant", "0.0.0", "")]
593+
return
594+
else:
595+
raise NoVersionsFound(f"This package does not exist: {name}")
588596
yield from self.get_candidates(
589597
all_versions=versions,
590598
requirements=requirements,

src/python_inspector/resolve_cli.py

+5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def print_version(ctx, param, value):
173173
callback=print_version,
174174
help="Show the version and exit.",
175175
)
176+
@click.option(
177+
"--ignore-errors", is_flag=True, default=False, help="Ignore errors and continue execution."
178+
)
176179
@click.help_option("-h", "--help")
177180
@click.option(
178181
"--generic-paths",
@@ -199,6 +202,7 @@ def resolve_dependencies(
199202
prefer_source=False,
200203
verbose=TRACE,
201204
generic_paths=False,
205+
ignore_errors=False,
202206
):
203207
"""
204208
Resolve the dependencies for the package requirements listed in one or
@@ -266,6 +270,7 @@ def resolve_dependencies(
266270
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
267271
printer=click.secho,
268272
prefer_source=prefer_source,
273+
ignore_errors=ignore_errors,
269274
generic_paths=generic_paths,
270275
)
271276

tests/data/azure-devops.req-310-expected.json

+19-17
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@
248248
"type": "pypi",
249249
"namespace": null,
250250
"name": "azure-devops",
251-
"version": "7.1.0b3",
251+
"version": "7.1.0b4",
252252
"qualifiers": {},
253253
"subpath": null,
254254
"primary_language": "Python",
255255
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
256-
"release_date": "2023-04-26T17:38:59",
256+
"release_date": "2023-11-20T14:38:02",
257257
"parties": [
258258
{
259259
"type": "person",
@@ -278,16 +278,17 @@
278278
"Programming Language :: Python :: 3",
279279
"Programming Language :: Python :: 3.10",
280280
"Programming Language :: Python :: 3.11",
281+
"Programming Language :: Python :: 3.12",
281282
"Programming Language :: Python :: 3.7",
282283
"Programming Language :: Python :: 3.8",
283284
"Programming Language :: Python :: 3.9"
284285
],
285286
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
286-
"download_url": "https://files.pythonhosted.org/packages/2f/26/0be5efeeef498ac42b2c1c0d29dd9dc1917e19aab7e442a3f521122a7093/azure_devops-7.1.0b3-py3-none-any.whl",
287-
"size": 1555021,
287+
"download_url": "https://files.pythonhosted.org/packages/9a/30/067b9aba3cb146f4334afb737eb86c4f66e2b645fbca770377253550a9b3/azure_devops-7.1.0b4-py3-none-any.whl",
288+
"size": 1554711,
288289
"sha1": null,
289-
"md5": "b9373f77e9cd0a737d0648e79062ff56",
290-
"sha256": "ef082a59e79e7f5d979481c7737093cb54618f362b216292fcce7f26d9c452c3",
290+
"md5": "5f916043df39453932e3214d309450d0",
291+
"sha256": "f827e9fbc7c77bc6f2aaee46e5717514e9fe7d676c87624eccd0ca640b54f122",
291292
"sha512": null,
292293
"bug_tracking_url": null,
293294
"code_view_url": null,
@@ -307,20 +308,20 @@
307308
"dependencies": [],
308309
"repository_homepage_url": null,
309310
"repository_download_url": null,
310-
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
311+
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
311312
"datasource_id": null,
312-
"purl": "pkg:pypi/[email protected].0b3"
313+
"purl": "pkg:pypi/[email protected].0b4"
313314
},
314315
{
315316
"type": "pypi",
316317
"namespace": null,
317318
"name": "azure-devops",
318-
"version": "7.1.0b3",
319+
"version": "7.1.0b4",
319320
"qualifiers": {},
320321
"subpath": null,
321322
"primary_language": "Python",
322323
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
323-
"release_date": "2023-04-26T17:39:02",
324+
"release_date": "2023-11-20T14:38:06",
324325
"parties": [
325326
{
326327
"type": "person",
@@ -345,16 +346,17 @@
345346
"Programming Language :: Python :: 3",
346347
"Programming Language :: Python :: 3.10",
347348
"Programming Language :: Python :: 3.11",
349+
"Programming Language :: Python :: 3.12",
348350
"Programming Language :: Python :: 3.7",
349351
"Programming Language :: Python :: 3.8",
350352
"Programming Language :: Python :: 3.9"
351353
],
352354
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
353-
"download_url": "https://files.pythonhosted.org/packages/48/1b/a6198ee1d90aa9c8d23ff1b3a9f7ea680c445e42a810cb32f465990bcd01/azure-devops-7.1.0b3.tar.gz",
354-
"size": 1336724,
355+
"download_url": "https://files.pythonhosted.org/packages/e1/f9/495982345252dc7a15ac632e038be1f975ca0d2f25abfe8f8d908569141d/azure-devops-7.1.0b4.tar.gz",
356+
"size": 1336261,
355357
"sha1": null,
356-
"md5": "aa3428f6ee9a66111e4002e9e1528c3e",
357-
"sha256": "644e34d110f016e65c7b36647274c90c20223bf2ecca9be8806aa5a4c754b4e7",
358+
"md5": "bf401acf6533d4a2dcfd2106ffcbc86a",
359+
"sha256": "f04ba939112579f3d530cfecc044a74ef9e9339ba23c9ee1ece248241f07ff85",
358360
"sha512": null,
359361
"bug_tracking_url": null,
360362
"code_view_url": null,
@@ -374,9 +376,9 @@
374376
"dependencies": [],
375377
"repository_homepage_url": null,
376378
"repository_download_url": null,
377-
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
379+
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
378380
"datasource_id": null,
379-
"purl": "pkg:pypi/[email protected].0b3"
381+
"purl": "pkg:pypi/[email protected].0b4"
380382
},
381383
{
382384
"type": "pypi",
@@ -2489,7 +2491,7 @@
24892491
]
24902492
},
24912493
{
2492-
"package": "pkg:pypi/[email protected].0b3",
2494+
"package": "pkg:pypi/[email protected].0b4",
24932495
"dependencies": [
24942496
"pkg:pypi/[email protected]"
24952497
]

tests/data/azure-devops.req-38-expected.json

+19-17
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@
248248
"type": "pypi",
249249
"namespace": null,
250250
"name": "azure-devops",
251-
"version": "7.1.0b3",
251+
"version": "7.1.0b4",
252252
"qualifiers": {},
253253
"subpath": null,
254254
"primary_language": "Python",
255255
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
256-
"release_date": "2023-04-26T17:38:59",
256+
"release_date": "2023-11-20T14:38:02",
257257
"parties": [
258258
{
259259
"type": "person",
@@ -278,16 +278,17 @@
278278
"Programming Language :: Python :: 3",
279279
"Programming Language :: Python :: 3.10",
280280
"Programming Language :: Python :: 3.11",
281+
"Programming Language :: Python :: 3.12",
281282
"Programming Language :: Python :: 3.7",
282283
"Programming Language :: Python :: 3.8",
283284
"Programming Language :: Python :: 3.9"
284285
],
285286
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
286-
"download_url": "https://files.pythonhosted.org/packages/2f/26/0be5efeeef498ac42b2c1c0d29dd9dc1917e19aab7e442a3f521122a7093/azure_devops-7.1.0b3-py3-none-any.whl",
287-
"size": 1555021,
287+
"download_url": "https://files.pythonhosted.org/packages/9a/30/067b9aba3cb146f4334afb737eb86c4f66e2b645fbca770377253550a9b3/azure_devops-7.1.0b4-py3-none-any.whl",
288+
"size": 1554711,
288289
"sha1": null,
289-
"md5": "b9373f77e9cd0a737d0648e79062ff56",
290-
"sha256": "ef082a59e79e7f5d979481c7737093cb54618f362b216292fcce7f26d9c452c3",
290+
"md5": "5f916043df39453932e3214d309450d0",
291+
"sha256": "f827e9fbc7c77bc6f2aaee46e5717514e9fe7d676c87624eccd0ca640b54f122",
291292
"sha512": null,
292293
"bug_tracking_url": null,
293294
"code_view_url": null,
@@ -307,20 +308,20 @@
307308
"dependencies": [],
308309
"repository_homepage_url": null,
309310
"repository_download_url": null,
310-
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
311+
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
311312
"datasource_id": null,
312-
"purl": "pkg:pypi/[email protected].0b3"
313+
"purl": "pkg:pypi/[email protected].0b4"
313314
},
314315
{
315316
"type": "pypi",
316317
"namespace": null,
317318
"name": "azure-devops",
318-
"version": "7.1.0b3",
319+
"version": "7.1.0b4",
319320
"qualifiers": {},
320321
"subpath": null,
321322
"primary_language": "Python",
322323
"description": "Python wrapper around the Azure DevOps 7.x APIs\nAzure DevOps Python clients",
323-
"release_date": "2023-04-26T17:39:02",
324+
"release_date": "2023-11-20T14:38:06",
324325
"parties": [
325326
{
326327
"type": "person",
@@ -345,16 +346,17 @@
345346
"Programming Language :: Python :: 3",
346347
"Programming Language :: Python :: 3.10",
347348
"Programming Language :: Python :: 3.11",
349+
"Programming Language :: Python :: 3.12",
348350
"Programming Language :: Python :: 3.7",
349351
"Programming Language :: Python :: 3.8",
350352
"Programming Language :: Python :: 3.9"
351353
],
352354
"homepage_url": "https://github.com/microsoft/azure-devops-python-api",
353-
"download_url": "https://files.pythonhosted.org/packages/48/1b/a6198ee1d90aa9c8d23ff1b3a9f7ea680c445e42a810cb32f465990bcd01/azure-devops-7.1.0b3.tar.gz",
354-
"size": 1336724,
355+
"download_url": "https://files.pythonhosted.org/packages/e1/f9/495982345252dc7a15ac632e038be1f975ca0d2f25abfe8f8d908569141d/azure-devops-7.1.0b4.tar.gz",
356+
"size": 1336261,
355357
"sha1": null,
356-
"md5": "aa3428f6ee9a66111e4002e9e1528c3e",
357-
"sha256": "644e34d110f016e65c7b36647274c90c20223bf2ecca9be8806aa5a4c754b4e7",
358+
"md5": "bf401acf6533d4a2dcfd2106ffcbc86a",
359+
"sha256": "f04ba939112579f3d530cfecc044a74ef9e9339ba23c9ee1ece248241f07ff85",
358360
"sha512": null,
359361
"bug_tracking_url": null,
360362
"code_view_url": null,
@@ -374,9 +376,9 @@
374376
"dependencies": [],
375377
"repository_homepage_url": null,
376378
"repository_download_url": null,
377-
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b3/json",
379+
"api_data_url": "https://pypi.org/pypi/azure-devops/7.1.0b4/json",
378380
"datasource_id": null,
379-
"purl": "pkg:pypi/[email protected].0b3"
381+
"purl": "pkg:pypi/[email protected].0b4"
380382
},
381383
{
382384
"type": "pypi",
@@ -2489,7 +2491,7 @@
24892491
]
24902492
},
24912493
{
2492-
"package": "pkg:pypi/[email protected].0b3",
2494+
"package": "pkg:pypi/[email protected].0b4",
24932495
"dependencies": [
24942496
"pkg:pypi/[email protected]"
24952497
]

tests/data/error-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
noexistingpacjagee

0 commit comments

Comments
 (0)