-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[WIP] Inference of setuptools' own version from git history #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
86588a3
0edc3b6
ecf79d9
7dc8851
a1658e0
b2ed1e6
aee4dc9
8573e95
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ backend-path = ["."] | |
|
||
[project] | ||
name = "setuptools" | ||
version = "78.1.0" | ||
authors = [ | ||
{ name = "Python Packaging Authority", email = "[email protected]" }, | ||
] | ||
|
@@ -26,6 +25,7 @@ requires-python = ">=3.9" | |
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,14 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
import textwrap | ||
import time | ||
|
||
import setuptools | ||
from setuptools import _normalization | ||
from setuptools.command.install import install | ||
|
||
here = os.path.dirname(__file__) | ||
|
@@ -26,6 +30,21 @@ | |
package_data.setdefault('setuptools.command', []).extend(['*.xml']) | ||
|
||
|
||
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 | ||
if os.path.exists("PKG-INFO"): # building wheel from sdist | ||
with open("PKG-INFO", encoding="utf-8") as fp: | ||
if match := re.search(r"^Version: (\d+\.\d+\.\d+.*)$", fp.read(), re.M): | ||
return match[1] | ||
with open("NEWS.rst", encoding="utf-8") as fp: | ||
match = re.search(r"v\d+\.\d+\.\d+", fp.read()) # latest version | ||
return f"{match[0] if match else '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.
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. BTW, the I have considered checking if a 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. OK, it may be necessary to check for $ python -m build
Successfully built setuptools-78.1.2.tar.gz and setuptools-78.1.2.dev0+20250416-py3-none-any.whl 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.
So I inevitably had to add some lines in aee4dc9 to deal with this problem: It does increase the complexity of the solution. We can see now consistency between version inference in sdist and wheel: https://github.com/pypa/setuptools/actions/runs/14501313828/job/40681414420?pr=4948#step:8:3078 |
||
|
||
|
||
def pypi_link(pkg_filename): | ||
""" | ||
Given the filename, including md5 fragment, construct the | ||
|
@@ -76,13 +95,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 98 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: | ||
|
@@ -65,7 +65,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") | ||
|
@@ -80,6 +83,8 @@ 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' | ||
""" | ||
# See pkg_resources._forgiving_version | ||
try: | ||
|
@@ -94,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.