File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424from many other contributors within Google.
2525"""
2626
27+ import re
2728import sys
2829from datetime import date
30+ from pathlib import Path
2931
3032from setuptools import find_packages , setup
3133from setuptools .command .install import install
3234from setuptools .dist import Distribution
3335
34- CUR_VERSION = "0.7.7"
36+
37+ def read_version ():
38+ """Return the package version from tensorflow_quantum/__init__.py."""
39+
40+ # Need to account for 2 situations: when setup.py is copied to a build
41+ # directory, and when setup.py is in a 'release/' subdirectory.
42+ here = Path (__file__ ).resolve ().parent
43+ possible_paths = [
44+ here / "tensorflow_quantum" / "__init__.py" ,
45+ here .parent / "tensorflow_quantum" / "__init__.py" ,
46+ ]
47+
48+ for init_path in possible_paths :
49+ if init_path .is_file ():
50+ content = init_path .read_text (encoding = "utf-8" )
51+ # Look for __version__ = 'X.Y.Z' at the start of a line.
52+ version_match = re .search (r'^__version__\s*=\s*[\'"]([^\'"]+)[\'"]' ,
53+ content , re .MULTILINE )
54+ if version_match :
55+ return version_match .group (1 )
56+
57+ raise RuntimeError (
58+ "Could not find a valid __version__ definition. Checked:\n " +
59+ "\n " .join (f" - { p } " for p in possible_paths ))
60+
61+
62+ CUR_VERSION = read_version ()
3563
3664DOCLINES = __doc__ .split ("\n " )
3765
You can’t perform that action at this time.
0 commit comments