2015-11-09 11:33:38 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2022-02-08 21:05:39 +08:00
|
|
|
|
2020-07-30 00:54:07 +08:00
|
|
|
VERSION_FILE = """
|
|
|
|
def get_version():
|
|
|
|
return "{version}"
|
2022-02-08 21:05:39 +08:00
|
|
|
|
|
|
|
def get_rev():
|
|
|
|
return "{rev}"
|
2020-07-30 00:54:07 +08:00
|
|
|
"""
|
2015-11-09 11:33:38 +08:00
|
|
|
|
2020-07-30 00:54:07 +08:00
|
|
|
def get_version():
|
2022-08-18 14:35:43 +08:00
|
|
|
return os.getenv("VERSIONEER_OVERRIDE", default="7.0")
|
2020-07-30 00:54:07 +08:00
|
|
|
|
2022-02-08 21:05:39 +08:00
|
|
|
def get_rev():
|
|
|
|
return os.getenv("VERSIONEER_REV", default="unknown")
|
|
|
|
|
|
|
|
def write_to_version_file(filename, version, rev):
|
2015-11-09 11:33:38 +08:00
|
|
|
os.unlink(filename)
|
|
|
|
with open(filename, "w") as f:
|
2022-02-08 21:05:39 +08:00
|
|
|
f.write(VERSION_FILE.format(version=version, rev=rev))
|
2015-11-09 11:33:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_cmdclass():
|
|
|
|
cmds = {}
|
|
|
|
|
2015-11-09 12:19:01 +08:00
|
|
|
# we override different "build_py" commands for both environments
|
|
|
|
if "setuptools" in sys.modules:
|
|
|
|
from setuptools.command.build_py import build_py as _build_py
|
|
|
|
else:
|
|
|
|
from distutils.command.build_py import build_py as _build_py
|
2015-11-09 11:33:38 +08:00
|
|
|
|
|
|
|
class cmd_build_py(_build_py):
|
|
|
|
def run(self):
|
2020-07-30 00:54:07 +08:00
|
|
|
version = get_version()
|
2022-02-08 21:05:39 +08:00
|
|
|
rev = get_rev()
|
2015-11-09 11:33:38 +08:00
|
|
|
_build_py.run(self)
|
2020-07-30 00:54:07 +08:00
|
|
|
target_versionfile = os.path.join(self.build_lib,
|
|
|
|
"artiq", "_version.py")
|
|
|
|
print("UPDATING %s" % target_versionfile)
|
2022-02-08 21:05:39 +08:00
|
|
|
write_to_version_file(target_versionfile, version, rev)
|
2015-11-09 11:33:38 +08:00
|
|
|
cmds["build_py"] = cmd_build_py
|
|
|
|
|
2017-06-05 13:27:26 +08:00
|
|
|
|
2015-11-09 11:33:38 +08:00
|
|
|
# we override different "sdist" commands for both environments
|
|
|
|
if "setuptools" in sys.modules:
|
|
|
|
from setuptools.command.sdist import sdist as _sdist
|
|
|
|
else:
|
|
|
|
from distutils.command.sdist import sdist as _sdist
|
|
|
|
|
|
|
|
class cmd_sdist(_sdist):
|
|
|
|
def run(self):
|
2020-07-30 00:54:07 +08:00
|
|
|
version = get_version()
|
|
|
|
self._versioneer_generated_version = version
|
2022-02-08 21:05:39 +08:00
|
|
|
self._versioneer_rev = get_rev()
|
2015-11-09 11:33:38 +08:00
|
|
|
# unless we update this, the command will keep using the old
|
|
|
|
# version
|
2020-07-30 00:54:07 +08:00
|
|
|
self.distribution.metadata.version = version
|
2015-11-09 11:33:38 +08:00
|
|
|
return _sdist.run(self)
|
|
|
|
|
|
|
|
def make_release_tree(self, base_dir, files):
|
|
|
|
_sdist.make_release_tree(self, base_dir, files)
|
2020-07-30 00:54:07 +08:00
|
|
|
target_versionfile = os.path.join(base_dir, "artiq", "_version.py")
|
2015-11-09 11:33:38 +08:00
|
|
|
print("UPDATING %s" % target_versionfile)
|
|
|
|
write_to_version_file(target_versionfile,
|
2022-02-08 21:05:39 +08:00
|
|
|
self._versioneer_generated_version,
|
|
|
|
self._versioneer_rev)
|
2015-11-09 11:33:38 +08:00
|
|
|
cmds["sdist"] = cmd_sdist
|
|
|
|
|
|
|
|
return cmds
|