Skip to content

Commit

Permalink
Replaced Packaging module with Packvers in different files.
Browse files Browse the repository at this point in the history
Signed-off-by: swastik <[email protected]>
  • Loading branch information
TG1999 authored and swastkk committed Jan 12, 2023
1 parent a5891f4 commit eae13cf
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 532 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ v0.9.3
------

- Add support for recursive requirements.
- Add python 3.11 as a valid python version in choices.
- Operating system and python version are now required fields in CLI.
- Add dot versions (3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 2.7) with
current python version choices for CLI (36, 37, 38, 39, 310, 311, 27).


v0.9.2
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ charset-normalizer==2.1.0
click==8.1.3
colorama==0.4.5
commoncode==30.2.0
dparse2==0.6.1
dparse2==0.7.0
idna==3.3
importlib-metadata==4.12.0
intbitset==3.0.1
packageurl-python==0.10.0
packaging==21.3
pip-requirements-parser==31.2.0
packvers==21.5
pip-requirements-parser==32.0.1
pkginfo2==30.0.0
pyparsing==3.0.9
PyYAML==6.0
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ install_requires =
click > 7.0
colorama >= 0.3.9
commoncode >= 30.0.0
dparse2 >= 0.6.1
dparse2 >= 0.7.0
importlib_metadata >= 4.12.0
packageurl_python >= 0.9.0
pkginfo2 >= 30.0.0
pip-requirements-parser >= 31.2.0
pip-requirements-parser >= 32.0.1
requests >= 2.18.0
resolvelib >= 0.8.1
saneyaml >= 0.5.2
tinynetrc >= 1.3.1
toml >= 0.10.0
mock >= 3.0.5

packaging >= 21.0.0
packvers >= 21.5
[options.packages.find]
where = src

Expand Down
11 changes: 5 additions & 6 deletions src/_packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import zipfile

import dparse2
import packaging
import packvers as packaging
import pip_requirements_parser
import pkginfo2
from commoncode import fileutils
from packaging.specifiers import SpecifierSet
from packvers.specifiers import SpecifierSet
from packageurl import PackageURL
from packaging import markers
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
from packvers import markers
from packvers.requirements import Requirement
from packvers.utils import canonicalize_name

from _packagedcode import models
from _packagedcode.utils import build_description
Expand Down
7 changes: 5 additions & 2 deletions src/python_inspector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Sequence

from packageurl import PackageURL
from packaging.requirements import Requirement
from packvers.requirements import Requirement
from resolvelib import BaseReporter
from resolvelib import Resolver
from tinynetrc import Netrc
Expand All @@ -40,8 +40,8 @@
from python_inspector.resolution import get_requirements_from_python_manifest
from python_inspector.utils_pypi import PLATFORMS_BY_OS
from python_inspector.utils_pypi import PYPI_SIMPLE_URL
from python_inspector.utils_pypi import PYTHON_DOT_VERSIONS_BY_VER
from python_inspector.utils_pypi import Environment
from python_inspector.utils_pypi import valid_python_versions


class Resolution(NamedTuple):
Expand Down Expand Up @@ -103,6 +103,9 @@ def resolve_dependencies(
f"Must be one of: {', '.join(PLATFORMS_BY_OS.keys())}"
)

valid_python_versions = list(PYTHON_DOT_VERSIONS_BY_VER.keys())
valid_python_versions.extend([dot_ver for pyver, dot_ver in PYTHON_DOT_VERSIONS_BY_VER.items()])

if not python_version:
raise Exception(f"No python version provided.")
if python_version not in valid_python_versions:
Expand Down
2 changes: 1 addition & 1 deletion src/python_inspector/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

from packageurl import PackageURL
from packaging.requirements import Requirement
from packvers.requirements import Requirement
from pip_requirements_parser import InstallRequirement

from _packagedcode import models
Expand Down
14 changes: 7 additions & 7 deletions src/python_inspector/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from typing import Union
from zipfile import ZipFile

