Skip to content

Commit

Permalink
Merge branch 'main' into prefix-match-normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon committed Aug 19, 2022
2 parents d7db7a9 + cb2b89f commit 3979529
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Expand Up @@ -31,7 +31,7 @@ jobs:
cache: "pip"

- name: Run `nox -s lint`
run: pipx run nox --error-on-missing-interpreters -s lint
run: pipx run nox --error-on-missing-interpreters -s lint -- --show-diff-on-failure

build:
name: Build sdist and wheel
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,8 @@ Changelog
Evaluating markers like ``"extra == 'xyz'"`` without passing any extra in the
``environment`` will no longer raise an exception.
* Remove dependency on ``pyparsing``, by replacing it with a hand-written parser. This package now has no runtime dependencies (:issue:`468`)
* Update return type hint for ``Specifier.filter`` and ``SpecifierSet.filter``
to use ``Iterator`` instead of ``Iterable``

21.3 - 2021-11-17
~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 15 additions & 0 deletions docs/utils.rst
Expand Up @@ -63,6 +63,8 @@ Reference
instance of :class:`~packaging.tags.Tag`.

:param str filename: The name of the wheel file.
:raises InvalidWheelFilename: If the filename in question
does not follow conventions outlined in `PEP 427`_.

.. doctest::

Expand All @@ -87,6 +89,9 @@ Reference
represented by an instance of :class:`~packaging.version.Version`.

:param str filename: The name of the sdist file.
:raises InvalidSdistFilename: If the filename does not end
with an sdist extension (``.zip`` or ``.tar.gz``), or if it does not
contain a dash separating the name and the version of the distribution.

.. doctest::

Expand All @@ -98,4 +103,14 @@ Reference
>>> ver == Version('1.0')
True


.. exception:: InvalidWheelFilename

Raised when a file name for a wheel is invalid.

.. exception:: InvalidSdistFilename

Raised when a source distribution file name is considered invalid.

.. _Source distribution format: https://packaging.python.org/specifications/source-distribution-format/#source-distribution-file-name
.. _`PEP 427`: https://peps.python.org/pep-0427/#file-name-convention
2 changes: 1 addition & 1 deletion noxfile.py
Expand Up @@ -57,7 +57,7 @@ def coverage(*args):
def lint(session):
# Run the linters (via pre-commit)
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files")
session.run("pre-commit", "run", "--all-files", *session.posargs)

# Check the distribution
session.install("build", "twine")
Expand Down
16 changes: 8 additions & 8 deletions packaging/specifiers.py
Expand Up @@ -86,7 +86,7 @@ def contains(self, item: str, prereleases: Optional[bool] = None) -> bool:
@abc.abstractmethod
def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterable[UnparsedVersion]:
) -> Iterator[UnparsedVersion]:
"""
Takes an iterable of items and filters them so that only items which
are contained within this specifier are allowed in it.
Expand Down Expand Up @@ -567,14 +567,14 @@ def contains(

def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterable[UnparsedVersion]:
) -> Iterator[UnparsedVersion]:
"""Filter items in the given iterable, that match the specifier.
:param iterable:
An iterable that can contain version strings and :class:`Version` instances.
The items in the iterable will be filtered according to the specifier.
:param prereleases:
Whether or not to allow prereleases in the returned iterable. If set to
Whether or not to allow prereleases in the returned iterator. If set to
``None`` (the default), it will be intelligently decide whether to allow
prereleases or not (based on the :attr:`prereleases` attribute, and
whether the only versions matching are prereleases).
Expand Down Expand Up @@ -917,14 +917,14 @@ def contains(

def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterable[UnparsedVersion]:
) -> Iterator[UnparsedVersion]:
"""Filter items in the given iterable, that match the specifiers in this set.
:param iterable:
An iterable that can contain version strings and :class:`Version` instances.
The items in the iterable will be filtered according to the specifier.
:param prereleases:
Whether or not to allow prereleases in the returned iterable. If set to
Whether or not to allow prereleases in the returned iterator. If set to
``None`` (the default), it will be intelligently decide whether to allow
prereleases or not (based on the :attr:`prereleases` attribute, and
whether the only versions matching are prereleases).
Expand Down Expand Up @@ -968,7 +968,7 @@ def filter(
if self._specs:
for spec in self._specs:
iterable = spec.filter(iterable, prereleases=bool(prereleases))
return iterable
return iter(iterable)
# If we do not have any specifiers, then we need to have a rough filter
# which will filter out any pre-releases, unless there are no final
# releases.
Expand All @@ -990,6 +990,6 @@ def filter(
# If we've found no items except for pre-releases, then we'll go
# ahead and use the pre-releases
if not filtered and found_prereleases and prereleases is None:
return found_prereleases
return iter(found_prereleases)

return filtered
return iter(filtered)
7 changes: 5 additions & 2 deletions packaging/tags.py
Expand Up @@ -499,6 +499,9 @@ def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
yield from generic_tags()

if interp_name == "pp":
yield from compatible_tags(interpreter="pp3")
interp = "pp3"
elif interp_name == "cp":
interp = "cp" + interpreter_version(warn=warn)
else:
yield from compatible_tags()
interp = None
yield from compatible_tags(interpreter=interp)
13 changes: 13 additions & 0 deletions tests/test_tags.py
Expand Up @@ -1226,3 +1226,16 @@ def test_pypy_first_none_any_tag(self, monkeypatch):
break

assert tag == tags.Tag("pp3", "none", "any")

def test_cpython_first_none_any_tag(self, monkeypatch):
# When building the complete list of cpython tags, make sure the first
# <interpreter>-none-any one is cpxx-none-any
monkeypatch.setattr(tags, "interpreter_name", lambda: "cp")

# Find the first tag that is ABI- and platform-agnostic.
for tag in tags.sys_tags():
if tag.abi == "none" and tag.platform == "any":
break

interpreter = f"cp{tags.interpreter_version()}"
assert tag == tags.Tag(interpreter, "none", "any")

0 comments on commit 3979529

Please sign in to comment.