Skip to content

Commit 7e7701f

Browse files
authored
Use setuptools_scm to single-source an always-valid version number (#789)
The latest pip versions fail to install a source checkout if its version is set to `LAST_TAG`, which we do for all untagged commits. Use setuptools_scm instead, so that we always have a valid, PEP440-compliant version number, even for commits in between tags.
1 parent b2b556b commit 7e7701f

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
uses: actions/setup-python@v3
1818
with:
1919
python-version: 3.x
20-
- name: Replace the hard-coded version number
21-
run: sed -i "s/LAST_TAG/${GITHUB_REF#refs/tags/}/g" alibuild_helpers/__init__.py
2220
- name: Build the Python distribution
2321
run: python setup.py sdist
2422
- name: Publish distribution to PyPI

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ _site
1111
# For unit tests
1212
build.log
1313
.tox
14+
# For setuptools_scm
15+
alibuild_helpers/_version.py

alibuild_helpers/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# This file is needed to package build_template.sh.
22

3-
# Versions should comply with PEP440. For a discussion on single-sourcing the
4-
# version across setup.py and the project code, see
5-
# https://packaging.python.org/en/latest/single_source_version.html
6-
#
7-
# LAST_TAG is actually a placeholder which will be automatically replaced by
8-
# the release-alibuild pipeline in jenkins whenever we need a new release.
9-
__version__ = 'LAST_TAG'
3+
# Single-source a PEP440-compliant version using setuptools_scm.
4+
try:
5+
# This is an sdist or wheel, and it's properly installed.
6+
from alibuild_helpers._version import __version__
7+
except ImportError:
8+
# We're probably running directly from a source checkout.
9+
try:
10+
from setuptools_scm import get_version
11+
except ImportError:
12+
__version__ = '(could not detect version)'
13+
else:
14+
try:
15+
__version__ = get_version()
16+
except LookupError:
17+
__version__ = '(could not detect version)'
18+
finally:
19+
del get_version

setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from codecs import open
99
import os.path
1010
import sys
11-
import alibuild_helpers
1211

1312
here = os.path.abspath(os.path.dirname(__file__))
1413

@@ -25,8 +24,6 @@
2524
setup(
2625
name='alibuild',
2726

28-
version=alibuild_helpers.__version__,
29-
3027
description='ALICE Build Tool',
3128
long_description=long_description,
3229

@@ -75,6 +72,18 @@
7572
# this:
7673
# py_modules=["my_module"],
7774

75+
# Single-source our package version using setuptools_scm. This makes it
76+
# PEP440-compliant, and it always references the alibuild commit that
77+
# aliBuild was built from.
78+
use_scm_version={'write_to': 'alibuild_helpers/_version.py'},
79+
setup_requires=[
80+
# The 6.* series removed support for Python 2.7.
81+
'setuptools_scm<6.0.0' if sys.version_info < (3, 0) else
82+
# The 7.* series removed support for Python 3.6.
83+
'setuptools_scm<7.0.0' if sys.version_info < (3, 7) else
84+
'setuptools_scm'
85+
],
86+
7887
# List run-time dependencies here. These will be installed by pip when
7988
# your project is installed. For an analysis of "install_requires" vs pip's
8089
# requirements files see:

0 commit comments

Comments
 (0)