import packaging.utils
import packvers.utils
from packageurl import PackageURL
from packaging.requirements import Requirement
from packaging.version import LegacyVersion
from packaging.version import Version
from packaging.version import parse as parse_version
from packvers.requirements import Requirement
from packvers.version import LegacyVersion
from packvers.version import Version
from packvers.version import parse as parse_version
from resolvelib import AbstractProvider
from resolvelib.structs import DirectedGraph

Expand Down Expand Up @@ -325,7 +325,7 @@ def __init__(

def identify(self, requirement_or_candidate: Union[Candidate, Requirement]) -> str:
"""Given a requirement, return an identifier for it. Overridden."""
name = packaging.utils.canonicalize_name(requirement_or_candidate.name)
name = packvers.utils.canonicalize_name(requirement_or_candidate.name)
if requirement_or_candidate.extras:
extras_str = ",".join(sorted(requirement_or_candidate.extras))
return "{}[{}]".format(name, extras_str)
Expand Down Expand Up @@ -576,7 +576,7 @@ def _iter_dependencies(self, candidate: Candidate) -> Generator[Requirement, Non
"""
Yield dependencies for the given candidate.
"""
name = packaging.utils.canonicalize_name(candidate.name)
name = packvers.utils.canonicalize_name(candidate.name)
# TODO: handle extras https://github.com/nexB/python-inspector/issues/10
if candidate.extras:
r = f"{name}=={candidate.version}"
Expand Down
4 changes: 1 addition & 3 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ def print_version(ctx, param, value):
"-p",
"--python-version",
"python_version",
type=click.Choice(utils_pypi.valid_python_versions),
type=click.Choice(utils_pypi.PYTHON_VERSIONS),
metavar="PYVER",
show_default=True,
required=True,
help="Python version to use for dependency resolution.",
)
@click.option(
Expand All @@ -83,7 +82,6 @@ def print_version(ctx, param, value):
type=click.Choice(utils_pypi.PLATFORMS_BY_OS),
metavar="OS",
show_default=True,
required=True,
help="OS to use for dependency resolution.",
)
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion src/python_inspector/setup_py_live_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import mock
import setuptools
from commoncode.command import pushd
from packaging.requirements import Requirement
from packvers.requirements import Requirement


def minver_error(pkg_name):
Expand Down
12 changes: 6 additions & 6 deletions src/python_inspector/utils_pip_compatibility_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

import re

from packaging.tags import compatible_tags
from packaging.tags import cpython_tags
from packaging.tags import generic_tags
from packaging.tags import interpreter_name
from packaging.tags import interpreter_version
from packaging.tags import mac_platforms
from packvers.tags import compatible_tags
from packvers.tags import cpython_tags
from packvers.tags import generic_tags
from packvers.tags import interpreter_name
from packvers.tags import interpreter_version
from packvers.tags import mac_platforms

_osx_arch_pat = re.compile(r"(.+)_(\d+)_(\d+)_(.+)")

Expand Down
13 changes: 4 additions & 9 deletions src/python_inspector/utils_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from bs4 import BeautifulSoup
from commoncode import fileutils
from commoncode.hash import multi_checksums
from packaging import tags as packaging_tags
from packaging import version as packaging_version
from packaging.specifiers import SpecifierSet
from packvers import tags as packaging_tags
from packvers import version as packaging_version
from packvers.specifiers import SpecifierSet

from python_inspector import DEFAULT_PYTHON_VERSION
from python_inspector import utils_pip_compatibility_tags
Expand Down Expand Up @@ -98,7 +98,7 @@
TRACE_ULTRA_DEEP = False

# Supported environments
PYTHON_VERSIONS = "36", "37", "38", "39", "310", "311", "27"
PYTHON_VERSIONS = "36", "37", "38", "39", "310", "27"

PYTHON_DOT_VERSIONS_BY_VER = {
"36": "3.6",
Expand All @@ -107,12 +107,8 @@
"39": "3.9",
"310": "3.10",
"27": "2.7",
"311": "3.11",
}

valid_python_versions = list(PYTHON_DOT_VERSIONS_BY_VER.keys())
valid_python_versions.extend([dot_ver for pyver, dot_ver in PYTHON_DOT_VERSIONS_BY_VER.items()])


def get_python_dot_version(version):
"""
Expand All @@ -127,7 +123,6 @@ def get_python_dot_version(version):
"38": ["cp38", "cp38m", "abi3"],
"39": ["cp39", "cp39m", "abi3"],
"310": ["cp310", "cp310m", "abi3"],
"311": ["cp311", "cp311m", "abi3"],
"27": ["cp27", "cp27m"],
}

Expand Down
34 changes: 17 additions & 17 deletions tests/data/frozen-requirements.txt-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6013,12 +6013,12 @@
"type": "pypi",
"namespace": null,
"name": "pip",
"version": "22.3.1",
"version": "22.3",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "The PyPA recommended tool for installing Python packages.\npip - 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",
"release_date": "2022-11-05T15:56:17",
"release_date": "2022-10-15T11:41:14",
"parties": [
{
"type": "person",
Expand All @@ -6044,11 +6044,11 @@
"Topic :: Software Development :: Build Tools"
],
"homepage_url": "https://pip.pypa.io/",
"download_url": "https://files.pythonhosted.org/packages/09/bd/2410905c76ee14c62baf69e3f4aa780226c1bbfc9485731ad018e35b0cb5/pip-22.3.1-py3-none-any.whl",
"size": 2051534,
"download_url": "https://files.pythonhosted.org/packages/47/ef/8b5470b5b94b36231ed9c0bde90caa71c0d4322d4a15f009b2b7f4287fe0/pip-22.3-py3-none-any.whl",
"size": 2051507,
"sha1": null,
"md5": "74d0d338e0af6ca545d6ce7ef9734d75",
"sha256": "908c78e6bc29b676ede1c4d57981d490cb892eb45cd8c214ab6298125119e077",
"md5": "6123dc5fc3483ebb12becce7faa4cd28",
"sha256": "1daab4b8d3b97d1d763caeb01a4640a2250a0ea899e257b1e44b9eded91e15ab",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": "https://github.com/pypa/pip",
Expand All @@ -6068,20 +6068,20 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/pip/22.3.1/json",
"api_data_url": "https://pypi.org/pypi/pip/22.3/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].1"
"purl": "pkg:pypi/[email protected]"
},
{
"type": "pypi",
"namespace": null,
"name": "pip",
"version": "22.3.1",
"version": "22.3",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "The PyPA recommended tool for installing Python packages.\npip - 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",
"release_date": "2022-11-05T15:56:20",
"release_date": "2022-10-15T11:41:17",
"parties": [
{
"type": "person",
Expand All @@ -6107,11 +6107,11 @@
"Topic :: Software Development :: Build Tools"
],
"homepage_url": "https://pip.pypa.io/",
"download_url": "https://files.pythonhosted.org/packages/a3/50/c4d2727b99052780aad92c7297465af5fe6eec2dbae490aa9763273ffdc1/pip-22.3.1.tar.gz",
"size": 2078129,
"download_url": "https://files.pythonhosted.org/packages/f8/08/7f92782ff571c7c7cb6c5eeb8ebbb1f68cb02bdb24e55c5de4dd9ce98bc3/pip-22.3.tar.gz",
"size": 2077961,
"sha1": null,
"md5": "996f58a94fe0b8b82b6795c42bd171ba",
"sha256": "65fd48317359f3af8e593943e6ae1506b66325085ea64b706a998c6e83eeaf38",
"md5": "f0dd02265e7ccd2f8758c840fba64810",
"sha256": "8182aec21dad6c0a49a2a3d121a87cd524b950e0b6092b181625f07ebdde7530",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": "https://github.com/pypa/pip",
Expand All @@ -6131,9 +6131,9 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/pip/22.3.1/json",
"api_data_url": "https://pypi.org/pypi/pip/22.3/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected].1"
"purl": "pkg:pypi/[email protected]"
},
{
"type": "pypi",
Expand Down Expand Up @@ -10940,7 +10940,7 @@
{
"key": "pip",
"package_name": "pip",
"installed_version": "22.3.1",
"installed_version": "22.3",
"dependencies": []
}
]
Expand Down
Loading

0 comments on commit eae13cf

Please sign in to comment.