Skip to content

Commit 21037f4

Browse files
committed
Unified version information and added requirements installation
1 parent 1135dce commit 21037f4

File tree

6 files changed

+81
-36
lines changed

6 files changed

+81
-36
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,24 @@ target_link_libraries(${TARGET_NAME}
119119
hedley
120120
)
121121

122-
# Version consists of: (depthai-core).(bindings revision)[+bindings hash]
123-
set(DEPTHAI_PYTHON_VERSION "${DEPTHAI_VERSION}.${PROJECT_VERSION}")
124-
125122
# Add default commit hash ('dev') if not build by CI
126123
if(NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
127-
set(DEPTHAI_PYTHON_COMMIT_HASH dev)
124+
set(DEPTHAI_PYTHON_COMMIT_HASH "dev")
128125
endif()
129126

130-
# Append build info to version
127+
# Get version to use
128+
set(version_command "import find_version as v; print(v.get_package_version())")
131129
if(DEPTHAI_PYTHON_COMMIT_HASH)
132-
set(DEPTHAI_PYTHON_VERSION "${DEPTHAI_PYTHON_VERSION}+${DEPTHAI_PYTHON_COMMIT_HASH}")
130+
set(version_command "import find_version as v; print(v.get_package_dev_version('${DEPTHAI_PYTHON_COMMIT_HASH}'))")
133131
endif()
132+
execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "${version_command}"
133+
OUTPUT_VARIABLE DEPTHAI_PYTHON_VERSION
134+
OUTPUT_STRIP_TRAILING_WHITESPACE
135+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
136+
)
134137

135138
# Add version definition
136139
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_VERSION="${DEPTHAI_PYTHON_VERSION}")
137-
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_BINDINGS_REVISION="${PROJECT_VERSION}")
138-
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_VERSION="${DEPTHAI_VERSION}")
139-
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_COMMIT_HASH="${DEPTHAI_PYTHON_COMMIT_HASH}")
140140

141141
# Set compiler features (c++14), and disables extensions
142142
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14)

examples/install_requirements.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
import sys, os, subprocess
3+
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4+
os.chdir(parent_dir)
5+
sys.path.insert(1, parent_dir)
6+
import find_version
7+
8+
# 3rdparty dependencies to install
9+
DEPENDENCIES = ['opencv-python']
10+
11+
# Constants
12+
ARTIFACTORY_URL = 'https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local'
13+
14+
# Check if in virtual environment
15+
in_venv = getattr(sys, "real_prefix", getattr(sys, "base_prefix", sys.prefix)) != sys.prefix
16+
pip_call = [sys.executable, "-m", "pip"]
17+
pip_install = pip_call + ["install"]
18+
if not in_venv:
19+
pip_install.append("--user")
20+
21+
# Update pip
22+
subprocess.check_call([*pip_install, "pip", "-U"])
23+
# Install opencv-python
24+
subprocess.check_call([*pip_install, *DEPENDENCIES])
25+
26+
# Check if in git context and retrieve some information
27+
git_context = True
28+
git_commit = ""
29+
git_branch = ""
30+
try:
31+
git_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('UTF-8').strip()
32+
git_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('UTF-8').strip()
33+
except (OSError, CalledProcessError) as e:
34+
git_context = False
35+
36+
# Install depthai depending on context
37+
if not git_context or git_branch == 'main':
38+
# Install latest pypi depthai release
39+
subprocess.check_call([*pip_install, '-U', '--force-reinstall', 'depthai'])
40+
elif git_context:
41+
# Get package version if in git context
42+
final_version = find_version.get_package_dev_version(git_commit)
43+
# Install latest built wheels from artifactory (0.0.0.0+[hash] or [version]+[hash])
44+
commands = [[*pip_install, "--extra-index-url", ARTIFACTORY_URL, "depthai=="+final_version],
45+
[*pip_install, "."]]
46+
success = False
47+
for command in commands:
48+
try:
49+
success = subprocess.call(command) == 0
50+
except (OSError, CalledProcessError) as e:
51+
success = False
52+
if success:
53+
break
54+
55+
# If all commands failed
56+
if not success:
57+
print("Couldn't install dependencies as wheels and trying to compile from sources failed")
58+
print("Check https://github.com/luxonis/depthai-python#dependencies on retrieving dependencies for compiling from sources")

examples/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/requirements_develop.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

find_version.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import os
33
import re
44

5-
version_depthai_core_path = "depthai-core/CMakeLists.txt"
6-
version_depthai_python_path = "CMakeLists.txt"
5+
6+
project_root = os.path.dirname(__file__)
7+
version_depthai_core_path = project_root + "/" + "depthai-core/CMakeLists.txt"
8+
version_depthai_python_path = project_root + "/" + "CMakeLists.txt"
79

810
cmake_lists_txt_version_pattern = r'project[\s]*\([^Vv]*version[\s]+((\"(?P<ver1>\S*)\"|(?P<ver2>\S*)\s))'
911

@@ -27,3 +29,7 @@ def get_package_version():
2729
package_version = version_core + '.' + version_revision
2830

2931
return package_version
32+
33+
34+
def get_package_dev_version(commit_hash):
35+
return get_package_version() + ".dev+" + commit_hash

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
if os.environ.get('CI') != None :
2020
### If CI build, respect 'BUILD_COMMIT_HASH' to determine final version if set
2121
final_version = find_version.get_package_version()
22-
if os.environ.get('BUILD_COMMIT_HASH') != None :
23-
final_version = final_version + '+' + os.environ['BUILD_COMMIT_HASH']
22+
if os.environ.get('BUILD_COMMIT_HASH') != None:
23+
final_version = find_version.get_package_dev_version(os.environ['BUILD_COMMIT_HASH'])
2424
with open(version_file, 'w') as vf :
2525
vf.write("__version__ = '" + final_version + "'")
2626
elif os.path.exists(".git"):
2727
### else if .git folder exists, create depthai with commit hash retrieved from git rev-parse HEAD
28-
commit_hash = ''
28+
commit_hash = 'dev'
2929
try:
3030
commit_hash = (
3131
subprocess.check_output(
@@ -36,8 +36,8 @@
3636
)
3737
except subprocess.CalledProcessError as e:
3838
# cannot get commit hash, leave empty
39-
commit_hash = ''
40-
final_version = find_version.get_package_version() + '+' + commit_hash
39+
commit_hash = 'dev'
40+
final_version = find_version.get_package_dev_version(commit_hash)
4141

4242
with open(version_file, 'w') as vf :
4343
vf.write("__version__ = '" + final_version + "'")
@@ -46,7 +46,7 @@
4646
# If not generated, generate from find_version
4747
if os.path.isfile(version_file) == False :
4848
# generate from find_version
49-
final_version = find_version.get_package_version()
49+
final_version = find_version.get_package_dev_version('dev')
5050
with open(version_file, 'w') as vf :
5151
vf.write("__version__ = '" + final_version + "'")
5252

0 commit comments

Comments
 (0)