Skip to content

Commit b0b0e9d

Browse files
MarkDaoustcopybara-github
authored andcommitted
PR #456: Fix to version numbering so that it is in accordance with PEP 404
Please approve this CL. It will be submitted automatically, and its GitHub pull request will be marked as merged. Imported from GitHub PR #456 Recently I tried installing this repo through pip, and it failed with the following message: ``` raise InvalidVersion(f"Invalid version: '{version}'") pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'b4eb09b4a3d167557d999723f7c2ed0d53a1bb7d-' ``` After some googling, I found that this is by design: * pypa/setuptools#2497 * pypa/setuptools#3772 Apparently, `Setuptools` only supports version numbering in accordance with [PEP 404](https://peps.python.org/pep-0440/) from version 66 onwards. So I created a fork of this repo, changing the version numbering scheme so that it can be installed through pip. The idea is essentially the same as it is currently, with only some minor modifications. Currently, the version number is simply the hash of the most recent commit, so there isn't any pattern or sequence to be worried about. PEP 404 required the version number to be in base 10, so I changed the base 16 representation of the commit hash to base 10. By keeping the commit hash, the commit can still be retrieved through the version number. I also prepended the commit's timestamp, so that the more recent commits have higher version numbering. Copybara import of the project: - db7542d Change version numbering to be in accordance with PEP 440... by Eduardo <[email protected]> - 94860f6 Minor changes for clarity and add explanatory comments. by Eduardo <[email protected]> - f0d9155 Merge 94860f6 into b4eb0... by Eduardo Santos Carlos de Souza <[email protected]> PiperOrigin-RevId: 532326489
1 parent eb5c721 commit b0b0e9d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

setup.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,23 @@
3131
sys.argv.remove('--nightly')
3232

3333
project_name = 'tensorflow-examples'
34-
# Get the current commit hash
35-
version = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8')
34+
# Get the current commit hash and timestamp
35+
# The timestamp is used so that newer commits have a higher version number
36+
# The hash is used so that the specific commit can be identified
37+
# The hash integer can be converted back to the hash string with:
38+
# '%032x' % commit_hash_int
39+
commit_hash_int = int(
40+
subprocess.check_output(['git', 'rev-parse', 'HEAD'])
41+
.decode('utf-8')
42+
.strip(),
43+
16,
44+
)
45+
commit_timestamp = (
46+
subprocess.check_output(['git', 'show', '-s', '--format=%ct', 'HEAD'])
47+
.decode('utf-8')
48+
.strip()
49+
)
50+
version = f'0.{commit_timestamp}.{commit_hash_int}'
3651

3752
if nightly:
3853
project_name = 'tensorflow-examples-nightly'

0 commit comments

Comments
 (0)