Skip to content

Commit 7edb262

Browse files
committed
Change 'release' flag to be derived from VERSION
Previously setup.py decided if it was in "release mode" by looking at command-line flags or environment variables. This meant that distributed sdists could not tell that they were supposed to be building in release mode, and so would add on additional local version information. Instead, we change our release procedures such that the VERSION file has a '.dev' postfix if this is a development release, and it doesn't have one if it isn't. Development branches such as 'master' and 'dev.major' will always have this development postfix, but release branches won't.
1 parent ca1ec00 commit 7edb262

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ jobs:
4343
needs: deploy_test
4444
runs-on: ubuntu-latest
4545
env:
46-
CI_QUTIP_RELEASE: 1
4746
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }}
4847

4948
steps:
@@ -107,9 +106,6 @@ jobs:
107106
env:
108107
# Set up wheels matrix. This is CPython 3.6--3.9 for all OS targets.
109108
CIBW_BUILD: "cp3[6-9]-*"
110-
# Environment variable understood by QuTiP's setup.py to produce a release
111-
# version of the wheels.
112-
CIBW_ENVIRONMENT: "CI_QUTIP_RELEASE=1"
113109
OVERRIDE_VERSION: ${{ github.event.inputs.override_version }}
114110

115111
steps:
@@ -160,6 +156,17 @@ jobs:
160156
- name: Download build artifacts to local runner
161157
uses: actions/download-artifact@v2
162158

159+
- uses: actions/setup-python@v2
160+
name: Install Python
161+
with:
162+
python-version: '3.7'
163+
164+
- name: Verify this is not a dev version
165+
shell: bash
166+
run: |
167+
python -m pip install wheels/*-cp37-cp37m-manylinux2010_x86_64.whl
168+
python -c 'import qutip; print(qutip.__version__); assert "dev" not in qutip.__version__; assert "+" not in qutip.__version__'
169+
163170
# We built the zipfile for convenience distributing to Windows users on
164171
# our end, but PyPI only needs the tarball.
165172
- name: Upload sdist and wheels to PyPI

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.7.0
1+
4.7.0.dev

doc/development/release_distribution.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ Create a new branch from this, e.g. ::
103103

104104
$ git checkout -b 4.1-release_ready qutip-4.1.X
105105

106-
First change the ``VERSION`` file to contain the new version number.
106+
First change the ``VERSION`` file to contain the new version number, and remove any ``dev`` postfix if present.
107107
A major release increments the first number, while a minor release increments the second.
108108
All numbers after the change digit are reset to 0, so the next minor release after 4.5.3 is 4.6.0, and the next major release after either of these is 5.0.0.
109+
Alpha, beta and release-candidate releases have a postfix ``.a<n>``, ``.b<n>`` or ``.rc<n>`` repsectively, where ``<n>`` is a counter for the pre-release status, starting from 0.
110+
For example, the third beta release of version 5.2.1 would have a version of ``5.2.1.b2``.
109111
The file should contain only the version number in this format, with no extra characters (the automatic line-break at the end is fine).
110112

111113
Next edit ``setup.cfg``.
@@ -124,7 +126,7 @@ The "Development Status" of ``master`` should remain ::
124126
Development Status :: 2 - Pre-Alpha
125127

126128
because it is never directly released.
127-
The ``VERSION`` file on ``master`` should reflect the last major or minor release.
129+
The ``VERSION`` file on ``master`` should reflect the last major or minor release, with a trailing ``.dev`` to indicate that this is a development branch.
128130

129131

130132
.. _docbuild:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build-system]
22
requires = [
33
"setuptools",
4+
"packaging",
45
"wheel",
56
"cython>=0.29.20",
67
"numpy>=1.16.6,<1.20",

setup.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import warnings
1111

1212
# Required third-party imports, must be specified in pyproject.toml.
13+
import packaging.version
1314
from setuptools import setup, Extension
1415
import distutils.sysconfig
1516
import numpy as np
@@ -49,15 +50,9 @@ def process_options():
4950

5051
def _determine_user_arguments(options):
5152
"""
52-
Add the 'release' and 'openmp' options to the collection, based on the
53-
passed command-line arguments or environment variables.
53+
Add the 'openmp' option to the collection, based on the passed command-line
54+
arguments or environment variables.
5455
"""
55-
options['release'] = (
56-
'--release' in sys.argv
57-
or bool(os.environ.get('CI_QUTIP_RELEASE'))
58-
)
59-
if '--release' in sys.argv:
60-
sys.argv.remove('--release')
6156
options['openmp'] = (
6257
'--with-openmp' in sys.argv
6358
or bool(os.environ.get('CI_QUTIP_WITH_OPENMP'))
@@ -104,7 +99,7 @@ def _determine_compilation_options(options):
10499

105100
def _determine_version(options):
106101
"""
107-
Adds the 'short_version' and 'version' options.
102+
Adds the 'short_version', 'version' and 'release' options.
108103
109104
Read from the VERSION file to discover the version. This should be a
110105
single line file containing valid Python package public identifier (see PEP
@@ -117,27 +112,31 @@ def _determine_version(options):
117112
"""
118113
version_filename = os.path.join(options['rootdir'], 'VERSION')
119114
with open(version_filename, "r") as version_file:
120-
version = options['short_version'] = version_file.read().strip()
121-
VERSION_RE = r'\d+(\.\d+)*((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?'
122-
if re.fullmatch(VERSION_RE, version, re.A) is None:
123-
raise ValueError("invalid version: " + version)
115+
version_string = version_file.read().strip()
116+
version = packaging.version.parse(version_string)
117+
if isinstance(version, packaging.version.LegacyVersion):
118+
raise ValueError("invalid version: " + version_string)
119+
options['short_version'] = str(version.public)
120+
options['release'] = not version.is_devrelease
124121
if not options['release']:
125-
version += "+"
122+
# Put the version string into canonical form, if it wasn't already.
123+
version_string = str(version)
124+
version_string += "+"
126125
try:
127126
git_out = subprocess.run(
128127
('git', 'rev-parse', '--verify', '--short=7', 'HEAD'),
129128
check=True,
130129
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
131130
)
132131
git_hash = git_out.stdout.decode(sys.stdout.encoding).strip()
133-
version += git_hash or "nogit"
132+
version_string += git_hash or "nogit"
134133
# CalledProcessError is for if the git command fails for internal
135134
# reasons (e.g. we're not in a git repository), OSError is for if
136135
# something goes wrong when trying to run git (e.g. it's not installed,
137136
# or a permission error).
138137
except (subprocess.CalledProcessError, OSError):
139-
version += "nogit"
140-
options['version'] = version
138+
version_string += "nogit"
139+
options['version'] = version_string
141140
return options
142141

143142

0 commit comments

Comments
 (0)