Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/git-filter-repo-pip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion etc/scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pip
setuptools
twine
wheel
build
build
packvers
2 changes: 1 addition & 1 deletion etc/scripts/utils_dejacode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 8 additions & 18 deletions etc/scripts/utils_pip_compatibility_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import re

from packaging.tags import (
from packvers.tags import (
compatible_tags,
cpython_tags,
generic_tags,
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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":
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -119,15 +113,13 @@ 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:
return (int(version[0]),)


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:
Expand All @@ -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`.

Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions etc/scripts/utils_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
packaging
packaging
packvers
pytest
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +44,7 @@ python_requires = >=3.6.0

install_requires =
packaging
packvers
pyparsing


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
#

Expand Down Expand Up @@ -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("*"):
Expand Down
48 changes: 24 additions & 24 deletions src/pip_requirements_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]<specifiers,>;marker
- a standard ``packvers`` requirement as name[extras]<specifiers,>;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

Expand Down Expand Up @@ -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)

Expand All @@ -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
################################################################################


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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=<name>" fragment
Expand All @@ -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=<name> the <name> can be a packaging
As a recap for VCS URL in #egg=<name> the <name> can be a packvers
Requirement-compatible string, but only name is kept and used.
Trailing marker is an error
"""
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
#

Expand All @@ -16,7 +16,7 @@

import pytest

from packaging_legacy_version import parse, LegacyVersion
from packvers.version import parse, LegacyVersion


@pytest.mark.parametrize(
Expand Down Expand Up @@ -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")
Expand Down