diff --git a/etc/git-filter-repo-pip.sh b/etc/git-filter-repo-pip.sh index 3e0d0056..272a2ef7 100644 --- a/etc/git-filter-repo-pip.sh +++ b/etc/git-filter-repo-pip.sh @@ -37,7 +37,7 @@ gfr --path README.rst \ --path src/pip/_internal/utils/urls.py \ --path src/pip/_internal/utils/hashes.py \ --path src/pip/_internal/utils/models.py \ ---path src/pip/_internal/utils/packaging.py \ +--path src/pip/_internal/utils/packvers.py \ --path src/pip/_internal/models/link.py \ --path src/pip/_vendor/pkg_resource/__init__.py \ --path src/pip/_vendor/pkg_resource/__init__.py \ diff --git a/etc/scripts/requirements.txt b/etc/scripts/requirements.txt index ebb404b7..7c514da9 100644 --- a/etc/scripts/requirements.txt +++ b/etc/scripts/requirements.txt @@ -8,4 +8,5 @@ pip setuptools twine wheel -build \ No newline at end of file +build +packvers diff --git a/etc/scripts/utils_dejacode.py b/etc/scripts/utils_dejacode.py index f28e2479..c42e6c93 100644 --- a/etc/scripts/utils_dejacode.py +++ b/etc/scripts/utils_dejacode.py @@ -15,7 +15,7 @@ import requests import saneyaml -from packaging import version as packaging_version +from packvers import version as packaging_version """ Utility to create and retrieve package and ABOUT file data from DejaCode. diff --git a/etc/scripts/utils_pip_compatibility_tags.py b/etc/scripts/utils_pip_compatibility_tags.py index 5d5eb34c..3fc77416 100644 --- a/etc/scripts/utils_pip_compatibility_tags.py +++ b/etc/scripts/utils_pip_compatibility_tags.py @@ -27,7 +27,7 @@ import re -from packaging.tags import ( +from packvers.tags import ( compatible_tags, cpython_tags, generic_tags, @@ -40,13 +40,10 @@ def version_info_to_nodot(version_info): - # type: (Tuple[int, ...]) -> str - # Only use up to the first two numbers. return "".join(map(str, version_info[:2])) def _mac_platforms(arch): - # type: (str) -> List[str] match = _osx_arch_pat.match(arch) if match: name, major, minor, actual_arch = match.groups() @@ -57,7 +54,7 @@ def _mac_platforms(arch): # actual prefix provided by the user in case they provided # something like "macosxcustom_". It may be good to remove # this as undocumented or deprecate it in the future. - "{}_{}".format(name, arch[len("macosx_") :]) + "{}_{}".format(name, arch[len("macosx_"):]) for arch in mac_platforms(mac_version, actual_arch) ] else: @@ -67,7 +64,6 @@ def _mac_platforms(arch): def _custom_manylinux_platforms(arch): - # type: (str) -> List[str] arches = [arch] arch_prefix, arch_sep, arch_suffix = arch.partition("_") if arch_prefix == "manylinux2014": @@ -89,7 +85,6 @@ def _custom_manylinux_platforms(arch): def _get_custom_platforms(arch): - # type: (str) -> List[str] arch_prefix, _arch_sep, _arch_suffix = arch.partition("_") if arch.startswith("macosx"): arches = _mac_platforms(arch) @@ -101,7 +96,6 @@ def _get_custom_platforms(arch): def _expand_allowed_platforms(platforms): - # type: (Optional[List[str]]) -> Optional[List[str]] if not platforms: return None @@ -119,7 +113,6 @@ def _expand_allowed_platforms(platforms): def _get_python_version(version): - # type: (str) -> PythonVersion if len(version) > 1: return int(version[0]), int(version[1:]) else: @@ -127,7 +120,6 @@ def _get_python_version(version): def _get_custom_interpreter(implementation=None, version=None): - # type: (Optional[str], Optional[str]) -> str if implementation is None: implementation = interpreter_name() if version is None: @@ -136,12 +128,11 @@ def _get_custom_interpreter(implementation=None, version=None): def get_supported( - version=None, # type: Optional[str] - platforms=None, # type: Optional[List[str]] - impl=None, # type: Optional[str] - abis=None, # type: Optional[List[str]] + version=None, + platforms=None, + impl=None, + abis=None, ): - # type: (...) -> List[Tag] """Return a list of supported tags for each version specified in `versions`. @@ -154,9 +145,8 @@ def get_supported( :param abis: specify a list of abis you want valid tags for, or None. If None, use the local interpreter abi. """ - supported = [] # type: List[Tag] - - python_version = None # type: Optional[PythonVersion] + supported = [] + python_version = None if version is not None: python_version = _get_python_version(version) diff --git a/etc/scripts/utils_thirdparty.py b/etc/scripts/utils_thirdparty.py index 53f2d33c..121af386 100644 --- a/etc/scripts/utils_thirdparty.py +++ b/etc/scripts/utils_thirdparty.py @@ -28,8 +28,8 @@ from commoncode import fileutils from commoncode.hash import multi_checksums from commoncode.text import python_safe_name -from packaging import tags as packaging_tags -from packaging import version as packaging_version +from packvers import tags as packaging_tags +from packvers import version as packaging_version import utils_pip_compatibility_tags diff --git a/requirements.txt b/requirements.txt index 75aa6c06..50ab07f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -packaging \ No newline at end of file +packaging +packvers +pytest diff --git a/setup.cfg b/setup.cfg index 0a6d0596..107072cd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ packages = find: include_package_data = true py_modules = pip_requirements_parser - packaging_legacy_version + packvers_legacy_version zip_safe = false setup_requires = setuptools_scm[toml] >= 4 @@ -44,6 +44,7 @@ python_requires = >=3.6.0 install_requires = packaging + packvers pyparsing diff --git a/src/packaging_legacy_version.py b/src/packvers_legacy_version.py similarity index 96% rename from src/packaging_legacy_version.py rename to src/packvers_legacy_version.py index e511322c..89f028ee 100644 --- a/src/packaging_legacy_version.py +++ b/src/packvers_legacy_version.py @@ -1,12 +1,12 @@ # -# This is a heavily streamlined subset of the packaging.version@21.3 to extract +# This is a heavily streamlined subset of the packvers.version@21.3 to extract # LegacyVersion that was dropped in version 22. # # SPDX-license-identifier: BSD-2-Clause or Apache-2.0 # copyright (c) Donald Stufft and individual contributors # # This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the packaging_legacy_version.LICENSE file in +# 2.0, and the BSD License. See the packvers_legacy_version.LICENSE file in # this repository for complete details. # @@ -180,7 +180,7 @@ def _legacy_cmpkey(version: str) -> LegacyCmpKey: epoch = -1 # This scheme is taken from pkg_resources.parse_version setuptools prior to - # it's adoption of the packaging library. + # it's adoption of the packvers library. parts: List[str] = [] for part in _parse_version_parts(version.lower()): if part.startswith("*"): diff --git a/src/packaging_legacy_version.py.ABOUT b/src/packvers_legacy_version.py.ABOUT similarity index 100% rename from src/packaging_legacy_version.py.ABOUT rename to src/packvers_legacy_version.py.ABOUT diff --git a/src/packaging_legacy_version.py.LICENSE b/src/packvers_legacy_version.py.LICENSE similarity index 100% rename from src/packaging_legacy_version.py.LICENSE rename to src/packvers_legacy_version.py.LICENSE diff --git a/src/packaging_legacy_version.py.LICENSE.APACHE b/src/packvers_legacy_version.py.LICENSE.APACHE similarity index 100% rename from src/packaging_legacy_version.py.LICENSE.APACHE rename to src/packvers_legacy_version.py.LICENSE.APACHE diff --git a/src/packaging_legacy_version.py.LICENSE.BSD b/src/packvers_legacy_version.py.LICENSE.BSD similarity index 100% rename from src/packaging_legacy_version.py.LICENSE.BSD rename to src/packvers_legacy_version.py.LICENSE.BSD diff --git a/src/pip_requirements_parser.py b/src/pip_requirements_parser.py index 77f43a48..67ff441c 100644 --- a/src/pip_requirements_parser.py +++ b/src/pip_requirements_parser.py @@ -65,16 +65,16 @@ cast, ) -from packaging.markers import Marker -from packaging.requirements import InvalidRequirement -from packaging.requirements import Requirement -from packaging.specifiers import Specifier -from packaging.specifiers import SpecifierSet -from packaging.tags import Tag -from packaging.version import parse -from packaging.version import Version - -from packaging_legacy_version import LegacyVersion +from packvers.markers import Marker +from packvers.requirements import InvalidRequirement +from packvers.requirements import Requirement +from packvers.specifiers import Specifier +from packvers.specifiers import SpecifierSet +from packvers.tags import Tag +from packvers.version import parse +from packvers.version import Version + +from packvers.version import LegacyVersion """ A pip requirements files parser, doing it as well as pip does it because it is based on pip's own code. @@ -133,23 +133,23 @@ # The pip requirement styles """ A pip requirement line comes in many styles. Some are supported by the -``packaging`` library some are not. +``packvers`` library some are not. -Standard ``packaging``-supported requirement lines +Standard ``packvers``-supported requirement lines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- a standard ``packaging`` requirement as name[extras];marker +- a standard ``packvers`` requirement as name[extras];marker For example: "django[extras]==3.2;marker" - non-standard pip additions: same with pip per-requirement options such as --hash -- a standard ``packaging`` pep 508 URL as in name[extras]@url - This is a standard packaging requirement. +- a standard ``packvers`` pep 508 URL as in name[extras]@url + This is a standard packvers requirement. For example: boolean.py[bar]@https://github.com/bastikr/boolean.py.git - - non-standard pip additions: support for VCS URLs. packaging can parse + - non-standard pip additions: support for VCS URLs. packvers can parse these though pip's code is needed to interpret them. For example: boolean.py[bar]@git+https://github.com/bastikr/boolean.py.git @@ -1698,7 +1698,7 @@ def _compare(self, other: Any, method: Callable[[Any, Any], bool]) -> bool: ################################################################################ -# PIPREQPARSE: from src/pip/_internal/utils/packaging.py +# PIPREQPARSE: from src/pip/_internal/utils/packvers.py NormalizedExtra = NewType("NormalizedExtra", str) @@ -1714,7 +1714,7 @@ def safe_extra(extra: str) -> NormalizedExtra: """ return cast(NormalizedExtra, re.sub("[^A-Za-z0-9.-]+", "_", extra).lower()) -# PIPREQPARSE: end from src/pip/_internal/utils/packaging.py +# PIPREQPARSE: end from src/pip/_internal/utils/packvers.py ################################################################################ @@ -1953,10 +1953,10 @@ def __init__( """ Initialize a new pip requirement - - ``req`` is a packaging Requirement object that may be None + - ``req`` is a packvers Requirement object that may be None - ``requirement_line`` is the original line this requirement was found - ``link`` is a Link object provided when the requirement is a path or URL - - ``marker`` is a packaging Marker object. + - ``marker`` is a packvers Marker object. This is provided when a marker is used and there is no ``req`` Requirement. - ``install_options``, ``global_options`` and ``hash_options`` are the CLI-style pip options for this specifc requirement. @@ -2255,7 +2255,7 @@ def dumps(self, with_name=True) -> str: def _as_version(version: Union[str, LegacyVersion, Version] ) -> Union[LegacyVersion, Version]: """ - Return a packaging Version-like object suitable for sorting + Return a packvers Version-like object suitable for sorting """ if isinstance(version, (LegacyVersion, Version)): return version @@ -2279,7 +2279,7 @@ class EditableRequirement(InstallRequirement): """ Represents a pip editable requirement. These are special because they are unique to pip (e.g., they cannot be - specified only as packaging.requriements.Requirement. + specified only as packvers.requriements.Requirement. They track: - a path/ or a path/subpath to a dir with an optional [extra]. - a VCS URL with a package name i.e., the "#egg=" fragment @@ -2290,7 +2290,7 @@ class EditableRequirement(InstallRequirement): is the same as: -e git+https://github.com/bastikr/boolean.py.git#egg=boolean.py - As a recap for VCS URL in #egg= the can be a packaging + As a recap for VCS URL in #egg= the can be a packvers Requirement-compatible string, but only name is kept and used. Trailing marker is an error """ @@ -2764,7 +2764,7 @@ def parse_reqparts_from_string(requirement_string: str) -> RequirementParts: # will become an 'unnamed' requirement req_as_string = link.egg_fragment - # a requirement specifier that should be packaging-parsable. + # a requirement specifier that should be packvers-parsable. # this includes name@url else: req_as_string = requirement_string_no_marker diff --git a/tests/test_packaging_legacy_version.py b/tests/test_packvers_legacy_version.py similarity index 95% rename from tests/test_packaging_legacy_version.py rename to tests/test_packvers_legacy_version.py index 86809dc0..cede2c3c 100644 --- a/tests/test_packaging_legacy_version.py +++ b/tests/test_packvers_legacy_version.py @@ -1,12 +1,12 @@ # -# This is a heavily streamlined subset of the packaging.version@21.3 to extract +# This is a heavily streamlined subset of the packvers.version@21.3 to extract # LegacyVersion that was dropped in version 22. # # SPDX-license-identifier: BSD-2-Clause or Apache-2.0 # copyright (c) Donald Stufft and individual contributors # # This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the packaging_legacy_version.LICENSE file in +# 2.0, and the BSD License. See the packvers_legacy_version.LICENSE file in # this repository for complete details. # @@ -16,7 +16,7 @@ import pytest -from packaging_legacy_version import parse, LegacyVersion +from packvers.version import parse, LegacyVersion @pytest.mark.parametrize( @@ -93,7 +93,7 @@ def test_parse(version, klass): class TestLegacyVersion: - @pytest.mark.xfail(reason="We vendored packaging to reinstate LegacyVersion") + @pytest.mark.xfail(reason="We vendored packvers to reinstate LegacyVersion") def test_legacy_version_is_deprecated(self): with warnings.catch_warnings(record=True) as w: LegacyVersion("some-legacy-version") diff --git a/tests/test_packaging_legacy_version.py.ABOUT b/tests/test_packvers_legacy_version.py.ABOUT similarity index 100% rename from tests/test_packaging_legacy_version.py.ABOUT rename to tests/test_packvers_legacy_version.py.ABOUT diff --git a/tests/test_packaging_legacy_version.py.LICENSE b/tests/test_packvers_legacy_version.py.LICENSE similarity index 100% rename from tests/test_packaging_legacy_version.py.LICENSE rename to tests/test_packvers_legacy_version.py.LICENSE diff --git a/tests/test_packaging_legacy_version.py.LICENSE.APACHE b/tests/test_packvers_legacy_version.py.LICENSE.APACHE similarity index 100% rename from tests/test_packaging_legacy_version.py.LICENSE.APACHE rename to tests/test_packvers_legacy_version.py.LICENSE.APACHE diff --git a/tests/test_packaging_legacy_version.py.LICENSE.BSD b/tests/test_packvers_legacy_version.py.LICENSE.BSD similarity index 100% rename from tests/test_packaging_legacy_version.py.LICENSE.BSD rename to tests/test_packvers_legacy_version.py.LICENSE.BSD