Skip to content

Commit 1e7cf2b

Browse files
authored
Merge pull request #83 from nexB/non_existing_package
Raise error for non existing package
2 parents ed7c4bf + 028e413 commit 1e7cf2b

21 files changed

+172
-126
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
=========
33

44

5+
v0.8.4
6+
------
7+
8+
- Raise error for non existing package.
9+
10+
511
v0.8.3
612
------
713

src/python_inspector/error.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# ScanCode is a trademark of nexB Inc.
6+
# SPDX-License-Identifier: Apache-2.0
7+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
8+
# See https://github.com/nexB/python-inspector for support or download.
9+
# See https://aboutcode.org for more information about nexB OSS projects.
10+
#
11+
12+
13+
class NoVersionsFound(Exception):
14+
pass

src/python_inspector/resolution.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from _packagedcode.pypi import SetupCfgHandler
4040
from _packagedcode.pypi import can_process_dependent_package
4141
from python_inspector import utils_pypi
42+
from python_inspector.error import NoVersionsFound
4243
from python_inspector.setup_py_live_eval import iter_requirements
4344
from python_inspector.utils_pypi import Environment
4445
from python_inspector.utils_pypi import PypiSimpleRepository
@@ -288,10 +289,17 @@ def remove_extras(identifier: str) -> str:
288289
return name
289290

290291

