Skip to content

Commit 8d90a91

Browse files
committed
Updated versioning and CI
1 parent c9187c0 commit 8d90a91

File tree

7 files changed

+76
-13
lines changed

7 files changed

+76
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.vs/
55
build*/*
66
# Auto-generated
7-
shared/version.hpp
7+
generated/*
88

99
#pybind11
1010
pybind11-2.5.0/

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ target_link_libraries(${TARGET_NAME}
5151
pybind11::pybind11
5252
depthai-core
5353
)
54+
55+
# Add bindings revision
56+
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_BINDINGS_REVISION="${PROJECT_VERSION}")
57+
# Add commit hash
58+
if(DEPTHAI_PYTHON_COMMIT_HASH)
59+
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_COMMIT_HASH="${DEPTHAI_PYTHON_COMMIT_HASH}")
60+
endif()
61+

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
include README.md LICENSE
2+
include find_version.py
3+
graft generated
24
global-include CMakeLists.txt *.cmake
35
recursive-include src *
46
recursive-include pybind11/include *.h

ci/upload-artifactory.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

3+
curl -fL https://getcli.jfrog.io | sh
4+
35
cd wheelhouse/audited/ || exit 1
46
export PATH_PREFIX=luxonis-python-snapshot-local/depthai
57

6-
curl -fL https://getcli.jfrog.io | sh
7-
./jfrog rt config --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --password=$ARTIFACTORY_PASS
8-
./jfrog rt u "*" "$PATH_PREFIX/"
8+
../../jfrog rt config --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --password=$ARTIFACTORY_PASS
9+
../../jfrog rt u "*" "$PATH_PREFIX/"

setup.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,50 @@
99
from setuptools.command.build_ext import build_ext
1010
from distutils.version import LooseVersion
1111

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+
1256
class CMakeExtension(Extension):
1357
def __init__(self, name, sourcedir=''):
1458
Extension.__init__(self, name, sources=[])
@@ -42,6 +86,9 @@ def build_extension(self, ext):
4286
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
4387
'-DPYTHON_EXECUTABLE=' + sys.executable]
4488

89+
if buildCommitHash != None :
90+
cmake_args += ['-DDEPTHAI_PYTHON_COMMIT_HASH=' + buildCommitHash]
91+
4592
cfg = 'Debug' if self.debug else 'Release'
4693
build_args = ['--config', cfg]
4794

@@ -98,14 +145,10 @@ def build_extension(self, ext):
98145
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
99146

100147

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']
105148

106149
setup(
107150
name='depthai',
108-
version=final_version,
151+
version=__version__,
109152
author='Martin Peterlin',
110153
author_email='martin@luxonis.com',
111154
description='DepthAI Python Library',

src/py_bindings.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
// depthai-core
1515
#include "depthai/device.hpp"
16+
#include "depthai/build/version.hpp"
1617

1718
// project
1819
#include "host_data_packet_bindings.hpp"
@@ -33,11 +34,19 @@ PYBIND11_MODULE(depthai,m)
3334

3435
// TODO: test ownership in python
3536

36-
// TODO
3737
//std::string _version = c_depthai_version;
38-
m.attr("__version__") = "0.0.1";
38+
std::string version = std::string(dai::build::VERSION) + "." + std::string(DEPTHAI_PYTHON_BINDINGS_REVISION);
39+
40+
#ifdef DEPTHAI_PYTHON_COMMIT_HASH
41+
version += "+" + std::string(DEPTHAI_PYTHON_COMMIT_HASH);
42+
#endif
43+
44+
m.attr("__version__") = version;
45+
46+
47+
// TODO
3948
//std::string _dev_version = c_depthai_dev_version;
40-
m.attr("__dev_version__") = "badf00d";
49+
//m.attr("__dev_version__") = "badf00d";
4150

4251

4352
// for te in nnet_packet.ENTRIES()

0 commit comments

Comments
 (0)