Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop LegacySpecifier and LegacyVersion #407

Merged
merged 7 commits into from
Jul 8, 2022
Merged
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
62 changes: 7 additions & 55 deletions docs/specifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ Reference
can be passed a single specifier (``>=3.0``), a comma-separated list of
specifiers (``>=3.0,!=3.1``), or no specifier at all. Each individual
specifier will be attempted to be parsed as a PEP 440 specifier
(:class:`Specifier`) or as a legacy, setuptools style specifier
(deprecated :class:`LegacySpecifier`). You may combine
:class:`SpecifierSet` instances using the ``&`` operator
(``SpecifierSet(">2") & SpecifierSet("<4")``).
(:class:`Specifier`). You may combine :class:`SpecifierSet` instances using
the ``&`` operator (``SpecifierSet(">2") & SpecifierSet("<4")``).

Both the membership tests and the combination support using raw strings
in place of already instantiated objects.
Expand Down Expand Up @@ -91,8 +89,7 @@ Reference
.. method:: contains(version, prereleases=None)

Determines if ``version``, which can be either a version string, a
:class:`Version`, or a deprecated :class:`LegacyVersion` object, is
contained within this set of specifiers.
:class:`Version` is contained within this set of specifiers.

This will either match or not match prereleases based on the
``prereleases`` parameter. When ``prereleases`` is set to ``None``
Expand All @@ -106,15 +103,14 @@ Reference

.. method:: __iter__()

Returns an iterator over all the underlying :class:`Specifier` (or
deprecated :class:`LegacySpecifier`) instances in this specifier set.
Returns an iterator over all the underlying :class:`Specifier` instances
in this specifier set.

.. method:: filter(iterable, prereleases=None)

Takes an iterable that can contain version strings, :class:`~.Version`,
and deprecated :class:`~.LegacyVersion` instances and will then filter
it, returning an iterable that contains only items which match the
rules of this specifier object.
instances and will then filter them, returning an iterable that contains
only items which match the rules of this specifier object.

This method is smarter than just
``filter(Specifier().contains, [...])`` because it implements the rule
Expand Down Expand Up @@ -169,50 +165,6 @@ Reference
See :meth:`SpecifierSet.filter()`.


.. class:: LegacySpecifier(specifier, prereleases=None)

.. deprecated:: 20.5

Use :class:`Specifier` instead.

This class abstracts the handling of a single legacy, setuptools style
specifier. It is generally not required to instantiate this manually,
preferring instead to work with :class:`SpecifierSet`.

:param str specifier: The string representation of a specifier which will
be parsed and normalized before use.
:param bool prereleases: This tells the specifier if it should accept
prerelease versions if applicable or not. The
default of ``None`` will autodetect it from the
given specifiers.
:raises InvalidSpecifier: If the ``specifier`` is not parseable then this
will be raised.

.. attribute:: operator

The string value of the operator part of this specifier.

.. attribute:: version

The string version of the version part of this specifier.

.. attribute:: prereleases

See :attr:`SpecifierSet.prereleases`.

.. method:: __contains__(version)

See :meth:`SpecifierSet.__contains__()`.

.. method:: contains(version, prereleases=None)

See :meth:`SpecifierSet.contains()`.

.. method:: filter(iterable, prereleases=None)

See :meth:`SpecifierSet.filter()`.


.. exception:: InvalidSpecifier

Raised when attempting to create a :class:`Specifier` with a specifier
Expand Down
138 changes: 2 additions & 136 deletions docs/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Reference
.. function:: parse(version)

This function takes a version string and will parse it as a
:class:`Version` if the version is a valid PEP 440 version, otherwise it
will parse it as a deprecated :class:`LegacyVersion`.
:class:`Version` if the version is a valid PEP 440 version.
Otherwise, raises :class:`InvalidVersion`.


.. class:: Version(version)
Expand Down Expand Up @@ -138,140 +138,6 @@ Reference
represents a post-release.


.. class:: LegacyVersion(version)

.. deprecated:: 20.5

Use :class:`Version` instead.

This class abstracts handling of a project's versions if they are not
compatible with the scheme defined in `PEP 440`_. It implements a similar
interface to that of :class:`Version`.

This class implements the previous de facto sorting algorithm used by
setuptools, however it will always sort as less than a :class:`Version`
instance.

:param str version: The string representation of a version which will be
used as is.

.. note::

:class:`LegacyVersion` instances are always ordered lower than :class:`Version` instances.

>>> from packaging.version import Version, LegacyVersion
>>> v1 = Version("1.0")
>>> v2 = LegacyVersion("1.0")
>>> v1 > v2
True
>>> v3 = LegacyVersion("1.3")
>>> v1 > v3
True

