-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Inference of setuptools' own version from git history (without setuptools-scm) #4948
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
base: main
Are you sure you want to change the base?
Changes from all commits
f6f2cc2
2ff5a0e
346ae7e
072df10
28d4522
d50b3cb
723ca92
f1956af
06343cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Setuptools stopped using ``egg_info --tag-build --tag-date`` for its own build | ||
process. Instead version is now inferred from git tag history. | ||
To ensure the proper version is considered, please make sure to fetch the git tags. | ||
Local development tags are added to the latest version if the latest commit is not tagged. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ backend-path = ["."] | |
|
||
[project] | ||
name = "setuptools" | ||
version = "80.9.0" | ||
authors = [ | ||
{ name = "Python Packaging Authority", email = "[email protected]" }, | ||
] | ||
|
@@ -31,6 +30,7 @@ license = "MIT" | |
dependencies = [ | ||
] | ||
keywords = ["CPAN PyPI distutils eggs package management"] | ||
dynamic = ["version"] | ||
|
||
[project.urls] | ||
Source = "https://github.com/pypa/setuptools" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
#!/usr/bin/env python | ||
from __future__ import annotations | ||
|
||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
import textwrap | ||
import time | ||
from contextlib import suppress | ||
from itertools import starmap | ||
|
||
import setuptools | ||
from setuptools import _normalization | ||
from setuptools.command.install import install | ||
|
||
here = os.path.dirname(__file__) | ||
|
@@ -26,6 +33,29 @@ | |
package_data.setdefault('setuptools.command', []).extend(['*.xml']) | ||
|
||
|
||
_VERSION_FALLBACK = [ | ||
("PKG-INFO", r"^Version: (\d+\.\d+\.\d+.*)$", "{match[1]}"), # sdist | ||
("NEWS.rst", r"^v(\d+\.\d+\.\d+)", "{match[1]}.dev+{timestamp}"), # latest version | ||
] | ||
|
||
|
||
def _extract_version(file: str, pattern: str, fmt: str) -> str | None: | ||
with suppress(FileNotFoundError), open(file, encoding="utf-8") as fp: | ||
if match := re.search(pattern, fp.read(), re.M): | ||
return fmt.format(match=match, timestamp=time.strftime("%Y%m%d")) | ||
return None | ||
|
||
|
||
def _get_version() -> str: | ||
cmd = ["git", "describe", "--abbrev", "--match", "v?[0-9]*", "--dirty"] | ||
try: | ||
version = subprocess.check_output(cmd, encoding="utf-8") | ||
return _normalization.best_effort_version(version, "{safe}.dev+{sanitized}") | ||
except subprocess.CalledProcessError: # e.g.: git not installed or history missing | ||
candidates = filter(None, starmap(_extract_version, _VERSION_FALLBACK)) | ||
return next(candidates, f"0.0.0.dev+{time.strftime('%Y%m%d')}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reposting from thread in https://github.com/pypa/setuptools/pull/4948/files#r2047494928: The exact format of the version can be further discussed, e.g. The Reading Reading I cannot see |
||
|
||
|
||
def pypi_link(pkg_filename): | ||
""" | ||
Given the filename, including md5 fragment, construct the | ||
|
@@ -76,13 +106,14 @@ | |
""" | ||
Undo secondary effect of `extra_path` adding to `install_lib` | ||
""" | ||
suffix = os.path.relpath(self.install_lib, self.install_libbase) | ||
Check warning on line 109 in setup.py
|
||
|
||
if suffix.strip() == self._pth_contents.strip(): | ||
self.install_lib = self.install_libbase | ||
|
||
|
||
setup_params = dict( | ||
version=_get_version(), | ||
cmdclass={'install': install_with_pth}, | ||
package_data=package_data, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I) | ||
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.I) | ||
_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.I) | ||
_PEP440_FALLBACK = re.compile(r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I) | ||
_PEP440_FALLBACK = re.compile(r"^(?P<safe>v?(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an existing bug that I have identified when working on this PR. >>> best_effort_version("v78.1.0-2-g3a3144f0d")
'78.1.0.dev0+sanitized.2.g3a3144f0d' |
||
|
||
|
||
def safe_identifier(name: str) -> str: | ||
|
@@ -64,7 +64,10 @@ def safe_version(version: str) -> str: | |
return str(packaging.version.Version(attempt)) | ||
|
||
|
||
def best_effort_version(version: str) -> str: | ||
def best_effort_version( | ||
version: str, | ||
template: str = "{safe}.dev0+sanitized.{sanitized}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This customisable template parameter is not strictly necessary, it can be removed if we don't mind versions looking like |
||
) -> str: | ||
"""Convert an arbitrary string into a version-like string. | ||
Fallback when ``safe_version`` is not safe enough. | ||
>>> best_effort_version("v0.2 beta") | ||
|
@@ -79,6 +82,10 @@ def best_effort_version(version: str) -> str: | |
'0.dev0+sanitized' | ||
>>> best_effort_version("42.+?1") | ||
'42.dev0+sanitized.1' | ||
>>> best_effort_version("v78.1.0-2-g3a3144f0d") | ||
'78.1.0.dev0+sanitized.2.g3a3144f0d' | ||
>>> best_effort_version("v80.9.0-18-gdf932b02e-dirty", "{safe}.dev+{sanitized}") | ||
'80.9.0.dev0+18.gdf932b02e.dirty' | ||
""" | ||
try: | ||
return safe_version(version) | ||
|
@@ -92,8 +99,8 @@ def best_effort_version(version: str) -> str: | |
safe = "0" | ||
rest = version | ||
safe_rest = _NON_ALPHANUMERIC.sub(".", rest).strip(".") | ||
local = f"sanitized.{safe_rest}".strip(".") | ||
return safe_version(f"{safe}.dev0+{local}") | ||
fallback = template.format(safe=safe, sanitized=safe_rest).strip(".") | ||
return safe_version(fallback) | ||
|
||
|
||
def safe_extra(extra: str) -> str: | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,11 +63,10 @@ description = assemble changelog and tag a release | |
skip_install = True | ||
deps = | ||
towncrier | ||
bump2version | ||
jaraco.develop >= 7.23 | ||
pass_env = * | ||
commands = | ||
python tools/finalize.py | ||
python -m jaraco.develop.finalize | ||
|
||
[testenv:vendor] | ||
skip_install = True | ||
|
@@ -102,8 +101,6 @@ setenv = | |
TWINE_USERNAME = {env:TWINE_USERNAME:__token__} | ||
commands = | ||
python -c "import shutil; shutil.rmtree('dist', ignore_errors=True)" | ||
# unset tag_build and tag_date pypa/setuptools#2500 | ||
python setup.py egg_info -Db "" saveopts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we would no longer need this. |
||
python -m build | ||
python -m twine upload dist/* | ||
python -m jaraco.develop.create-github-release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the absence of the commit/tag history it is not possible to infer the version correctly. So we need a deep checkout.
This has been discussed in https://github.com/pypa/setuptools/pull/4537/files#r1701658826.
The approach seems to be the standard workaround for the same problem in
setuptools-scm
, see pypa/setuptools-scm#480, pypa/setuptools-scm#952 (comment). Tracked in actions/checkout#249 and actions/checkout#1471.