diff options
| author | robot-piglet <[email protected]> | 2025-12-12 13:17:11 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-12-12 13:35:29 +0300 |
| commit | 3dbb803cfc6bfe14cb471126110c4f558130e309 (patch) | |
| tree | 603e35852665909c8ab6450429e4ac77c5b37461 /contrib/python/incremental/py3 | |
| parent | a89cff504d647d0988b75396aba8d67211e0ce66 (diff) | |
Intermediate changes
commit_hash:38e862c546aa268aac841565d1cc3f70df797d15
Diffstat (limited to 'contrib/python/incremental/py3')
| -rw-r--r-- | contrib/python/incremental/py3/.dist-info/METADATA | 99 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/.dist-info/entry_points.txt | 3 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/README.rst | 73 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/incremental/__init__.py | 152 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/incremental/_hatch.py | 10 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/incremental/_version.py | 4 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/incremental/update.py | 163 | ||||
| -rw-r--r-- | contrib/python/incremental/py3/ya.make | 4 |
8 files changed, 289 insertions, 219 deletions
diff --git a/contrib/python/incremental/py3/.dist-info/METADATA b/contrib/python/incremental/py3/.dist-info/METADATA index 77552dbb833..b3dbe3e6f09 100644 --- a/contrib/python/incremental/py3/.dist-info/METADATA +++ b/contrib/python/incremental/py3/.dist-info/METADATA @@ -1,43 +1,56 @@ -Metadata-Version: 2.1 -Name: incremental -Version: 24.7.2 -Summary: A small library that versions your Python projects. -Maintainer-email: Amber Brown <[email protected]> +Metadata-Version: 2.4 +Name: Incremental +Version: 24.11.0 +Summary: A CalVer version manager that supports the future. Project-URL: Homepage, https://github.com/twisted/incremental Project-URL: Documentation, https://twisted.org/incremental/docs/ Project-URL: Issues, https://github.com/twisted/incremental/issues Project-URL: Changelog, https://github.com/twisted/incremental/blob/trunk/NEWS.rst -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: MIT License +Maintainer-email: Amber Brown <[email protected]>, Tom Most <[email protected]> +License-File: LICENSE Classifier: Framework :: Hatch Classifier: Framework :: Setuptools Plugin +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 +Classifier: Programming Language :: Python :: 3.13 +Classifier: Programming Language :: Python :: 3.14 Requires-Python: >=3.8 -Description-Content-Type: text/x-rst -License-File: LICENSE -Requires-Dist: setuptools >=61.0 -Requires-Dist: tomli ; python_version < "3.11" +Requires-Dist: packaging>=17.0 +Requires-Dist: tomli; python_version < '3.11' Provides-Extra: scripts -Requires-Dist: click >=6.0 ; extra == 'scripts' +Description-Content-Type: text/x-rst Incremental =========== -|gha| |pypi| +|calver| +|gha| |coverage| -Incremental is a small library that versions your Python projects. +Incremental is a `CalVer <https://calver.org/>`_ version manager supports the future. API documentation can be found `here <https://twisted.org/incremental/docs/>`_. +Narrative documentation follows. .. contents:: +Theory of Operation +------------------- + +- A version number has the form YY.MM.PATCH. +- If your project is named "Shrubbery", its code is found in ``shrubbery/`` or ``src/shrubbery/``. +- Incremental stores your project's version number in ``{src/}shrubbery/_version.py``. +- To update the version, run ``incremental update Shrubbery``, passing ``--rc`` and/or ``--patch`` as appropriate (see `Updating`_, below). +- Changing the version also updates any `indeterminate versions`_ in your codebase, like "Shrubbery NEXT", so you can reference the upcoming release in documentation. + That's how Incremental supports the future. + + Quick Start ----------- @@ -57,13 +70,13 @@ Add Incremental to your ``pyproject.toml``: [project] name = "<projectname>" - dynamic = ["version"] # ← Mark the version dynamic + dynamic = ["version"] # ← Mark the version dynamic dependencies = [ "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... - [tool.incremental] # ← Activate Incremental's setuptools plugin + [tool.incremental] # ← Activate Incremental's setuptools plugin It's fine if the ``[tool.incremental]`` table is empty, but it must be present. @@ -88,19 +101,19 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: [project] name = "<projectname>" - dynamic = ["version"] # ← Mark the version dynamic + dynamic = ["version"] # ← Mark the version dynamic dependencies = [ "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... [tool.hatch.version] - source = "incremental" # ← Activate Incremental's Hatchling plugin + source = "incremental" # ← Activate Incremental's Hatchling plugin Incremental can be configured as usual in an optional ``[tool.incremental]`` table. The ``hatch version`` command will report the Incremental-managed version. -Use the ``python -m incremental.update`` command to change the version (setting it with ``hatch version`` is not supported). +Use the ``incremental update`` command to change the version (setting it with ``hatch version`` is not supported). Next, `initialize the project`_. @@ -126,8 +139,8 @@ Then `initialize the project`_. Initialize the project ~~~~~~~~~~~~~~~~~~~~~~ -Install Incremental to your local environment with ``pip install incremental[scripts]``. -Then run ``python -m incremental.update <projectname> --create``. +Install Incremental to your local environment with ``pipx install incremental``. +Then run ``incremental update <projectname> --create``. It will create a file in your package named ``_version.py`` like this: .. code:: python @@ -138,15 +151,26 @@ It will create a file in your package named ``_version.py`` like this: __all__ = ["__version__"] -Then, so users of your project can find your version, in your root package's ``__init__.py`` add: +Subsequent installations of your project will then use Incremental for versioning. + + +Runtime integration +~~~~~~~~~~~~~~~~~~~ + +You may expose the ``incremental.Version`` from ``_version.py`` in your package's API. +To do so, add to your root package's ``__init__.py``: .. code:: python from ._version import __version__ +.. note:: -Subsequent installations of your project will then use Incremental for versioning. + Providing a ``__version__`` attribute is falling out of fashion following the introduction of `importlib.metadata.version() <https://docs.python.org/3/library/importlib.metadata.html#distribution-versions>`_ in Python 3.6, which can retrieve an installed package's version. +If you don't expose this object publicly, nor make use of it within your package, +then there is no need to depend on Incremental at runtime. +You can remove it from your project's ``dependencies`` array (or, in ``setup.py``, from ``install_requires``). Incremental Versions @@ -169,12 +193,12 @@ Calling ``repr()`` with a ``Version`` will give a Python-source-code representat Updating -------- -Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental.update``. +Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental``. It updates the ``_version.py`` file and automatically updates some uses of Incremental versions from an indeterminate version to the current one. It requires ``click`` from PyPI. -``python -m incremental.update <projectname>`` will perform updates on that package. -The commands that can be given after that will determine what the next version is. +``incremental update <projectname>`` will perform updates on that package. +The commands that can be given after that determine what the next version is. - ``--newversion=<version>``, to set the project version to a fully-specified version (like 1.2.3, or 17.1.0dev1). - ``--rc``, to set the project version to ``<year-2000>.<month>.0rc1`` if the current version is not a release candidate, or bump the release candidate number by 1 if it is. @@ -184,12 +208,15 @@ The commands that can be given after that will determine what the next version i If you give no arguments, it will strip the release candidate number, making it a "full release". +Indeterminate Versions +---------------------- + Incremental supports "indeterminate" versions, as a stand-in for the next "full" version. This can be used when the version which will be displayed to the end-user is unknown (for example "introduced in" or "deprecated in"). Incremental supports the following indeterminate versions: - ``Version("<projectname>", "NEXT", 0, 0)`` - ``<projectname> NEXT`` -When you run ``python -m incremental.update <projectname> --rc``, these will be updated to real versions (assuming the target final version is 17.1.0): +When you run ``incremental update <projectname> --rc``, these will be updated to real versions (assuming the target final version is 17.1.0): - ``Version("<projectname>", 17, 1, 0, release_candidate=1)`` - ``<projectname> 17.1.0rc1`` @@ -200,11 +227,17 @@ Once the final version is made, it will become: - ``<projectname> 17.1.0`` -.. |coverage| image:: https://codecov.io/gh/twisted/incremental/branch/master/graph/badge.svg?token=K2ieeL887X -.. _coverage: https://codecov.io/gh/twisted/incremental +.. |pypi| image:: http://img.shields.io/pypi/v/incremental.svg + :alt: PyPI + :target: https://pypi.org/project/incremental/ + +.. |calver| image:: https://img.shields.io/badge/calver-YY.MM.MICRO-22bfda.svg + :alt: calver: YY.MM.MICRO + :target: https://calver.org/ .. |gha| image:: https://github.com/twisted/incremental/actions/workflows/tests.yaml/badge.svg -.. _gha: https://github.com/twisted/incremental/actions/workflows/tests.yaml + :alt: Tests + :target: https://github.com/twisted/incremental/actions/workflows/tests.yaml -.. |pypi| image:: http://img.shields.io/pypi/v/incremental.svg -.. _pypi: https://pypi.python.org/pypi/incremental +.. |coverage| image:: https://img.shields.io/badge/Coverage-100%25-green + :alt: Coverage: 100% diff --git a/contrib/python/incremental/py3/.dist-info/entry_points.txt b/contrib/python/incremental/py3/.dist-info/entry_points.txt index 5e1e6d9974f..d367ed50d5d 100644 --- a/contrib/python/incremental/py3/.dist-info/entry_points.txt +++ b/contrib/python/incremental/py3/.dist-info/entry_points.txt @@ -1,3 +1,6 @@ +[console_scripts] +incremental = incremental.update:_main + [distutils.setup_keywords] use_incremental = incremental:_get_distutils_version diff --git a/contrib/python/incremental/py3/README.rst b/contrib/python/incremental/py3/README.rst index 0d74e8a8b67..089e0cd4170 100644 --- a/contrib/python/incremental/py3/README.rst +++ b/contrib/python/incremental/py3/README.rst @@ -1,16 +1,29 @@ Incremental =========== -|gha| |pypi| +|calver| +|gha| |coverage| -Incremental is a small library that versions your Python projects. +Incremental is a `CalVer <https://calver.org/>`_ version manager supports the future. API documentation can be found `here <https://twisted.org/incremental/docs/>`_. +Narrative documentation follows. .. contents:: +Theory of Operation +------------------- + +- A version number has the form YY.MM.PATCH. +- If your project is named "Shrubbery", its code is found in ``shrubbery/`` or ``src/shrubbery/``. +- Incremental stores your project's version number in ``{src/}shrubbery/_version.py``. +- To update the version, run ``incremental update Shrubbery``, passing ``--rc`` and/or ``--patch`` as appropriate (see `Updating`_, below). +- Changing the version also updates any `indeterminate versions`_ in your codebase, like "Shrubbery NEXT", so you can reference the upcoming release in documentation. + That's how Incremental supports the future. + + Quick Start ----------- @@ -30,13 +43,13 @@ Add Incremental to your ``pyproject.toml``: [project] name = "<projectname>" - dynamic = ["version"] # ← Mark the version dynamic + dynamic = ["version"] # ← Mark the version dynamic dependencies = [ "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... - [tool.incremental] # ← Activate Incremental's setuptools plugin + [tool.incremental] # ← Activate Incremental's setuptools plugin It's fine if the ``[tool.incremental]`` table is empty, but it must be present. @@ -61,19 +74,19 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: [project] name = "<projectname>" - dynamic = ["version"] # ← Mark the version dynamic + dynamic = ["version"] # ← Mark the version dynamic dependencies = [ "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... [tool.hatch.version] - source = "incremental" # ← Activate Incremental's Hatchling plugin + source = "incremental" # ← Activate Incremental's Hatchling plugin Incremental can be configured as usual in an optional ``[tool.incremental]`` table. The ``hatch version`` command will report the Incremental-managed version. -Use the ``python -m incremental.update`` command to change the version (setting it with ``hatch version`` is not supported). +Use the ``incremental update`` command to change the version (setting it with ``hatch version`` is not supported). Next, `initialize the project`_. @@ -99,8 +112,8 @@ Then `initialize the project`_. Initialize the project ~~~~~~~~~~~~~~~~~~~~~~ -Install Incremental to your local environment with ``pip install incremental[scripts]``. -Then run ``python -m incremental.update <projectname> --create``. +Install Incremental to your local environment with ``pipx install incremental``. +Then run ``incremental update <projectname> --create``. It will create a file in your package named ``_version.py`` like this: .. code:: python @@ -111,15 +124,26 @@ It will create a file in your package named ``_version.py`` like this: __all__ = ["__version__"] -Then, so users of your project can find your version, in your root package's ``__init__.py`` add: +Subsequent installations of your project will then use Incremental for versioning. + + +Runtime integration +~~~~~~~~~~~~~~~~~~~ + +You may expose the ``incremental.Version`` from ``_version.py`` in your package's API. +To do so, add to your root package's ``__init__.py``: .. code:: python from ._version import __version__ +.. note:: -Subsequent installations of your project will then use Incremental for versioning. + Providing a ``__version__`` attribute is falling out of fashion following the introduction of `importlib.metadata.version() <https://docs.python.org/3/library/importlib.metadata.html#distribution-versions>`_ in Python 3.6, which can retrieve an installed package's version. +If you don't expose this object publicly, nor make use of it within your package, +then there is no need to depend on Incremental at runtime. +You can remove it from your project's ``dependencies`` array (or, in ``setup.py``, from ``install_requires``). Incremental Versions @@ -142,12 +166,12 @@ Calling ``repr()`` with a ``Version`` will give a Python-source-code representat Updating -------- -Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental.update``. +Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental``. It updates the ``_version.py`` file and automatically updates some uses of Incremental versions from an indeterminate version to the current one. It requires ``click`` from PyPI. -``python -m incremental.update <projectname>`` will perform updates on that package. -The commands that can be given after that will determine what the next version is. +``incremental update <projectname>`` will perform updates on that package. +The commands that can be given after that determine what the next version is. - ``--newversion=<version>``, to set the project version to a fully-specified version (like 1.2.3, or 17.1.0dev1). - ``--rc``, to set the project version to ``<year-2000>.<month>.0rc1`` if the current version is not a release candidate, or bump the release candidate number by 1 if it is. @@ -157,12 +181,15 @@ The commands that can be given after that will determine what the next version i If you give no arguments, it will strip the release candidate number, making it a "full release". +Indeterminate Versions +---------------------- + Incremental supports "indeterminate" versions, as a stand-in for the next "full" version. This can be used when the version which will be displayed to the end-user is unknown (for example "introduced in" or "deprecated in"). Incremental supports the following indeterminate versions: - ``Version("<projectname>", "NEXT", 0, 0)`` - ``<projectname> NEXT`` -When you run ``python -m incremental.update <projectname> --rc``, these will be updated to real versions (assuming the target final version is 17.1.0): +When you run ``incremental update <projectname> --rc``, these will be updated to real versions (assuming the target final version is 17.1.0): - ``Version("<projectname>", 17, 1, 0, release_candidate=1)`` - ``<projectname> 17.1.0rc1`` @@ -173,11 +200,17 @@ Once the final version is made, it will become: - ``<projectname> 17.1.0`` -.. |coverage| image:: https://codecov.io/gh/twisted/incremental/branch/master/graph/badge.svg?token=K2ieeL887X -.. _coverage: https://codecov.io/gh/twisted/incremental +.. |pypi| image:: http://img.shields.io/pypi/v/incremental.svg + :alt: PyPI + :target: https://pypi.org/project/incremental/ + +.. |calver| image:: https://img.shields.io/badge/calver-YY.MM.MICRO-22bfda.svg + :alt: calver: YY.MM.MICRO + :target: https://calver.org/ .. |gha| image:: https://github.com/twisted/incremental/actions/workflows/tests.yaml/badge.svg -.. _gha: https://github.com/twisted/incremental/actions/workflows/tests.yaml + :alt: Tests + :target: https://github.com/twisted/incremental/actions/workflows/tests.yaml -.. |pypi| image:: http://img.shields.io/pypi/v/incremental.svg -.. _pypi: https://pypi.python.org/pypi/incremental +.. |coverage| image:: https://img.shields.io/badge/Coverage-100%25-green + :alt: Coverage: 100% diff --git a/contrib/python/incremental/py3/incremental/__init__.py b/contrib/python/incremental/py3/incremental/__init__.py index aa960bbe1cf..afec27ddf0c 100644 --- a/contrib/python/incremental/py3/incremental/__init__.py +++ b/contrib/python/incremental/py3/incremental/__init__.py @@ -7,18 +7,13 @@ Versions for Python packages. See L{Version}. """ -from __future__ import division, absolute_import - import os import sys import warnings -from typing import TYPE_CHECKING, Any, TypeVar, Union, Optional, Dict, BinaryIO from dataclasses import dataclass - +from typing import TYPE_CHECKING, Any, BinaryIO, Dict, Literal, Optional, Union if TYPE_CHECKING: - import io - from typing_extensions import Literal from distutils.dist import Distribution as _Distribution @@ -27,7 +22,7 @@ if TYPE_CHECKING: # -def _cmp(a, b): # type: (Any, Any) -> int +def _cmp(a: Any, b: Any) -> int: """ Compare two objects. @@ -47,33 +42,32 @@ def _cmp(a, b): # type: (Any, Any) -> int # -class _Inf(object): +class _Inf: """ An object that is bigger than all other objects. """ - def __cmp__(self, other): # type: (object) -> int + def __cmp__(self, other: object) -> int: """ @param other: Another object. @type other: any @return: 0 if other is inf, 1 otherwise. - @rtype: C{int} """ if other is _inf: return 0 return 1 - def __lt__(self, other): # type: (object) -> bool + def __lt__(self, other: object) -> bool: return self.__cmp__(other) < 0 - def __le__(self, other): # type: (object) -> bool + def __le__(self, other: object) -> bool: return self.__cmp__(other) <= 0 - def __gt__(self, other): # type: (object) -> bool + def __gt__(self, other: object) -> bool: return self.__cmp__(other) > 0 - def __ge__(self, other): # type: (object) -> bool + def __ge__(self, other: object) -> bool: return self.__cmp__(other) >= 0 @@ -86,7 +80,7 @@ class IncomparableVersions(TypeError): """ -class Version(object): +class Version: """ An encapsulation of a version for a project, with support for outputting PEP-440 compatible version strings. @@ -97,14 +91,14 @@ class Version(object): def __init__( self, - package, # type: str - major, # type: Union[Literal["NEXT"], int] - minor, # type: int - micro, # type: int - release_candidate=None, # type: Optional[int] - prerelease=None, # type: Optional[int] - post=None, # type: Optional[int] - dev=None, # type: Optional[int] + package: str, + major: Union[Literal["NEXT"], int], + minor: int, + micro: int, + release_candidate: Optional[int] = None, + prerelease: Optional[int] = None, + post: Optional[int] = None, + dev: Optional[int] = None, ): """ @param package: Name of the package that this is a version of. @@ -151,7 +145,7 @@ class Version(object): self.dev = dev @property - def prerelease(self): # type: () -> Optional[int] + def prerelease(self) -> Optional[int]: warnings.warn( "Accessing incremental.Version.prerelease was " "deprecated in Incremental 16.9.0. Use " @@ -161,7 +155,7 @@ class Version(object): ) return self.release_candidate - def public(self): # type: () -> str + def public(self) -> str: """ Return a PEP440-compatible "public" representation of this L{Version}. @@ -178,55 +172,50 @@ class Version(object): if self.release_candidate is None: rc = "" else: - rc = "rc%s" % (self.release_candidate,) + rc = f"rc{self.release_candidate}" if self.post is None: post = "" else: - post = ".post%s" % (self.post,) + post = f".post{self.post}" if self.dev is None: dev = "" else: - dev = ".dev%s" % (self.dev,) + dev = f".dev{self.dev}" - return "%r.%d.%d%s%s%s" % (self.major, self.minor, self.micro, rc, post, dev) + return f"{self.major!r}.{self.minor:d}.{self.micro:d}{rc}{post}{dev}" base = public short = public local = public - def __repr__(self): # type: () -> str + def __repr__(self) -> str: if self.release_candidate is None: release_candidate = "" else: - release_candidate = ", release_candidate=%r" % (self.release_candidate,) + release_candidate = f", release_candidate={self.release_candidate!r}" if self.post is None: post = "" else: - post = ", post=%r" % (self.post,) + post = f", post={self.post!r}" if self.dev is None: dev = "" else: - dev = ", dev=%r" % (self.dev,) + dev = f", dev={self.dev!r}" - return "%s(%r, %r, %d, %d%s%s%s)" % ( - self.__class__.__name__, - self.package, - self.major, - self.minor, - self.micro, - release_candidate, - post, - dev, + return ( + f"{self.__class__.__name__}(" + f"{self.package!r}, {self.major!r}, {self.minor:d}, {self.micro:d}" + f"{release_candidate}{post}{dev})" ) - def __str__(self): # type: () -> str - return "[%s, version %s]" % (self.package, self.short()) + def __str__(self) -> str: + return f"[{self.package}, version {self.short()}]" - def __cmp__(self, other): # type: (object) -> int + def __cmp__(self, other: object) -> int: """ Compare two versions, considering major versions, minor versions, micro versions, then release candidates, then postreleases, then dev @@ -250,17 +239,21 @@ class Version(object): differ. """ if not isinstance(other, self.__class__): - return NotImplemented + # MyPy historically treated NotImplemented as Any, hence no-any-return. + # It doesn't seem to know that types.NotImplementedType exists, so it + # doesn't seem to be possible to correctly type-annotate this method. + # See https://github.com/python/mypy/issues/4791 for more weirdness. + return NotImplemented # type: ignore[no-any-return] if self.package.lower() != other.package.lower(): - raise IncomparableVersions("%r != %r" % (self.package, other.package)) + raise IncomparableVersions(f"{self.package!r} != {other.package!r}") if self.major == "NEXT": - major = _inf # type: Union[int, _Inf] + major: Union[int, _Inf] = _inf else: major = self.major if self.release_candidate is None: - release_candidate = _inf # type: Union[int, _Inf] + release_candidate: Union[int, _Inf] = _inf else: release_candidate = self.release_candidate @@ -270,17 +263,17 @@ class Version(object): post = self.post if self.dev is None: - dev = _inf # type: Union[int, _Inf] + dev: Union[int, _Inf] = _inf else: dev = self.dev if other.major == "NEXT": - othermajor = _inf # type: Union[int, _Inf] + othermajor: Union[int, _Inf] = _inf else: othermajor = other.major if other.release_candidate is None: - otherrc = _inf # type: Union[int, _Inf] + otherrc: Union[int, _Inf] = _inf else: otherrc = other.release_candidate @@ -290,7 +283,7 @@ class Version(object): otherpost = other.post if other.dev is None: - otherdev = _inf # type: Union[int, _Inf] + otherdev: Union[int, _Inf] = _inf else: otherdev = other.dev @@ -300,55 +293,55 @@ class Version(object): ) return x - def __eq__(self, other): # type: (object) -> bool + def __eq__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c == 0 - def __ne__(self, other): # type: (object) -> bool + def __ne__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c != 0 - def __lt__(self, other): # type: (object) -> bool + def __lt__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c < 0 - def __le__(self, other): # type: (object) -> bool + def __le__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c <= 0 - def __gt__(self, other): # type: (object) -> bool + def __gt__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c > 0 - def __ge__(self, other): # type: (object) -> bool + def __ge__(self, other: object) -> bool: c = self.__cmp__(other) if c is NotImplemented: return c # type: ignore[return-value] return c >= 0 -def getVersionString(version): # type: (Version) -> str +def getVersionString(version: Version) -> str: """ Get a friendly string for the given version object. @param version: A L{Version} object. @return: A string containing the package and short version number. """ - result = "%s %s" % (version.package, version.short()) + result = f"{version.package} {version.short()}" return result -def _findPath(path, package): # type: (str, str) -> str +def _findPath(path: str, package: str) -> str: """ Determine the package root directory. @@ -368,25 +361,23 @@ def _findPath(path, package): # type: (str, str) -> str return current_dir else: raise ValueError( - "Can't find the directory of project {}: I looked in {} and {}".format( - package, src_dir, current_dir - ) + f"Can't find the directory of project {package}: I looked in {src_dir} and {current_dir}" ) -def _existing_version(version_path): # type: (str) -> Version +def _existing_version(version_path: str) -> Version: """ Load the current version from a ``_version.py`` file. """ - version_info = {} # type: Dict[str, Version] + version_info: Dict[str, Version] = {} - with open(version_path, "r") as f: + with open(version_path) as f: exec(f.read(), version_info) return version_info["__version__"] -def _get_setuptools_version(dist): # type: (_Distribution) -> None +def _get_setuptools_version(dist: "_Distribution") -> None: """ Setuptools integration: load the version from the working directory @@ -421,7 +412,9 @@ def _get_setuptools_version(dist): # type: (_Distribution) -> None dist.metadata.version = version.public() -def _get_distutils_version(dist, keyword, value): # type: (_Distribution, object, object) -> None +def _get_distutils_version( + dist: "_Distribution", keyword: object, value: object +) -> None: """ Distutils integration: get the version from the package listed in the Distribution. @@ -446,7 +439,7 @@ def _get_distutils_version(dist, keyword, value): # type: (_Distribution, objec raise Exception("No _version.py found.") # pragma: no cover -def _load_toml(f): # type: (BinaryIO) -> Any +def _load_toml(f: BinaryIO) -> Any: """ Read the content of a TOML file. """ @@ -480,12 +473,12 @@ class _IncrementalConfig: """Path to the package root""" @property - def version_path(self): # type: () -> str + def version_path(self) -> str: """Path of the ``_version.py`` file. May not exist.""" return os.path.join(self.path, "_version.py") -def _load_pyproject_toml(toml_path): # type: (str) -> _IncrementalConfig +def _load_pyproject_toml(toml_path: str) -> _IncrementalConfig: """ Load Incremental configuration from a ``pyproject.toml`` @@ -527,9 +520,7 @@ Or: """) if not isinstance(package, str): - raise TypeError( - "The project name must be a string, but found {}".format(type(package)) - ) + raise TypeError(f"The project name must be a string, but found {type(package)}") return _IncrementalConfig( opt_in=tool_incremental is not None, @@ -538,7 +529,7 @@ Or: ) -def _extract_tool_incremental(data): # type: (Dict[str, object]) -> Optional[Dict[str, object]] +def _extract_tool_incremental(data: Dict[str, object]) -> Optional[Dict[str, object]]: if "tool" not in data: return None if not isinstance(data["tool"], dict): @@ -557,9 +548,4 @@ def _extract_tool_incremental(data): # type: (Dict[str, object]) -> Optional[Di from ._version import __version__ # noqa: E402 - -def _setuptools_version(): # type: () -> str - return __version__.public() # pragma: no cover - - -__all__ = ["__version__", "Version", "getVersionString"] +__all__ = ["Version", "__version__", "getVersionString"] diff --git a/contrib/python/incremental/py3/incremental/_hatch.py b/contrib/python/incremental/py3/incremental/_hatch.py index b7e53250a4b..f2feb544faf 100644 --- a/contrib/python/incremental/py3/incremental/_hatch.py +++ b/contrib/python/incremental/py3/incremental/_hatch.py @@ -5,10 +5,10 @@ import os import shlex from typing import Any, Dict, List, Type, TypedDict -from hatchling.version.source.plugin.interface import VersionSourceInterface from hatchling.plugin import hookimpl +from hatchling.version.source.plugin.interface import VersionSourceInterface -from incremental import _load_pyproject_toml, _existing_version +from incremental import _existing_version, _load_pyproject_toml class _VersionData(TypedDict): @@ -24,10 +24,12 @@ class IncrementalVersionSource(VersionSourceInterface): return {"version": _existing_version(config.version_path).public()} def set_version(self, version: str, version_data: Dict[Any, Any]) -> None: + path = os.path.join(self.root, "./pyproject.toml") # TODO: #111 Delete this. + config = _load_pyproject_toml(path) raise NotImplementedError( - f"Run `python -m incremental.version --newversion" + f"Run `incremental update {shlex.quote(config.package)} --newversion" f" {shlex.quote(version)}` to set the version.\n\n" - f" See `python -m incremental.version --help` for more options." + f" See `incremental --help` for more options." ) diff --git a/contrib/python/incremental/py3/incremental/_version.py b/contrib/python/incremental/py3/incremental/_version.py index 4cf64ac92c3..dc186c1036c 100644 --- a/contrib/python/incremental/py3/incremental/_version.py +++ b/contrib/python/incremental/py3/incremental/_version.py @@ -3,9 +3,9 @@ Provides Incremental version information. """ # This file is auto-generated! Do not edit! -# Use `python -m incremental.update Incremental` to change this file. +# Use `incremental` to change this file. from incremental import Version -__version__ = Version("Incremental", 24, 7, 2) +__version__ = Version("Incremental", 24, 11, 0) __all__ = ["__version__"] diff --git a/contrib/python/incremental/py3/incremental/update.py b/contrib/python/incremental/py3/incremental/update.py index 0c92e77768b..956be5fe33e 100644 --- a/contrib/python/incremental/py3/incremental/update.py +++ b/contrib/python/incremental/py3/incremental/update.py @@ -1,21 +1,20 @@ # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. -from __future__ import absolute_import, division, print_function -import click -import os import datetime -from typing import Dict, Optional, Callable +import os +from argparse import ArgumentParser +from typing import Any, Callable, Optional, Sequence -from incremental import Version, _findPath, _existing_version +from incremental import Version, _existing_version, _findPath _VERSIONPY_TEMPLATE = '''""" Provides {package} version information. """ # This file is auto-generated! Do not edit! -# Use `python -m incremental.update {package}` to change this file. +# Use `incremental` to change this file. from incremental import Version @@ -27,18 +26,18 @@ _YEAR_START = 2000 def _run( - package, # type: str - path, # type: Optional[str] - newversion, # type: Optional[str] - patch, # type: bool - rc, # type: bool - post, # type: bool - dev, # type: bool - create, # type: bool - _date=None, # type: Optional[datetime.date] - _getcwd=None, # type: Optional[Callable[[], str]] - _print=print, # type: Callable[[object], object] -): # type: (...) -> None + package: str, + path: Optional[str], + newversion: Optional[str], + patch: bool, + rc: bool, + post: bool, + dev: bool, + create: bool, + _date: Optional[datetime.date] = None, + _getcwd: Optional[Callable[[], str]] = None, + _print: Callable[[object], object] = print, +) -> None: if not _getcwd: _getcwd = os.getcwd @@ -49,40 +48,31 @@ def _run( path = _findPath(_getcwd(), package) if ( - newversion - and patch - or newversion - and dev - or newversion - and rc - or newversion - and post + (newversion and patch) + or (newversion and dev) + or (newversion and rc) + or (newversion and post) ): raise ValueError("Only give --newversion") - if dev and patch or dev and rc or dev and post: + if (dev and patch) or (dev and rc) or (dev and post): raise ValueError("Only give --dev") if ( - create - and dev - or create - and patch - or create - and rc - or create - and post - or create - and newversion + (create and dev) + or (create and patch) + or (create and rc) + or (create and post) + or (create and newversion) ): raise ValueError("Only give --create") versionpath = os.path.join(path, "_version.py") if newversion: - from pkg_resources import parse_version + from packaging.version import Version as parse_version existing = _existing_version(versionpath) - st_version = parse_version(newversion)._version # type: ignore[attr-defined] + st_version = parse_version(newversion) release = list(st_version.release) @@ -101,8 +91,8 @@ def _run( minor, micro, release_candidate=st_version.pre[1] if st_version.pre else None, - post=st_version.post[1] if st_version.post else None, - dev=st_version.dev[1] if st_version.dev else None, + post=st_version.post, + dev=st_version.dev, ) elif create: @@ -177,7 +167,7 @@ def _run( existing_version_repr = repr(existing).split("#")[0].replace("'", '"') existing_version_repr_bytes = existing_version_repr.encode("utf8") - _print("Updating codebase to %s" % (v.public())) + _print(f"Updating codebase to {v.public()}") for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: @@ -209,48 +199,71 @@ def _run( ) if content != original_content: - _print("Updating %s" % (filepath,)) + _print(f"Updating {filepath}") with open(filepath, "wb") as f: f.write(content) - _print("Updating %s" % (versionpath,)) + _print(f"Updating {versionpath}") with open(versionpath, "wb") as f: f.write( - ( - _VERSIONPY_TEMPLATE.format(package=package, version_repr=version_repr) - ).encode("utf8") + _VERSIONPY_TEMPLATE.format( + package=package, version_repr=version_repr + ).encode("utf-8") ) [email protected]("package") [email protected]("--path", default=None) [email protected]("--newversion", default=None) [email protected]("--patch", is_flag=True) [email protected]("--rc", is_flag=True) [email protected]("--post", is_flag=True) [email protected]("--dev", is_flag=True) [email protected]("--create", is_flag=True) -def run( - package, # type: str - path, # type: Optional[str] - newversion, # type: Optional[str] - patch, # type: bool - rc, # type: bool - post, # type: bool - dev, # type: bool - create, # type: bool -): # type: (...) -> None - return _run( - package=package, - path=path, - newversion=newversion, - patch=patch, - rc=rc, - post=post, - dev=dev, - create=create, +def _add_update_args(p: ArgumentParser) -> None: + p.add_argument("package") + p.add_argument("--path", default=None) + p.add_argument("--newversion", default=None, metavar="VERSION") + p.add_argument("--patch", default=False, action="store_true") + p.add_argument("--rc", default=False, action="store_true") + p.add_argument("--post", default=False, action="store_true") + p.add_argument("--dev", default=False, action="store_true") + p.add_argument("--create", default=False, action="store_true") + + +def _main(argv: Optional[Sequence[str]] = None) -> None: + """ + Entrypoint of the `incremental` script + """ + p = ArgumentParser() + subparsers = p.add_subparsers(required=True) + + update_p = subparsers.add_parser("update") + _add_update_args(update_p) + + args: Any = p.parse_args(argv) + _run( + package=args.package, + path=args.path, + newversion=args.newversion, + patch=args.patch, + rc=args.rc, + post=args.post, + dev=args.dev, + create=args.create, + ) + + +def run(argv: Optional[Sequence[str]] = None) -> None: + """ + Entrypoint for `python -m incremental.update` + """ + p = ArgumentParser() + _add_update_args(p) + args: Any = p.parse_args(argv) + _run( + package=args.package, + path=args.path, + newversion=args.newversion, + patch=args.patch, + rc=args.rc, + post=args.post, + dev=args.dev, + create=args.create, ) + raise SystemExit(0) # Behave like Click. if __name__ == "__main__": # pragma: no cover diff --git a/contrib/python/incremental/py3/ya.make b/contrib/python/incremental/py3/ya.make index 7809332c4e5..15ba33e6b69 100644 --- a/contrib/python/incremental/py3/ya.make +++ b/contrib/python/incremental/py3/ya.make @@ -2,12 +2,12 @@ PY3_LIBRARY() -VERSION(24.7.2) +VERSION(24.11.0) LICENSE(MIT) PEERDIR( - contrib/python/setuptools + contrib/python/packaging ) NO_LINT() |
