Skip to content

Commit 42ba7d6

Browse files
committed
__version__
1 parent 1d4b947 commit 42ba7d6

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
steps:
5454
- uses: actions/checkout@v3
5555
- uses: actions/setup-python@v3
56-
- run: python dev/overwrite_dev_versions_with_date.py
56+
- run: python tools/overwrite_dev_versions_with_date.py
5757
- run: mkdir -p output/stim
5858
- run: mkdir -p output/stimcirq
5959
- run: mkdir -p output/sinter

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def build_extension(self, ext):
4949
], cwd=build_temp, env=build_env)
5050

5151

52-
version = '0.0.dev0'
52+
__version__ = '0.0.dev0'
5353

5454
with open("README.md", "r", encoding="utf-8") as f:
5555
long_description = f.read()
@@ -64,7 +64,7 @@ def build_extension(self, ext):
6464

6565
setuptools.setup(
6666
name="chromobius",
67-
version=version,
67+
version=__version__,
6868
author="Craig Gidney",
6969
url="https://github.com/quantumlib/chromobius",
7070
description="A fast implementation of the mobius color code decoder.",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
3+
#########################################################
4+
# Sets version numbers to a date-based dev version.
5+
#
6+
# Does nothing if not on a dev version.
7+
#########################################################
8+
# Example usage (from repo root):
9+
#
10+
# ./dev/overwrite_dev_versions_with_date.sh
11+
#########################################################
12+
13+
import os
14+
import pathlib
15+
import re
16+
import subprocess
17+
18+
19+
def main():
20+
os.chdir(pathlib.Path(__file__).parent)
21+
os.chdir(subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode().strip())
22+
23+
# Generate dev version starting from major.minor version.
24+
# (Requires the existing version to have a 'dev' suffix.)
25+
# (Uses the timestamp of the HEAD commit, to ensure consistency when run multiple times.)
26+
with open('setup.py') as f:
27+
maj_min_version_line, = [line for line in f.read().splitlines() if re.match("^__version__ = '[^']+'", line)]
28+
maj_version, min_version, patch = maj_min_version_line.split()[-1].strip("'").split('.')
29+
if 'dev' not in patch:
30+
return # Do nothing for non-dev versions.
31+
timestamp = subprocess.check_output(['git', 'show', '-s', '--format=%ct', 'HEAD']).decode().strip()
32+
new_version = f"{maj_version}.{min_version}.dev{timestamp}"
33+
34+
# Overwrite existing versions.
35+
package_setup_files = [
36+
"setup.py",
37+
]
38+
for path in package_setup_files:
39+
with open(path) as f:
40+
content = f.read()
41+
assert maj_min_version_line in content
42+
content = content.replace(maj_min_version_line, f"__version__ = '{new_version}'")
43+
with open(path, 'w') as f:
44+
print(content, file=f, end='')
45+
46+
47+
if __name__ == '__main__':
48+
main()

0 commit comments

Comments
 (0)