Also note that some strings are still valid PEP 440 strings (:class:`Version`), even if they look very similar to
other versions that are not (:class:`LegacyVersion`). Examples include versions with `Pre-release spelling`_ and
`Post-release spelling`_.

>>> from packaging.version import parse
>>> v1 = parse('0.9.8a')
>>> v2 = parse('0.9.8beta')
>>> v3 = parse('0.9.8r')
>>> v4 = parse('0.9.8rev')
>>> v5 = parse('0.9.8t')
>>> v1
<Version('0.9.8a0')>
>>> v1.is_prerelease
True
>>> v2
<Version('0.9.8b0')>
>>> v2.is_prerelease
True
>>> v3
<Version('0.9.8.post0')>
>>> v3.is_postrelease
True
>>> v4
<Version('0.9.8.post0')>
>>> v4.is_postrelease
True
>>> v5
<LegacyVersion('0.9.8t')>
>>> v5.is_prerelease
False
>>> v5.is_postrelease
False

.. attribute:: public

A string representing the public version portion of this
:class:`LegacyVersion`. This will always be the entire version string.

.. attribute:: base_version

A string representing the base version portion of this
:class:`LegacyVersion` instance. This will always be the entire version
string.

.. attribute:: epoch

This will always be ``-1`` since without `PEP 440`_ we do not have the
concept of version epochs. The value reflects the fact that
:class:`LegacyVersion` instances always compare less than
:class:`Version` instances.

.. attribute:: release

This will always be ``None`` since without `PEP 440`_ we do not have
the concept of a release segment or its components. It exists
primarily to allow a :class:`LegacyVersion` to be used as a stand in
for a :class:`Version`.

.. attribute:: local

This will always be ``None`` since without `PEP 440`_ we do not have
the concept of a local version. It exists primarily to allow a
:class:`LegacyVersion` to be used as a stand in for a :class:`Version`.

.. attribute:: pre

This will always be ``None`` since without `PEP 440`_ we do not have
the concept of a prerelease. It exists primarily to allow a
:class:`LegacyVersion` to be used as a stand in for a :class:`Version`.

.. attribute:: is_prerelease

A boolean value indicating whether this :class:`LegacyVersion`
represents a prerelease and/or development release. Since without
`PEP 440`_ there is no concept of pre or dev releases this will
always be `False` and exists for compatibility with :class:`Version`.

.. attribute:: dev

This will always be ``None`` since without `PEP 440`_ we do not have
the concept of a development release. It exists primarily to allow a
:class:`LegacyVersion` to be used as a stand in for a :class:`Version`.

.. attribute:: is_devrelease

A boolean value indicating whether this :class:`LegacyVersion`
represents a development release. Since without `PEP 440`_ there is
no concept of dev releases this will always be `False` and exists for
compatibility with :class:`Version`.

.. attribute:: post

This will always be ``None`` since without `PEP 440`_ we do not have
the concept of a postrelease. It exists primarily to allow a
:class:`LegacyVersion` to be used as a stand in for a :class:`Version`.

.. attribute:: is_postrelease

A boolean value indicating whether this :class:`LegacyVersion`
represents a post-release. Since without `PEP 440`_ there is no concept
of post-releases this will always be ``False`` and exists for
compatibility with :class:`Version`.


.. exception:: InvalidVersion

Raised when attempting to create a :class:`Version` with a version string
Expand Down
7 changes: 2 additions & 5 deletions packaging/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)

from .markers import MARKER_EXPR as _MARKER_EXPR, Marker
from .specifiers import LegacySpecifier, Specifier, SpecifierSet
from .specifiers import Specifier, SpecifierSet


class InvalidRequirement(ValueError):
Expand Down Expand Up @@ -53,10 +53,7 @@ class InvalidRequirement(ValueError):
EXTRAS_LIST = EXTRA + ZeroOrMore(COMMA + EXTRA)
EXTRAS = (LBRACKET + Optional(EXTRAS_LIST) + RBRACKET)("extras")

VERSION_PEP440 = Regex(Specifier._regex_str, re.VERBOSE | re.IGNORECASE)
VERSION_LEGACY = Regex(LegacySpecifier._regex_str, re.VERBOSE | re.IGNORECASE)

VERSION_ONE = VERSION_PEP440 ^ VERSION_LEGACY
VERSION_ONE = Regex(Specifier._regex_str, re.VERBOSE | re.IGNORECASE)
VERSION_MANY = Combine(
VERSION_ONE + ZeroOrMore(COMMA + VERSION_ONE), joinString=",", adjacent=False
)("_raw_spec")
Expand Down
Loading