Skip to content

Commit 1317e20

Browse files
committed
more version info #14228
1 parent 1b343c6 commit 1317e20

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ install(DIRECTORY tools/ DESTINATION ${DATA_PATH}tools
679679
PATTERN "*.pyc" EXCLUDE
680680
PATTERN "*.egg-info" EXCLUDE
681681
PATTERN ".git" EXCLUDE)
682+
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/build_config/version.py --sumolib \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${DATA_PATH}tools/sumolib/version.py)")
682683
if (DATA_PATH)
683684
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../bin \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${DATA_PATH}bin)")
684685
endif ()
@@ -914,6 +915,7 @@ if (GIT_FOUND)
914915
COMMAND rm -r sumo-${PACKAGE_VERSION}/tests
915916
COMMAND cp -a docs/tutorial docs/examples sumo-${PACKAGE_VERSION}/docs
916917
COMMAND find tools/contributed/saga/ tools/contributed/traci4matlab -type f | grep -v .git | xargs cp --parents --target-dir sumo-${PACKAGE_VERSION}
918+
COMMAND ${PYTHON_EXECUTABLE} tools/build_config/version.py --sumolib sumo-${PACKAGE_VERSION}/tools/sumolib/version.py
917919
COMMAND mkdir sumo-${PACKAGE_VERSION}/include
918920
COMMAND cp ${CMAKE_BINARY_DIR}/src/version.h sumo-${PACKAGE_VERSION}/include
919921
COMMAND zip -rq sumo-src-${PACKAGE_VERSION}.zip sumo-${PACKAGE_VERSION}

tools/build_config/version.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def create_version_file(versionFile, revision):
5959
print('#define VERSION_STRING "%s"' % revision, file=f)
6060

6161

62+
def filter_sumolib(version_py):
63+
with open(version_py) as inf:
64+
inp = inf.read()
65+
with open(version_py, "w") as outf:
66+
outf.write(inp.replace('0.0.0', get_pep440_version()))
67+
68+
6269
def filter_setup_py(in_file, out_file):
6370
with open(in_file) as inf, open(out_file, "w") as outf:
6471
for line in inf:
@@ -72,7 +79,10 @@ def filter_setup_py(in_file, out_file):
7279

7380
def main():
7481
if len(sys.argv) > 2:
75-
filter_setup_py(sys.argv[1], sys.argv[2])
82+
if sys.argv[1] == "--sumolib":
83+
filter_sumolib(sys.argv[2])
84+
else:
85+
filter_setup_py(sys.argv[1], sys.argv[2])
7686
return
7787
# determine output file
7888
if len(sys.argv) > 1:

tools/sumolib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# the visualization submodule is not imported to avoid an explicit matplotlib dependency
2929
from .miscutils import openz
3030
from .options import pullOptions, ArgumentParser
31+
from .version import _version as __version__
3132
from .xml import writeHeader as writeXMLHeader # noqa
3233

3334

tools/sumolib/version.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
import subprocess
2626
from os.path import dirname, exists, join
2727

28+
try:
29+
# this tries to determine the version number of an installed wheel
30+
import importlib.metadata # noqa
31+
_version = importlib.metadata.version("sumolib")
32+
except ImportError:
33+
# this is the fallback version, it gets replaced with the current version on "make install" or "make dist"
34+
_version = "0.0.0"
35+
2836
GITDIR = join(dirname(__file__), '..', '..', '.git')
2937

3038

@@ -48,7 +56,7 @@ def fromVersionHeader():
4856
version = config.find("VERSION_STRING") + 16
4957
if version > 16:
5058
return "v" + config[version:config.find('"\n', version)] + "-" + (10 * "0")
51-
raise EnvironmentError("Could not determine version.")
59+
return "v" + _version
5260

5361

5462
def gitDescribe(commit="HEAD", gitDir=GITDIR, padZero=True):

0 commit comments

Comments
 (0)