292+
DEFAULT_ENVIRONMENT = utils_pypi.Environment.from_pyver_and_os(
293+
python_version="38", operating_system="linux"
294+
)
295+
296+
291297
class PythonInputProvider(AbstractProvider):
292-
def __init__(self, environment=None, repos=tuple(), analyze_setup_py_insecurely=False):
298+
def __init__(
299+
self, environment=DEFAULT_ENVIRONMENT, repos=tuple(), analyze_setup_py_insecurely=False
300+
):
293301
self.environment = environment
294-
self.environment_marker = get_environment_marker_from_environment(environment)
302+
self.environment_marker = get_environment_marker_from_environment(self.environment)
295303
self.repos = repos or []
296304
self.versions_by_package = {}
297305
self.dependencies_by_purl = {}
@@ -472,7 +480,7 @@ def get_candidates(
472480
def _iter_matches(
473481
self,
474482
identifier: str,
475-
requirements: List[Requirement],
483+
requirements: Dict,
476484
incompatibilities: Dict,
477485
) -> Generator[Candidate, None, None]:
478486
"""
@@ -481,17 +489,24 @@ def _iter_matches(
481489
name = remove_extras(identifier=identifier)
482490
bad_versions = {c.version for c in incompatibilities[identifier]}
483491
extras = {e for r in requirements[identifier] for e in r.extras}
492+
versions = []
484493
if not self.repos:
485-
all_versions = self.get_versions_for_package(name=name)
486-
yield from self.get_candidates(
487-
all_versions, requirements, identifier, bad_versions, name, extras
488-
)
494+
versions.extend(self.get_versions_for_package(name=name))
489495
else:
490496
for repo in self.repos:
491-
all_versions = self.get_versions_for_package(name=name, repo=repo)
492-
yield from self.get_candidates(
493-
all_versions, requirements, identifier, bad_versions, name, extras
494-
)
497+
versions.extend(self.get_versions_for_package(name=name, repo=repo))
498+
499+
if not versions:
500+
raise NoVersionsFound(f"This package does not exist: {name}")
501+
502+
yield from self.get_candidates(
503+
all_versions=versions,
504+
requirements=requirements,
505+
identifier=identifier,
506+
bad_versions=bad_versions,
507+
name=name,
508+
extras=extras,
509+
)
495510

496511
def find_matches(
497512
self,

src/python_inspector/resolve_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
TRACE = False
3838

39-
__version__ = "0.8.3"
39+
__version__ = "0.8.4"
4040

4141
DEFAULT_PYTHON_VERSION = "38"
4242
PYPI_SIMPLE_URL = "https://pypi.org/simple"

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

+21-21
Large diffs are not rendered by default.

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

+21-21
Large diffs are not rendered by default.

tests/data/default-url-expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5-
"tool_version": "0.8.3",
5+
"tool_version": "0.8.4",
66
"options": [
77
"--specifier zipp==3.8.0",
88
"--index-url https://pypi.org/simple",

tests/data/environment-marker-test-requirements.txt-expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5-
"tool_version": "0.8.3",
5+
"tool_version": "0.8.4",
66
"options": [
77
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/environment-marker-test-requirements.txt",
88
"--index-url https://pypi.org/simple",

tests/data/frozen-requirements.txt-expected.json

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5-
"tool_version": "0.8.3",
5+
"tool_version": "0.8.4",
66
"options": [
77
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/frozen-requirements.txt",
88
"--index-url https://pypi.org/simple",
@@ -1846,7 +1846,7 @@
18461846
{
18471847
"key": "pip",
18481848
"package_name": "pip",
1849-
"installed_version": "22.2.2",
1849+
"installed_version": "22.3",
18501850
"dependencies": []
18511851
}
18521852
]
@@ -6010,12 +6010,12 @@
60106010
"type": "pypi",
60116011
"namespace": null,
60126012
"name": "pip",
6013-
"version": "22.2.2",
6013+
"version": "22.3",
60146014
"qualifiers": {},
60156015
"subpath": null,
60166016
"primary_language": "Python",
6017-
"description": "pip - The Python Package Installer\n==================================\n\n.. image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n\n.. image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIn pip 20.3, we've `made a big improvement to the heart of pip`_; `learn more`_. We want your input, so `sign up for our user experience research studies`_ to help us do it right.\n\n**Note**: pip 21.0, in January 2021, removed Python 2 support, per pip's `Python 2 support policy`_. Please migrate to Python 3.\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development mailing list`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _made a big improvement to the heart of pip: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html\n.. _learn more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020\n.. _sign up for our user experience research studies: https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html\n.. _Python 2 support policy: https://pip.pypa.io/en/latest/development/release-process/#python-2-support\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _Development mailing list: https://mail.python.org/mailman3/lists/distutils-sig.python.org/\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md\n",
6018-
"release_date": "2022-08-03T18:56:21",
6017+
"description": "pip - The Python Package Installer\n==================================\n\n.. image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n\n.. image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIn pip 20.3, we've `made a big improvement to the heart of pip`_; `learn more`_. We want your input, so `sign up for our user experience research studies`_ to help us do it right.\n\n**Note**: pip 21.0, in January 2021, removed Python 2 support, per pip's `Python 2 support policy`_. Please migrate to Python 3.\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _made a big improvement to the heart of pip: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html\n.. _learn more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020\n.. _sign up for our user experience research studies: https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html\n.. _Python 2 support policy: https://pip.pypa.io/en/latest/development/release-process/#python-2-support\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md\n",
6018+
"release_date": "2022-10-15T11:41:14",
60196019
"parties": [
60206020
{
60216021
"type": "person",
@@ -6034,11 +6034,11 @@
60346034
],
60356035
"keywords": [],
60366036
"homepage_url": "https://pip.pypa.io/",
6037-
"download_url": "https://files.pythonhosted.org/packages/1f/2c/d9626f045e7b49a6225c6b09257861f24da78f4e5f23af2ddbdf852c99b8/pip-22.2.2-py3-none-any.whl",
6038-
"size": 2044706,
6037+
"download_url": "https://files.pythonhosted.org/packages/47/ef/8b5470b5b94b36231ed9c0bde90caa71c0d4322d4a15f009b2b7f4287fe0/pip-22.3-py3-none-any.whl",
6038+
"size": 2051507,
60396039
"sha1": null,
6040-
"md5": "038988c69df6729ac9a7380930ec68f3",
6041-
"sha256": "b61a374b5bc40a6e982426aede40c9b5a08ff20e640f5b56977f4f91fed1e39a",
6040+
"md5": "6123dc5fc3483ebb12becce7faa4cd28",
6041+
"sha256": "1daab4b8d3b97d1d763caeb01a4640a2250a0ea899e257b1e44b9eded91e15ab",
60426042
"sha512": null,
60436043
"bug_tracking_url": null,
60446044
"code_view_url": "https://github.com/pypa/pip",
@@ -6053,20 +6053,20 @@
60536053
"dependencies": [],
60546054
"repository_homepage_url": null,
60556055
"repository_download_url": null,
6056-
"api_data_url": "https://pypi.org/pypi/pip/22.2.2/json",
6056+
"api_data_url": "https://pypi.org/pypi/pip/22.3/json",
60576057
"datasource_id": null,
6058-
"purl": "pkg:pypi/pip@22.2.2"
6058+
"purl": "pkg:pypi/pip@22.3"
60596059
},
60606060
{
60616061
"type": "pypi",
60626062
"namespace": null,
60636063
"name": "pip",
6064-
"version": "22.2.2",
6064+
"version": "22.3",
60656065
"qualifiers": {},
60666066
"subpath": null,
60676067
"primary_language": "Python",
6068-
"description": "pip - The Python Package Installer\n==================================\n\n.. image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n\n.. image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIn pip 20.3, we've `made a big improvement to the heart of pip`_; `learn more`_. We want your input, so `sign up for our user experience research studies`_ to help us do it right.\n\n**Note**: pip 21.0, in January 2021, removed Python 2 support, per pip's `Python 2 support policy`_. Please migrate to Python 3.\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development mailing list`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _made a big improvement to the heart of pip: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html\n.. _learn more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020\n.. _sign up for our user experience research studies: https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html\n.. _Python 2 support policy: https://pip.pypa.io/en/latest/development/release-process/#python-2-support\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _Development mailing list: https://mail.python.org/mailman3/lists/distutils-sig.python.org/\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md\n",
6069-
"release_date": "2022-08-03T18:56:25",
6068+
"description": "pip - The Python Package Installer\n==================================\n\n.. image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n\n.. image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIn pip 20.3, we've `made a big improvement to the heart of pip`_; `learn more`_. We want your input, so `sign up for our user experience research studies`_ to help us do it right.\n\n**Note**: pip 21.0, in January 2021, removed Python 2 support, per pip's `Python 2 support policy`_. Please migrate to Python 3.\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _made a big improvement to the heart of pip: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html\n.. _learn more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020\n.. _sign up for our user experience research studies: https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html\n.. _Python 2 support policy: https://pip.pypa.io/en/latest/development/release-process/#python-2-support\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md\n",
6069+
"release_date": "2022-10-15T11:41:17",
60706070
"parties": [
60716071
{
60726072
"type": "person",
@@ -6085,11 +6085,11 @@
60856085
],
60866086
"keywords": [],
60876087
"homepage_url": "https://pip.pypa.io/",
6088-
"download_url": "https://files.pythonhosted.org/packages/4b/30/e15b806597e67057e07a5acdc135216ccbf76a5f1681a324533b61066b0b/pip-22.2.2.tar.gz",
6089-
"size": 2036373,
6088+
"download_url": "https://files.pythonhosted.org/packages/f8/08/7f92782ff571c7c7cb6c5eeb8ebbb1f68cb02bdb24e55c5de4dd9ce98bc3/pip-22.3.tar.gz",
6089+
"size": 2077961,
60906090
"sha1": null,
6091-
"md5": "05bb8c0607721d171e9eecf22a8c5cc6",
6092-
"sha256": "3fd1929db052f056d7a998439176d3333fa1b3f6c1ad881de1885c0717608a4b",
6091+
"md5": "f0dd02265e7ccd2f8758c840fba64810",
6092+
"sha256": "8182aec21dad6c0a49a2a3d121a87cd524b950e0b6092b181625f07ebdde7530",
60936093
"sha512": null,
60946094
"bug_tracking_url": null,
60956095
"code_view_url": "https://github.com/pypa/pip",
@@ -6104,9 +6104,9 @@
61046104
"dependencies": [],
61056105
"repository_homepage_url": null,
61066106
"repository_download_url": null,
6107-
"api_data_url": "https://pypi.org/pypi/pip/22.2.2/json",
6107+
"api_data_url": "https://pypi.org/pypi/pip/22.3/json",
61086108
"datasource_id": null,
6109-
"purl": "pkg:pypi/pip@22.2.2"
6109+
"purl": "pkg:pypi/pip@22.3"
61106110
},
61116111
{
61126112
"type": "pypi",

0 commit comments

Comments
 (0)