|
9 | 9 | from setuptools.command.build_ext import build_ext |
10 | 10 | from distutils.version import LooseVersion |
11 | 11 |
|
| 12 | + |
| 13 | +### VERSION |
| 14 | +here = os.path.abspath(os.path.dirname(__file__)) |
| 15 | +version_file = os.path.join(here, "generated", "version.py") |
| 16 | +if os.environ.get('CI') != None : |
| 17 | + ### If CI build, respect 'BUILD_COMMIT_HASH' to determine final version if set |
| 18 | + final_version = find_version.get_package_version() |
| 19 | + if os.environ.get('BUILD_COMMIT_HASH') != None : |
| 20 | + final_version = final_version + '+' + os.environ['BUILD_COMMIT_HASH'] |
| 21 | + with open(version_file, 'w') as vf : |
| 22 | + vf.write("__version__ = '" + final_version + "'") |
| 23 | +elif os.path.exists(".git"): |
| 24 | + ### else if .git folder exists, create depthai with commit hash retrieved from git rev-parse HEAD |
| 25 | + commit_hash = '' |
| 26 | + try: |
| 27 | + commit_hash = ( |
| 28 | + subprocess.check_output( |
| 29 | + ["git", "rev-parse", "HEAD"], stderr=subprocess.STDOUT |
| 30 | + ) |
| 31 | + .splitlines()[0] |
| 32 | + .decode() |
| 33 | + ) |
| 34 | + except subprocess.CalledProcessError as e: |
| 35 | + # cannot get commit hash, leave empty |
| 36 | + commit_hash = '' |
| 37 | + final_version = find_version.get_package_version() + '+' + commit_hash |
| 38 | + |
| 39 | + with open(version_file, 'w') as vf : |
| 40 | + vf.write("__version__ = '" + final_version + "'") |
| 41 | + |
| 42 | + |
| 43 | +# If not generated, generate from find_version |
| 44 | +if os.path.isfile(version_file) == False : |
| 45 | + # generate from find_version |
| 46 | + final_version = find_version.get_package_version() |
| 47 | + with open(version_file, 'w') as vf : |
| 48 | + vf.write("__version__ = '" + final_version + "'") |
| 49 | + |
| 50 | +### Get version from version.py (sdist will have this pregenerated) |
| 51 | +exec(open(version_file).read()) |
| 52 | +buildCommitHash = None |
| 53 | +if len(__version__.split("+")) > 1 : |
| 54 | + buildCommitHash = __version__.split("+")[1] |
| 55 | + |
12 | 56 | class CMakeExtension(Extension): |
13 | 57 | def __init__(self, name, sourcedir=''): |
14 | 58 | Extension.__init__(self, name, sources=[]) |
@@ -42,6 +86,9 @@ def build_extension(self, ext): |
42 | 86 | cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
43 | 87 | '-DPYTHON_EXECUTABLE=' + sys.executable] |
44 | 88 |
|
| 89 | + if buildCommitHash != None : |
| 90 | + cmake_args += ['-DDEPTHAI_PYTHON_COMMIT_HASH=' + buildCommitHash] |
| 91 | + |
45 | 92 | cfg = 'Debug' if self.debug else 'Release' |
46 | 93 | build_args = ['--config', cfg] |
47 | 94 |
|
@@ -98,14 +145,10 @@ def build_extension(self, ext): |
98 | 145 | subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) |
99 | 146 |
|
100 | 147 |
|
101 | | -### GENERATED VERSION - Do not modify |
102 | | -final_version = find_version.get_package_version() |
103 | | -if 'BUILD_COMMIT_HASH' in os.environ: |
104 | | - final_version = final_version + '+' + os.environ['BUILD_COMMIT_HASH'] |
105 | 148 |
|
106 | 149 | setup( |
107 | 150 | name='depthai', |
108 | | - version=final_version, |
| 151 | + version=__version__, |
109 | 152 | author='Martin Peterlin', |
110 | 153 | author_email='martin@luxonis.com', |
111 | 154 | description='DepthAI Python Library', |
|
0 commit comments