File tree Expand file tree Collapse file tree 4 files changed +65
-14
lines changed Expand file tree Collapse file tree 4 files changed +65
-14
lines changed Original file line number Diff line number Diff line change 55# This source code is licensed under the BSD-style license found in the
66# LICENSE file in the root directory of this source tree.
77
8- import os
9- import re
108import sys
119from datetime import date
1210
11+ from base_version_gen import BASE_VERSION
1312from setuptools import find_packages , setup
1413
1514
16- def get_version ():
17- # get version string from version.py
18- # TODO: ideally the version.py should be generated when setup is run
19- version_file = os .path .join (os .path .dirname (__file__ ), "torchx/version.py" )
20- version_regex = r"__version__ = ['\"]([^'\"]*)['\"]"
21- with open (version_file , "r" ) as f :
22- version = re .search (version_regex , f .read (), re .M ).group (1 )
23- return version
24-
25-
2615def get_nightly_version ():
2716 today = date .today ()
2817 return f"{ today .year } .{ today .month } .{ today .day } "
@@ -49,7 +38,7 @@ def get_nightly_version():
4938 with open ("dev-requirements.txt" ) as f :
5039 dev_reqs = f .read ()
5140
52- version = get_nightly_version () if is_nightly else get_version ()
41+ version = get_nightly_version () if is_nightly else BASE_VERSION
5342 print (f"-- { name } building version: { version } " )
5443
5544 setup (
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3+ # All rights reserved.
4+ #
5+ # This source code is licensed under the BSD-style license found in the
6+ # LICENSE file in the root directory of this source tree.
7+
8+ # pyre-strict
9+ BASE_VERSION = "0.8.0dev0"
Original file line number Diff line number Diff line change 99
1010from torchx .util .entrypoints import load
1111
12+ from .version_gen import get_fb_version
13+
1214# Follows PEP-0440 version scheme guidelines
1315# https://www.python.org/dev/peps/pep-0440/#version-scheme
1416#
1820# 0.1.0bN # Beta release
1921# 0.1.0rcN # Release Candidate
2022# 0.1.0 # Final release
21- __version__ = "0.8.0dev0"
23+ __version__ : str = get_fb_version ()
2224
2325
2426# Use the github container registry images corresponding to the current package
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3+ # All rights reserved.
4+ #
5+ # This source code is licensed under the BSD-style license found in the
6+ # LICENSE file in the root directory of this source tree.
7+
8+ # pyre-strict
9+ import os
10+ import subprocess
11+ from typing import Optional
12+
13+ from .base_version_gen import BASE_VERSION
14+
15+
16+ def get_mercurial_hash () -> Optional [str ]:
17+ """Get the current mercurial revision hash."""
18+ try :
19+ # Try to get the mercurial hash from the current working directory
20+ result = subprocess .run (
21+ ["hg" , "id" , "-i" ],
22+ capture_output = True ,
23+ text = True ,
24+ check = True ,
25+ cwd = os .path .dirname (__file__ ),
26+ )
27+ # Remove the '+' suffix that indicates uncommitted changes
28+ hg_hash = result .stdout .strip ().rstrip ("+" )
29+ return hg_hash
30+ except (subprocess .CalledProcessError , FileNotFoundError ):
31+ # If hg command fails or is not available, return None
32+ return None
33+
34+
35+ def get_fb_version () -> str :
36+ """
37+ Get the torchx version string.
38+
39+ Returns:
40+ Version string following semantic versioning specs
41+ """
42+ hg_hash = get_mercurial_hash ()
43+ if hg_hash :
44+ # Follow semantic versioning local version identifier format
45+ # https://packaging.python.org/en/latest/specifications/version-specifiers/#local-version-identifiers
46+ version = f"{ BASE_VERSION } +fb.{ hg_hash } "
47+ else :
48+ # Fallback if we can't get mercurial hash
49+ version = f"{ BASE_VERSION } +fb"
50+
51+ return version
You can’t perform that action at this time.
0 commit comments