Merge pull request #9533 from henryiii/chore/packaging-20.9

Update to packaging 20.9
This commit is contained in:
Paul Moore 2021-01-30 09:41:50 +00:00 committed by GitHub
commit 00fb5a0b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 123 additions and 20 deletions

View File

@ -0,0 +1 @@
Upgrade packaging to 20.9

View File

@ -18,7 +18,7 @@ __title__ = "packaging"
__summary__ = "Core utilities for Python packages"
__uri__ = "https://github.com/pypa/packaging"
__version__ = "20.8"
__version__ = "20.9"
__author__ = "Donald Stufft and individual contributors"
__email__ = "donald@stufft.io"

View File

@ -8,13 +8,21 @@ import os
import platform
import sys
from pip._vendor.pyparsing import ParseException, ParseResults, stringStart, stringEnd
from pip._vendor.pyparsing import ZeroOrMore, Group, Forward, QuotedString
from pip._vendor.pyparsing import Literal as L # noqa
from pip._vendor.pyparsing import ( # noqa: N817
Forward,
Group,
Literal as L,
ParseException,
ParseResults,
QuotedString,
ZeroOrMore,
stringEnd,
stringStart,
)
from ._compat import string_types
from ._typing import TYPE_CHECKING
from .specifiers import Specifier, InvalidSpecifier
from .specifiers import InvalidSpecifier, Specifier
if TYPE_CHECKING: # pragma: no cover
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

View File

@ -3,13 +3,22 @@
# for complete details.
from __future__ import absolute_import, division, print_function
import string
import re
import string
import sys
from pip._vendor.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
from pip._vendor.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine
from pip._vendor.pyparsing import Literal as L # noqa
from pip._vendor.pyparsing import ( # noqa: N817
Combine,
Literal as L,
Optional,
ParseException,
Regex,
Word,
ZeroOrMore,
originalTextFor,
stringEnd,
stringStart,
)
from ._typing import TYPE_CHECKING
from .markers import MARKER_EXPR, Marker

View File

@ -12,10 +12,10 @@ import warnings
from ._compat import string_types, with_metaclass
from ._typing import TYPE_CHECKING
from .utils import canonicalize_version
from .version import Version, LegacyVersion, parse
from .version import LegacyVersion, Version, parse
if TYPE_CHECKING: # pragma: no cover
from typing import List, Dict, Union, Iterable, Iterator, Optional, Callable, Tuple
from typing import Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
ParsedVersion = Union[Version, LegacyVersion]
UnparsedVersion = Union[Version, LegacyVersion, str]

View File

@ -27,9 +27,9 @@ from ._typing import TYPE_CHECKING, cast
if TYPE_CHECKING: # pragma: no cover
from typing import (
IO,
Dict,
FrozenSet,
IO,
Iterable,
Iterator,
List,
@ -458,14 +458,28 @@ def mac_platforms(version=None, arch=None):
major=major_version, minor=0, binary_format=binary_format
)
if version >= (11, 0) and arch == "x86_64":
if version >= (11, 0):
# Mac OS 11 on x86_64 is compatible with binaries from previous releases.
# Arm64 support was introduced in 11.0, so no Arm binaries from previous
# releases exist.
for minor_version in range(16, 3, -1):
compat_version = 10, minor_version
binary_formats = _mac_binary_formats(compat_version, arch)
for binary_format in binary_formats:
#
# However, the "universal2" binary format can have a
# macOS version earlier than 11.0 when the x86_64 part of the binary supports
# that version of macOS.
if arch == "x86_64":
for minor_version in range(16, 3, -1):
compat_version = 10, minor_version
binary_formats = _mac_binary_formats(compat_version, arch)
for binary_format in binary_formats:
yield "macosx_{major}_{minor}_{binary_format}".format(
major=compat_version[0],
minor=compat_version[1],
binary_format=binary_format,
)
else:
for minor_version in range(16, 3, -1):
compat_version = 10, minor_version
binary_format = "universal2"
yield "macosx_{major}_{minor}_{binary_format}".format(
major=compat_version[0],
minor=compat_version[1],

View File

@ -6,23 +6,41 @@ from __future__ import absolute_import, division, print_function
import re
from ._typing import TYPE_CHECKING, cast
from .tags import Tag, parse_tag
from .version import InvalidVersion, Version
if TYPE_CHECKING: # pragma: no cover
from typing import NewType, Union
from typing import FrozenSet, NewType, Tuple, Union
BuildTag = Union[Tuple[()], Tuple[int, str]]
NormalizedName = NewType("NormalizedName", str)
else:
BuildTag = tuple
NormalizedName = str
class InvalidWheelFilename(ValueError):
"""
An invalid wheel filename was found, users should refer to PEP 427.
"""
class InvalidSdistFilename(ValueError):
"""
An invalid sdist filename was found, users should refer to the packaging user guide.
"""
_canonicalize_regex = re.compile(r"[-_.]+")
# PEP 427: The build number must start with a digit.
_build_tag_regex = re.compile(r"(\d+)(.*)")
def canonicalize_name(name):
# type: (str) -> NormalizedName
# This is taken from PEP 503.
value = _canonicalize_regex.sub("-", name).lower()
return cast("NormalizedName", value)
return cast(NormalizedName, value)
def canonicalize_version(version):
@ -65,3 +83,56 @@ def canonicalize_version(version):
parts.append("+{0}".format(version.local))
return "".join(parts)
def parse_wheel_filename(filename):
# type: (str) -> Tuple[NormalizedName, Version, BuildTag, FrozenSet[Tag]]
if not filename.endswith(".whl"):
raise InvalidWheelFilename(
"Invalid wheel filename (extension must be '.whl'): {0}".format(filename)
)
filename = filename[:-4]
dashes = filename.count("-")
if dashes not in (4, 5):
raise InvalidWheelFilename(
"Invalid wheel filename (wrong number of parts): {0}".format(filename)
)
parts = filename.split("-", dashes - 2)
name_part = parts[0]
# See PEP 427 for the rules on escaping the project name
if "__" in name_part or re.match(r"^[\w\d._]*$", name_part, re.UNICODE) is None:
raise InvalidWheelFilename("Invalid project name: {0}".format(filename))
name = canonicalize_name(name_part)
version = Version(parts[1])
if dashes == 5:
build_part = parts[2]
build_match = _build_tag_regex.match(build_part)
if build_match is None:
raise InvalidWheelFilename(
"Invalid build number: {0} in '{1}'".format(build_part, filename)
)
build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
else:
build = ()
tags = parse_tag(parts[-1])
return (name, version, build, tags)
def parse_sdist_filename(filename):
# type: (str) -> Tuple[NormalizedName, Version]
if not filename.endswith(".tar.gz"):
raise InvalidSdistFilename(
"Invalid sdist filename (extension must be '.tar.gz'): {0}".format(filename)
)
# We are requiring a PEP 440 version, which cannot contain dashes,
# so we split on the last dash.
name_part, sep, version_part = filename[:-7].rpartition("-")
if not sep:
raise InvalidSdistFilename("Invalid sdist filename: {0}".format(filename))
name = canonicalize_name(name_part)
version = Version(version_part)
return (name, version)

View File

@ -6,7 +6,7 @@ distlib==0.3.1
distro==1.5.0
html5lib==1.1
msgpack==1.0.2
packaging==20.8
packaging==20.9
pep517==0.9.1
progress==1.5
pyparsing==2.4.7