diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-13 08:14:28 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-13 08:23:21 +0300 |
commit | 79b357cabf7b8edfcdb3dec816d0f7172c9f7f97 (patch) | |
tree | 5c2ce1588b6d53d7732d40c19754e06f285d580b /contrib | |
parent | 225a97565211be7452d2b59dcbbd2fb76ec46da8 (diff) | |
download | ydb-79b357cabf7b8edfcdb3dec816d0f7172c9f7f97.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/python/incremental/py3/.dist-info/METADATA | 10 | ||||
-rw-r--r-- | contrib/python/incremental/py3/README.rst | 8 | ||||
-rw-r--r-- | contrib/python/incremental/py3/incremental/__init__.py | 77 | ||||
-rw-r--r-- | contrib/python/incremental/py3/incremental/_hatch.py | 3 | ||||
-rw-r--r-- | contrib/python/incremental/py3/incremental/_version.py | 2 | ||||
-rw-r--r-- | contrib/python/incremental/py3/incremental/update.py | 14 | ||||
-rw-r--r-- | contrib/python/incremental/py3/ya.make | 2 |
7 files changed, 67 insertions, 49 deletions
diff --git a/contrib/python/incremental/py3/.dist-info/METADATA b/contrib/python/incremental/py3/.dist-info/METADATA index 6cefbff794..77552dbb83 100644 --- a/contrib/python/incremental/py3/.dist-info/METADATA +++ b/contrib/python/incremental/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: incremental -Version: 24.7.1 +Version: 24.7.2 Summary: A small library that versions your Python projects. Maintainer-email: Amber Brown <hawkowl@twistedmatrix.com> Project-URL: Homepage, https://github.com/twisted/incremental @@ -51,7 +51,7 @@ Add Incremental to your ``pyproject.toml``: [build-system] requires = [ "setuptools", - "incremental>=24.7.0", # ← Add incremental as a build dependency + "incremental>=24.7.2", # ← Add incremental as a build dependency ] build-backend = "setuptools.build_meta" @@ -59,7 +59,7 @@ Add Incremental to your ``pyproject.toml``: name = "<projectname>" dynamic = ["version"] # ← Mark the version dynamic dependencies = [ - "incremental>=24.7.0", # ← Depend on incremental at runtime + "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... @@ -82,7 +82,7 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: [build-system] requires = [ "hatchling", - "incremental>=24.7.0", # ← Add incremental as a build dependency + "incremental>=24.7.2", # ← Add incremental as a build dependency ] build-backend = "hatchling.build" @@ -90,7 +90,7 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: name = "<projectname>" dynamic = ["version"] # ← Mark the version dynamic dependencies = [ - "incremental>=24.7.0", # ← Depend on incremental at runtime + "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... diff --git a/contrib/python/incremental/py3/README.rst b/contrib/python/incremental/py3/README.rst index 56baba2fca..0d74e8a8b6 100644 --- a/contrib/python/incremental/py3/README.rst +++ b/contrib/python/incremental/py3/README.rst @@ -24,7 +24,7 @@ Add Incremental to your ``pyproject.toml``: [build-system] requires = [ "setuptools", - "incremental>=24.7.0", # ← Add incremental as a build dependency + "incremental>=24.7.2", # ← Add incremental as a build dependency ] build-backend = "setuptools.build_meta" @@ -32,7 +32,7 @@ Add Incremental to your ``pyproject.toml``: name = "<projectname>" dynamic = ["version"] # ← Mark the version dynamic dependencies = [ - "incremental>=24.7.0", # ← Depend on incremental at runtime + "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... @@ -55,7 +55,7 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: [build-system] requires = [ "hatchling", - "incremental>=24.7.0", # ← Add incremental as a build dependency + "incremental>=24.7.2", # ← Add incremental as a build dependency ] build-backend = "hatchling.build" @@ -63,7 +63,7 @@ activate Incremental's Hatchling plugin by altering your ``pyproject.toml``: name = "<projectname>" dynamic = ["version"] # ← Mark the version dynamic dependencies = [ - "incremental>=24.7.0", # ← Depend on incremental at runtime + "incremental>=24.7.2", # ← Depend on incremental at runtime ] # ... diff --git a/contrib/python/incremental/py3/incremental/__init__.py b/contrib/python/incremental/py3/incremental/__init__.py index 7a29fd7b05..aa960bbe1c 100644 --- a/contrib/python/incremental/py3/incremental/__init__.py +++ b/contrib/python/incremental/py3/incremental/__init__.py @@ -368,20 +368,19 @@ def _findPath(path, package): # type: (str, str) -> str return current_dir else: raise ValueError( - "Can't find the directory of package {}: I looked in {} and {}".format( + "Can't find the directory of project {}: I looked in {} and {}".format( package, src_dir, current_dir ) ) -def _existing_version(path): # type: (str) -> Version +def _existing_version(version_path): # type: (str) -> Version """ - Load the current version from {path}/_version.py. + Load the current version from a ``_version.py`` file. """ version_info = {} # type: Dict[str, Version] - versionpath = os.path.join(path, "_version.py") - with open(versionpath, "r") as f: + with open(version_path, "r") as f: exec(f.read(), version_info) return version_info["__version__"] @@ -392,18 +391,34 @@ def _get_setuptools_version(dist): # type: (_Distribution) -> None Setuptools integration: load the version from the working directory This function is registered as a setuptools.finalize_distribution_options - entry point [1]. It is a no-op unless there is a pyproject.toml containing - an empty [tool.incremental] section. - - @param dist: An empty C{setuptools.Distribution} instance to mutate. + entry point [1]. Consequently, it is called in all sorts of weird + contexts. In setuptools, silent failure is the law. [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#customizing-distribution-options + + @param dist: + A (possibly) empty C{setuptools.Distribution} instance to mutate. + There may be some metadata here if a `setup.py` called `setup()`, + but this hook is always called before setuptools loads anything + from ``pyproject.toml``. """ - config = _load_pyproject_toml("./pyproject.toml") - if not config or not config.has_tool_incremental: + try: + # When operating in a packaging context (i.e. building an sdist or + # wheel) pyproject.toml will always be found in the current working + # directory. + config = _load_pyproject_toml("./pyproject.toml") + except Exception: + return + + if not config.opt_in: return - dist.metadata.version = _existing_version(config.path).public() + try: + version = _existing_version(config.version_path) + except FileNotFoundError: + return + + dist.metadata.version = version.public() def _get_distutils_version(dist, keyword, value): # type: (_Distribution, object, object) -> None @@ -424,8 +439,8 @@ def _get_distutils_version(dist, keyword, value): # type: (_Distribution, objec for item in sp_command.find_all_modules(): if item[1] == "_version": - package_path = os.path.dirname(item[2]) - dist.metadata.version = _existing_version(package_path).public() + version_path = os.path.join(os.path.dirname(item[2]), "_version.py") + dist.metadata.version = _existing_version(version_path).public() return raise Exception("No _version.py found.") # pragma: no cover @@ -451,7 +466,7 @@ class _IncrementalConfig: Configuration loaded from a ``pyproject.toml`` file. """ - has_tool_incremental: bool + opt_in: bool """ Does the pyproject.toml file contain a [tool.incremental] section? This indicates that the package has explicitly @@ -459,13 +474,18 @@ class _IncrementalConfig: """ package: str - """The package name, capitalized as in the package metadata.""" + """The project name, capitalized as in the project metadata.""" path: str """Path to the package root""" + @property + def version_path(self): # type: () -> 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) -> Optional[_IncrementalConfig] +def _load_pyproject_toml(toml_path): # type: (str) -> _IncrementalConfig """ Load Incremental configuration from a ``pyproject.toml`` @@ -473,30 +493,29 @@ def _load_pyproject_toml(toml_path): # type: (str) -> Optional[_IncrementalConf from the [project] section. Otherwise we require only a C{name} key specifying the project name. Other keys are forbidden to allow future extension and catch typos. + + @param toml_path: + Path to the ``pyproject.toml`` to load. """ - try: - with open(toml_path, "rb") as f: - data = _load_toml(f) - except FileNotFoundError: - return None + with open(toml_path, "rb") as f: + data = _load_toml(f) tool_incremental = _extract_tool_incremental(data) + # Extract the project name package = None if tool_incremental is not None and "name" in tool_incremental: package = tool_incremental["name"] if package is None: + # Try to fall back to [project] try: package = data["project"]["name"] except KeyError: pass if package is None: - # We can't proceed without a project name, but that's only an error - # if [tool.incremental] is present. - if tool_incremental is None: - return None + # We can't proceed without a project name. raise ValueError("""\ -Couldn't extract the package name from pyproject.toml. Specify it like: +Incremental failed to extract the project name from pyproject.toml. Specify it like: [project] name = "Foo" @@ -509,11 +528,11 @@ Or: """) if not isinstance(package, str): raise TypeError( - "Package name must be a string, but found {}".format(type(package)) + "The project name must be a string, but found {}".format(type(package)) ) return _IncrementalConfig( - has_tool_incremental=tool_incremental is not None, + opt_in=tool_incremental is not None, package=package, path=_findPath(os.path.dirname(toml_path), package), ) diff --git a/contrib/python/incremental/py3/incremental/_hatch.py b/contrib/python/incremental/py3/incremental/_hatch.py index 8d677c4b9d..b7e53250a4 100644 --- a/contrib/python/incremental/py3/incremental/_hatch.py +++ b/contrib/python/incremental/py3/incremental/_hatch.py @@ -21,8 +21,7 @@ class IncrementalVersionSource(VersionSourceInterface): def get_version_data(self) -> _VersionData: # type: ignore[override] path = os.path.join(self.root, "./pyproject.toml") config = _load_pyproject_toml(path) - assert config is not None, "Failed to read {}".format(path) - return {"version": _existing_version(config.path).public()} + return {"version": _existing_version(config.version_path).public()} def set_version(self, version: str, version_data: Dict[Any, Any]) -> None: raise NotImplementedError( diff --git a/contrib/python/incremental/py3/incremental/_version.py b/contrib/python/incremental/py3/incremental/_version.py index 654a7b7cd4..4cf64ac92c 100644 --- a/contrib/python/incremental/py3/incremental/_version.py +++ b/contrib/python/incremental/py3/incremental/_version.py @@ -7,5 +7,5 @@ Provides Incremental version information. from incremental import Version -__version__ = Version("Incremental", 24, 7, 1) +__version__ = Version("Incremental", 24, 7, 2) __all__ = ["__version__"] diff --git a/contrib/python/incremental/py3/incremental/update.py b/contrib/python/incremental/py3/incremental/update.py index f3e33ee003..0c92e77768 100644 --- a/contrib/python/incremental/py3/incremental/update.py +++ b/contrib/python/incremental/py3/incremental/update.py @@ -77,10 +77,11 @@ def _run( ): raise ValueError("Only give --create") + versionpath = os.path.join(path, "_version.py") if newversion: from pkg_resources import parse_version - existing = _existing_version(path) + existing = _existing_version(versionpath) st_version = parse_version(newversion)._version # type: ignore[attr-defined] release = list(st_version.release) @@ -109,7 +110,7 @@ def _run( existing = v elif rc and not patch: - existing = _existing_version(path) + existing = _existing_version(versionpath) if existing.release_candidate: v = Version( @@ -123,7 +124,7 @@ def _run( v = Version(package, _date.year - _YEAR_START, _date.month, 0, 1) elif patch: - existing = _existing_version(path) + existing = _existing_version(versionpath) v = Version( package, existing.major, @@ -133,7 +134,7 @@ def _run( ) elif post: - existing = _existing_version(path) + existing = _existing_version(versionpath) if existing.post is None: _post = 0 @@ -143,7 +144,7 @@ def _run( v = Version(package, existing.major, existing.minor, existing.micro, post=_post) elif dev: - existing = _existing_version(path) + existing = _existing_version(versionpath) if existing.dev is None: _dev = 0 @@ -160,7 +161,7 @@ def _run( ) else: - existing = _existing_version(path) + existing = _existing_version(versionpath) if existing.release_candidate: v = Version(package, existing.major, existing.minor, existing.micro) @@ -212,7 +213,6 @@ def _run( with open(filepath, "wb") as f: f.write(content) - versionpath = os.path.join(path, "_version.py") _print("Updating %s" % (versionpath,)) with open(versionpath, "wb") as f: f.write( diff --git a/contrib/python/incremental/py3/ya.make b/contrib/python/incremental/py3/ya.make index 668dd7c5e2..7809332c4e 100644 --- a/contrib/python/incremental/py3/ya.make +++ b/contrib/python/incremental/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(24.7.1) +VERSION(24.7.2) LICENSE(MIT) |