diff options
author | shmel1k <shmel1k@ydb.tech> | 2023-11-26 18:16:14 +0300 |
---|---|---|
committer | shmel1k <shmel1k@ydb.tech> | 2023-11-26 18:43:30 +0300 |
commit | b8cf9e88f4c5c64d9406af533d8948deb050d695 (patch) | |
tree | 218eb61fb3c3b96ec08b4d8cdfef383104a87d63 /contrib/python/incremental/py2 | |
parent | 523f645a83a0ec97a0332dbc3863bb354c92a328 (diff) | |
download | ydb-b8cf9e88f4c5c64d9406af533d8948deb050d695.tar.gz |
add kikimr_configure
Diffstat (limited to 'contrib/python/incremental/py2')
-rw-r--r-- | contrib/python/incremental/py2/.dist-info/METADATA | 136 | ||||
-rw-r--r-- | contrib/python/incremental/py2/.dist-info/entry_points.txt | 2 | ||||
-rw-r--r-- | contrib/python/incremental/py2/.dist-info/top_level.txt | 1 | ||||
-rw-r--r-- | contrib/python/incremental/py2/LICENSE | 74 | ||||
-rw-r--r-- | contrib/python/incremental/py2/README.rst | 108 | ||||
-rw-r--r-- | contrib/python/incremental/py2/incremental/__init__.py | 395 | ||||
-rw-r--r-- | contrib/python/incremental/py2/incremental/_version.py | 11 | ||||
-rw-r--r-- | contrib/python/incremental/py2/incremental/py.typed | 0 | ||||
-rw-r--r-- | contrib/python/incremental/py2/incremental/update.py | 331 | ||||
-rw-r--r-- | contrib/python/incremental/py2/ya.make | 30 |
10 files changed, 1088 insertions, 0 deletions
diff --git a/contrib/python/incremental/py2/.dist-info/METADATA b/contrib/python/incremental/py2/.dist-info/METADATA new file mode 100644 index 0000000000..c4a9409082 --- /dev/null +++ b/contrib/python/incremental/py2/.dist-info/METADATA @@ -0,0 +1,136 @@ +Metadata-Version: 2.1 +Name: incremental +Version: 22.10.0 +Summary: "A small library that versions your Python projects." +Home-page: https://github.com/twisted/incremental +Maintainer: Amber Brown +Maintainer-email: hawkowl@twistedmatrix.com +License: MIT +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +License-File: LICENSE +Provides-Extra: mypy +Requires-Dist: click (>=6.0) ; extra == 'mypy' +Requires-Dist: twisted (>=16.4.0) ; extra == 'mypy' +Requires-Dist: mypy (==0.812) ; extra == 'mypy' +Provides-Extra: scripts +Requires-Dist: click (>=6.0) ; extra == 'scripts' +Requires-Dist: twisted (>=16.4.0) ; extra == 'scripts' + +Incremental +=========== + +|gha| +|pypi| +|coverage| + +Incremental is a small library that versions your Python projects. + +API documentation can be found `here <https://twisted.github.io/incremental/docs/>`_. + + +Quick Start +----------- + +Add this to your ``setup.py``\ 's ``setup()`` call, removing any other versioning arguments: + +.. code:: + + setup( + use_incremental=True, + setup_requires=['incremental'], + install_requires=['incremental'], # along with any other install dependencies + ... + } + + +Install Incremental to your local environment with ``pip install incremental[scripts]``. +Then run ``python -m incremental.update <projectname> --create``. +It will create a file in your package named ``_version.py`` and look like this: + +.. code:: + + from incremental import Version + + __version__ = Version("widgetbox", 17, 1, 0) + __all__ = ["__version__"] + + +Then, so users of your project can find your version, in your root package's ``__init__.py`` add: + +.. code:: + + from ._version import __version__ + + +Subsequent installations of your project will then use Incremental for versioning. + + +Incremental Versions +-------------------- + +``incremental.Version`` is a class that represents a version of a given project. +It is made up of the following elements (which are given during instantiation): + +- ``package`` (required), the name of the package this ``Version`` represents. +- ``major``, ``minor``, ``micro`` (all required), the X.Y.Z of your project's ``Version``. +- ``release_candidate`` (optional), set to 0 or higher to mark this ``Version`` being of a release candidate (also sometimes called a "prerelease"). +- ``post`` (optional), set to 0 or higher to mark this ``Version`` as a postrelease. +- ``dev`` (optional), set to 0 or higher to mark this ``Version`` as a development release. + +You can extract a PEP-440 compatible version string by using the ``.public()`` method, which returns a ``str`` containing the full version. This is the version you should provide to users, or publicly use. An example output would be ``"13.2.0"``, ``"17.1.2dev1"``, or ``"18.8.0rc2"``. + +Calling ``repr()`` with a ``Version`` will give a Python-source-code representation of it, and calling ``str()`` with a ``Version`` will provide a string similar to ``'[Incremental, version 16.10.1]'``. + + +Updating +-------- + +Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental.update``. +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. + +- ``--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. +- ``--dev``, to set the project development release number to 0 if it is not a development release, or bump the development release number by 1 if it is. +- ``--patch``, to increment the patch number of the release. This will also reset the release candidate number, pass ``--rc`` at the same time to increment the patch number and make it a release candidate. +- ``--post``, to set the project postrelease number to 0 if it is not a postrelease, or bump the postrelease number by 1 if it is. This will also reset the release candidate and development release numbers. + +If you give no arguments, it will strip the release candidate number, making it a "full release". + +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): + +- ``Version("<projectname>", 17, 1, 0, release_candidate=1)`` +- ``<projectname> 17.1.0rc1`` + +Once the final version is made, it will become: + +- ``Version("<projectname>", 17, 1, 0)`` +- ``<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 + +.. |gha| image:: https://github.com/twisted/incremental/actions/workflows/tests.yaml/badge.svg +.. _gha: 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 diff --git a/contrib/python/incremental/py2/.dist-info/entry_points.txt b/contrib/python/incremental/py2/.dist-info/entry_points.txt new file mode 100644 index 0000000000..1c7b4877c1 --- /dev/null +++ b/contrib/python/incremental/py2/.dist-info/entry_points.txt @@ -0,0 +1,2 @@ +[distutils.setup_keywords] +use_incremental = incremental:_get_version diff --git a/contrib/python/incremental/py2/.dist-info/top_level.txt b/contrib/python/incremental/py2/.dist-info/top_level.txt new file mode 100644 index 0000000000..cb4023922a --- /dev/null +++ b/contrib/python/incremental/py2/.dist-info/top_level.txt @@ -0,0 +1 @@ +incremental diff --git a/contrib/python/incremental/py2/LICENSE b/contrib/python/incremental/py2/LICENSE new file mode 100644 index 0000000000..bc9d47f332 --- /dev/null +++ b/contrib/python/incremental/py2/LICENSE @@ -0,0 +1,74 @@ +Incremental +----------- + +This project includes code from the Twisted Project, which is licensed as below. + +Copyright (c) 2001-2015 +Allen Short +Amber Hawkie Brown +Andrew Bennetts +Andy Gayton +Antoine Pitrou +Apple Computer, Inc. +Ashwini Oruganti +Benjamin Bruheim +Bob Ippolito +Canonical Limited +Christopher Armstrong +David Reid +Divmod Inc. +Donovan Preston +Eric Mangold +Eyal Lotem +Google Inc. +Hybrid Logic Ltd. +Hynek Schlawack +Itamar Turner-Trauring +James Knight +Jason A. Mobarak +Jean-Paul Calderone +Jessica McKellar +Jonathan D. Simms +Jonathan Jacobs +Jonathan Lange +Julian Berman +Jürgen Hermann +Kevin Horn +Kevin Turner +Laurens Van Houtven +Mary Gardiner +Massachusetts Institute of Technology +Matthew Lefkowitz +Moshe Zadka +Paul Swartz +Pavel Pergamenshchik +Rackspace, US Inc. +Ralph Meijer +Richard Wall +Sean Riley +Software Freedom Conservancy +Tavendo GmbH +Thijs Triemstra +Thomas Herve +Timothy Allen +Tom Prince +Travis B. Hartwell + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/contrib/python/incremental/py2/README.rst b/contrib/python/incremental/py2/README.rst new file mode 100644 index 0000000000..7a20d077af --- /dev/null +++ b/contrib/python/incremental/py2/README.rst @@ -0,0 +1,108 @@ +Incremental +=========== + +|gha| +|pypi| +|coverage| + +Incremental is a small library that versions your Python projects. + +API documentation can be found `here <https://twisted.github.io/incremental/docs/>`_. + + +Quick Start +----------- + +Add this to your ``setup.py``\ 's ``setup()`` call, removing any other versioning arguments: + +.. code:: + + setup( + use_incremental=True, + setup_requires=['incremental'], + install_requires=['incremental'], # along with any other install dependencies + ... + } + + +Install Incremental to your local environment with ``pip install incremental[scripts]``. +Then run ``python -m incremental.update <projectname> --create``. +It will create a file in your package named ``_version.py`` and look like this: + +.. code:: + + from incremental import Version + + __version__ = Version("widgetbox", 17, 1, 0) + __all__ = ["__version__"] + + +Then, so users of your project can find your version, in your root package's ``__init__.py`` add: + +.. code:: + + from ._version import __version__ + + +Subsequent installations of your project will then use Incremental for versioning. + + +Incremental Versions +-------------------- + +``incremental.Version`` is a class that represents a version of a given project. +It is made up of the following elements (which are given during instantiation): + +- ``package`` (required), the name of the package this ``Version`` represents. +- ``major``, ``minor``, ``micro`` (all required), the X.Y.Z of your project's ``Version``. +- ``release_candidate`` (optional), set to 0 or higher to mark this ``Version`` being of a release candidate (also sometimes called a "prerelease"). +- ``post`` (optional), set to 0 or higher to mark this ``Version`` as a postrelease. +- ``dev`` (optional), set to 0 or higher to mark this ``Version`` as a development release. + +You can extract a PEP-440 compatible version string by using the ``.public()`` method, which returns a ``str`` containing the full version. This is the version you should provide to users, or publicly use. An example output would be ``"13.2.0"``, ``"17.1.2dev1"``, or ``"18.8.0rc2"``. + +Calling ``repr()`` with a ``Version`` will give a Python-source-code representation of it, and calling ``str()`` with a ``Version`` will provide a string similar to ``'[Incremental, version 16.10.1]'``. + + +Updating +-------- + +Incremental includes a tool to automate updating your Incremental-using project's version called ``incremental.update``. +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. + +- ``--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. +- ``--dev``, to set the project development release number to 0 if it is not a development release, or bump the development release number by 1 if it is. +- ``--patch``, to increment the patch number of the release. This will also reset the release candidate number, pass ``--rc`` at the same time to increment the patch number and make it a release candidate. +- ``--post``, to set the project postrelease number to 0 if it is not a postrelease, or bump the postrelease number by 1 if it is. This will also reset the release candidate and development release numbers. + +If you give no arguments, it will strip the release candidate number, making it a "full release". + +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): + +- ``Version("<projectname>", 17, 1, 0, release_candidate=1)`` +- ``<projectname> 17.1.0rc1`` + +Once the final version is made, it will become: + +- ``Version("<projectname>", 17, 1, 0)`` +- ``<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 + +.. |gha| image:: https://github.com/twisted/incremental/actions/workflows/tests.yaml/badge.svg +.. _gha: 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 diff --git a/contrib/python/incremental/py2/incremental/__init__.py b/contrib/python/incremental/py2/incremental/__init__.py new file mode 100644 index 0000000000..c0c06c0ae1 --- /dev/null +++ b/contrib/python/incremental/py2/incremental/__init__.py @@ -0,0 +1,395 @@ +# Copyright (c) Twisted Matrix Laboratories. +# See LICENSE for details. + +""" +Versions for Python packages. + +See L{Version}. +""" + +from __future__ import division, absolute_import + +import sys +import warnings +from typing import TYPE_CHECKING, Any, TypeVar, Union, Optional, Dict + +# +# Compat functions +# + +_T = TypeVar("_T", contravariant=True) + + +if TYPE_CHECKING: + from typing_extensions import Literal + from distutils.dist import Distribution as _Distribution + + +else: + _Distribution = object + +if sys.version_info > (3,): + + def _cmp(a, b): # type: (Any, Any) -> int + """ + Compare two objects. + + Returns a negative number if C{a < b}, zero if they are equal, and a + positive number if C{a > b}. + """ + if a < b: + return -1 + elif a == b: + return 0 + else: + return 1 + + +else: + _cmp = cmp # noqa: F821 + + +# +# Versioning +# + + +class _Inf(object): + """ + An object that is bigger than all other objects. + """ + + def __cmp__(self, other): # type: (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 + + if sys.version_info >= (3,): + + def __lt__(self, other): # type: (object) -> bool + return self.__cmp__(other) < 0 + + def __le__(self, other): # type: (object) -> bool + return self.__cmp__(other) <= 0 + + def __gt__(self, other): # type: (object) -> bool + return self.__cmp__(other) > 0 + + def __ge__(self, other): # type: (object) -> bool + return self.__cmp__(other) >= 0 + + +_inf = _Inf() + + +class IncomparableVersions(TypeError): + """ + Two versions could not be compared. + """ + + +class Version(object): + """ + An encapsulation of a version for a project, with support for outputting + PEP-440 compatible version strings. + + This class supports the standard major.minor.micro[rcN] scheme of + versioning. + """ + + 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] + ): + """ + @param package: Name of the package that this is a version of. + @type package: C{str} + @param major: The major version number. + @type major: C{int} or C{str} (for the "NEXT" symbol) + @param minor: The minor version number. + @type minor: C{int} + @param micro: The micro version number. + @type micro: C{int} + @param release_candidate: The release candidate number. + @type release_candidate: C{int} + @param prerelease: The prerelease number. (Deprecated) + @type prerelease: C{int} + @param post: The postrelease number. + @type post: C{int} + @param dev: The development release number. + @type dev: C{int} + """ + if release_candidate and prerelease: + raise ValueError("Please only return one of these.") + elif prerelease and not release_candidate: + release_candidate = prerelease + warnings.warn( + "Passing prerelease to incremental.Version was " + "deprecated in Incremental 16.9.0. Please pass " + "release_candidate instead.", + DeprecationWarning, + stacklevel=2, + ) + + if major == "NEXT": + if minor or micro or release_candidate or post or dev: + raise ValueError( + "When using NEXT, all other values except Package must be 0." + ) + + self.package = package + self.major = major + self.minor = minor + self.micro = micro + self.release_candidate = release_candidate + self.post = post + self.dev = dev + + @property + def prerelease(self): # type: () -> Optional[int] + warnings.warn( + "Accessing incremental.Version.prerelease was " + "deprecated in Incremental 16.9.0. Use " + "Version.release_candidate instead.", + DeprecationWarning, + stacklevel=2, + ), + return self.release_candidate + + def public(self): # type: () -> str + """ + Return a PEP440-compatible "public" representation of this L{Version}. + + Examples: + + - 14.4.0 + - 1.2.3rc1 + - 14.2.1rc1dev9 + - 16.04.0dev0 + """ + if self.major == "NEXT": + return self.major + + if self.release_candidate is None: + rc = "" + else: + rc = ".rc%s" % (self.release_candidate,) + + if self.post is None: + post = "" + else: + post = ".post%s" % (self.post,) + + if self.dev is None: + dev = "" + else: + dev = ".dev%s" % (self.dev,) + + return "%r.%d.%d%s%s%s" % (self.major, self.minor, self.micro, rc, post, dev) + + base = public + short = public + local = public + + def __repr__(self): # type: () -> str + + if self.release_candidate is None: + release_candidate = "" + else: + release_candidate = ", release_candidate=%r" % (self.release_candidate,) + + if self.post is None: + post = "" + else: + post = ", post=%r" % (self.post,) + + if self.dev is None: + dev = "" + else: + dev = ", dev=%r" % (self.dev,) + + return "%s(%r, %r, %d, %d%s%s%s)" % ( + self.__class__.__name__, + self.package, + self.major, + self.minor, + self.micro, + release_candidate, + post, + dev, + ) + + def __str__(self): # type: () -> str + return "[%s, version %s]" % (self.package, self.short()) + + def __cmp__(self, other): # type: (Version) -> int + """ + Compare two versions, considering major versions, minor versions, micro + versions, then release candidates, then postreleases, then dev + releases. Package names are case insensitive. + + A version with a release candidate is always less than a version + without a release candidate. If both versions have release candidates, + they will be included in the comparison. + + Likewise, a version with a dev release is always less than a version + without a dev release. If both versions have dev releases, they will + be included in the comparison. + + @param other: Another version. + @type other: L{Version} + + @return: NotImplemented when the other object is not a Version, or one + of -1, 0, or 1. + + @raise IncomparableVersions: when the package names of the versions + differ. + """ + if not isinstance(other, self.__class__): + return NotImplemented + if self.package.lower() != other.package.lower(): + raise IncomparableVersions("%r != %r" % (self.package, other.package)) + + if self.major == "NEXT": + major = _inf # type: Union[int, _Inf] + else: + major = self.major + + if self.release_candidate is None: + release_candidate = _inf # type: Union[int, _Inf] + else: + release_candidate = self.release_candidate + + if self.post is None: + post = -1 + else: + post = self.post + + if self.dev is None: + dev = _inf # type: Union[int, _Inf] + else: + dev = self.dev + + if other.major == "NEXT": + othermajor = _inf # type: Union[int, _Inf] + else: + othermajor = other.major + + if other.release_candidate is None: + otherrc = _inf # type: Union[int, _Inf] + else: + otherrc = other.release_candidate + + if other.post is None: + otherpost = -1 + else: + otherpost = other.post + + if other.dev is None: + otherdev = _inf # type: Union[int, _Inf] + else: + otherdev = other.dev + + x = _cmp( + (major, self.minor, self.micro, release_candidate, post, dev), + (othermajor, other.minor, other.micro, otherrc, otherpost, otherdev), + ) + return x + + if sys.version_info >= (3,): + + def __eq__(self, other): # type: (Any) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c == 0 + + def __ne__(self, other): # type: (Any) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c != 0 + + def __lt__(self, other): # type: (Version) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c < 0 + + def __le__(self, other): # type: (Version) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c <= 0 + + def __gt__(self, other): # type: (Version) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c > 0 + + def __ge__(self, other): # type: (Version) -> bool + c = self.__cmp__(other) + if c is NotImplemented: + return c # type: ignore[return-value] + return c >= 0 + + +def getVersionString(version): # type: (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()) + return result + + +def _get_version(dist, keyword, value): # type: (_Distribution, object, object) -> None + """ + Get the version from the package listed in the Distribution. + """ + if not value: + return + + from distutils.command import build_py + + sp_command = build_py.build_py(dist) + sp_command.finalize_options() + + for item in sp_command.find_all_modules(): # type: ignore[attr-defined] + if item[1] == "_version": + version_file = {} # type: Dict[str, Version] + + with open(item[2]) as f: + exec(f.read(), version_file) + + dist.metadata.version = version_file["__version__"].public() + return None + + raise Exception("No _version.py found.") + + +from ._version import __version__ # noqa: E402 + + +def _setuptools_version(): # type: () -> str + return __version__.public() + + +__all__ = ["__version__", "Version", "getVersionString"] diff --git a/contrib/python/incremental/py2/incremental/_version.py b/contrib/python/incremental/py2/incremental/_version.py new file mode 100644 index 0000000000..12cb1b8151 --- /dev/null +++ b/contrib/python/incremental/py2/incremental/_version.py @@ -0,0 +1,11 @@ +""" +Provides Incremental version information. +""" + +# This file is auto-generated! Do not edit! +# Use `python -m incremental.update Incremental` to change this file. + +from incremental import Version + +__version__ = Version("Incremental", 22, 10, 0) +__all__ = ["__version__"] diff --git a/contrib/python/incremental/py2/incremental/py.typed b/contrib/python/incremental/py2/incremental/py.typed new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/contrib/python/incremental/py2/incremental/py.typed diff --git a/contrib/python/incremental/py2/incremental/update.py b/contrib/python/incremental/py2/incremental/update.py new file mode 100644 index 0000000000..64a5cc84e7 --- /dev/null +++ b/contrib/python/incremental/py2/incremental/update.py @@ -0,0 +1,331 @@ +# 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 TYPE_CHECKING, Dict, Optional, Callable, Iterable + +from incremental import Version + +if TYPE_CHECKING: + from typing_extensions import Protocol + + class _ReadableWritable(Protocol): + def read(self): # type: () -> bytes + pass + + def write(self, v): # type: (bytes) -> object + pass + + def __enter__(self): # type: () -> _ReadableWritable + pass + + def __exit__(self, *args, **kwargs): # type: (object, object) -> Optional[bool] + pass + + # FilePath is missing type annotations + # https://twistedmatrix.com/trac/ticket/10148 + class FilePath(object): + def __init__(self, path): # type: (str) -> None + self.path = path + + def child(self, v): # type: (str) -> FilePath + pass + + def isdir(self): # type: () -> bool + pass + + def isfile(self): # type: () -> bool + pass + + def getContent(self): # type: () -> bytes + pass + + def open(self, mode): # type: (str) -> _ReadableWritable + pass + + def walk(self): # type: () -> Iterable[FilePath] + pass + + +else: + from twisted.python.filepath import FilePath + +_VERSIONPY_TEMPLATE = '''""" +Provides {package} version information. +""" + +# This file is auto-generated! Do not edit! +# Use `python -m incremental.update {package}` to change this file. + +from incremental import Version + +__version__ = {version_repr} +__all__ = ["__version__"] +''' + +_YEAR_START = 2000 + + +def _findPath(path, package): # type: (str, str) -> FilePath + + cwd = FilePath(path) + + src_dir = cwd.child("src").child(package.lower()) + current_dir = cwd.child(package.lower()) + + if src_dir.isdir(): + return src_dir + elif current_dir.isdir(): + return current_dir + else: + raise ValueError( + "Can't find under `./src` or `./`. Check the " + "package name is right (note that we expect your " + "package name to be lower cased), or pass it using " + "'--path'." + ) + + +def _existing_version(path): # type: (FilePath) -> Version + version_info = {} # type: Dict[str, Version] + + with path.child("_version.py").open("r") as f: + exec(f.read(), version_info) + + return version_info["__version__"] + + +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 + + if not _getcwd: + _getcwd = os.getcwd + + if not _date: + _date = datetime.date.today() + + if type(package) != str: + package = package.encode("utf8") # type: ignore[assignment] + + _path = FilePath(path) if path else _findPath(_getcwd(), package) + + if ( + 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: + 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 + ): + raise ValueError("Only give --create") + + if newversion: + from pkg_resources import parse_version + + existing = _existing_version(_path) + st_version = parse_version(newversion)._version # type: ignore[attr-defined] + + release = list(st_version.release) + + minor = 0 + micro = 0 + if len(release) == 1: + (major,) = release + elif len(release) == 2: + major, minor = release + else: + major, minor, micro = release + + v = Version( + package, + major, + 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, + ) + + elif create: + v = Version(package, _date.year - _YEAR_START, _date.month, 0) + existing = v + + elif rc and not patch: + existing = _existing_version(_path) + + if existing.release_candidate: + v = Version( + package, + existing.major, + existing.minor, + existing.micro, + existing.release_candidate + 1, + ) + else: + v = Version(package, _date.year - _YEAR_START, _date.month, 0, 1) + + elif patch: + existing = _existing_version(_path) + v = Version( + package, + existing.major, + existing.minor, + existing.micro + 1, + 1 if rc else None, + ) + + elif post: + existing = _existing_version(_path) + + if existing.post is None: + _post = 0 + else: + _post = existing.post + 1 + + v = Version(package, existing.major, existing.minor, existing.micro, post=_post) + + elif dev: + existing = _existing_version(_path) + + if existing.dev is None: + _dev = 0 + else: + _dev = existing.dev + 1 + + v = Version( + package, + existing.major, + existing.minor, + existing.micro, + existing.release_candidate, + dev=_dev, + ) + + else: + existing = _existing_version(_path) + + if existing.release_candidate: + v = Version(package, existing.major, existing.minor, existing.micro) + else: + raise ValueError("You need to issue a rc before updating the major/minor") + + NEXT_repr = repr(Version(package, "NEXT", 0, 0)).split("#")[0].replace("'", '"') + NEXT_repr_bytes = NEXT_repr.encode("utf8") + + version_repr = repr(v).split("#")[0].replace("'", '"') + version_repr_bytes = version_repr.encode("utf8") + + existing_version_repr = repr(existing).split("#")[0].replace("'", '"') + existing_version_repr_bytes = existing_version_repr.encode("utf8") + + _print("Updating codebase to %s" % (v.public())) + + for x in _path.walk(): + + if not x.isfile(): + continue + + original_content = x.getContent() + content = original_content + + # Replace previous release_candidate calls to the new one + if existing.release_candidate: + content = content.replace(existing_version_repr_bytes, version_repr_bytes) + content = content.replace( + (package.encode("utf8") + b" " + existing.public().encode("utf8")), + (package.encode("utf8") + b" " + v.public().encode("utf8")), + ) + + # Replace NEXT Version calls with the new one + content = content.replace(NEXT_repr_bytes, version_repr_bytes) + content = content.replace( + NEXT_repr_bytes.replace(b"'", b'"'), version_repr_bytes + ) + + # Replace <package> NEXT with <package> <public> + content = content.replace( + package.encode("utf8") + b" NEXT", + (package.encode("utf8") + b" " + v.public().encode("utf8")), + ) + + if content != original_content: + _print("Updating %s" % (x.path,)) + with x.open("w") as f: + f.write(content) + + _print("Updating %s/_version.py" % (_path.path)) + with _path.child("_version.py").open("w") as f: + f.write( + ( + _VERSIONPY_TEMPLATE.format(package=package, version_repr=version_repr) + ).encode("utf8") + ) + + +@click.command() +@click.argument("package") +@click.option("--path", default=None) +@click.option("--newversion", default=None) +@click.option("--patch", is_flag=True) +@click.option("--rc", is_flag=True) +@click.option("--post", is_flag=True) +@click.option("--dev", is_flag=True) +@click.option("--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, + ) + + +if __name__ == "__main__": # pragma: no cover + run() diff --git a/contrib/python/incremental/py2/ya.make b/contrib/python/incremental/py2/ya.make new file mode 100644 index 0000000000..bf41780b7e --- /dev/null +++ b/contrib/python/incremental/py2/ya.make @@ -0,0 +1,30 @@ +# Generated by devtools/yamaker (pypi). + +PY2_LIBRARY() + +VERSION(22.10.0) + +LICENSE(MIT) + +NO_LINT() + +NO_CHECK_IMPORTS( + incremental.update +) + +PY_SRCS( + TOP_LEVEL + incremental/__init__.py + incremental/_version.py + incremental/update.py +) + +RESOURCE_FILES( + PREFIX contrib/python/incremental/py2/ + .dist-info/METADATA + .dist-info/entry_points.txt + .dist-info/top_level.txt + incremental/py.typed +) + +END() |