Skip to content

Commit

Permalink
Unified version information and added requirements installation
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Mar 19, 2021
1 parent 1135dce commit 21037f4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 36 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,24 @@ target_link_libraries(${TARGET_NAME}
hedley
)

# Version consists of: (depthai-core).(bindings revision)[+bindings hash]
set(DEPTHAI_PYTHON_VERSION "${DEPTHAI_VERSION}.${PROJECT_VERSION}")

# Add default commit hash ('dev') if not build by CI
if(NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
set(DEPTHAI_PYTHON_COMMIT_HASH dev)
set(DEPTHAI_PYTHON_COMMIT_HASH "dev")
endif()

# Append build info to version
# Get version to use
set(version_command "import find_version as v; print(v.get_package_version())")
if(DEPTHAI_PYTHON_COMMIT_HASH)
set(DEPTHAI_PYTHON_VERSION "${DEPTHAI_PYTHON_VERSION}+${DEPTHAI_PYTHON_COMMIT_HASH}")
set(version_command "import find_version as v; print(v.get_package_dev_version('${DEPTHAI_PYTHON_COMMIT_HASH}'))")
endif()
execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "${version_command}"
OUTPUT_VARIABLE DEPTHAI_PYTHON_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

# Add version definition
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_VERSION="${DEPTHAI_PYTHON_VERSION}")
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_BINDINGS_REVISION="${PROJECT_VERSION}")
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_VERSION="${DEPTHAI_VERSION}")
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_COMMIT_HASH="${DEPTHAI_PYTHON_COMMIT_HASH}")

# Set compiler features (c++14), and disables extensions
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14)
Expand Down
58 changes: 58 additions & 0 deletions examples/install_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
import sys, os, subprocess
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.chdir(parent_dir)
sys.path.insert(1, parent_dir)
import find_version

# 3rdparty dependencies to install
DEPENDENCIES = ['opencv-python']

# Constants
ARTIFACTORY_URL = 'https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local'

# Check if in virtual environment
in_venv = getattr(sys, "real_prefix", getattr(sys, "base_prefix", sys.prefix)) != sys.prefix
pip_call = [sys.executable, "-m", "pip"]
pip_install = pip_call + ["install"]
if not in_venv:
pip_install.append("--user")

# Update pip
subprocess.check_call([*pip_install, "pip", "-U"])
# Install opencv-python
subprocess.check_call([*pip_install, *DEPENDENCIES])

# Check if in git context and retrieve some information
git_context = True
git_commit = ""
git_branch = ""
try:
git_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('UTF-8').strip()
git_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('UTF-8').strip()
except (OSError, CalledProcessError) as e:
git_context = False

# Install depthai depending on context
if not git_context or git_branch == 'main':
# Install latest pypi depthai release
subprocess.check_call([*pip_install, '-U', '--force-reinstall', 'depthai'])
elif git_context:
# Get package version if in git context
final_version = find_version.get_package_dev_version(git_commit)
# Install latest built wheels from artifactory (0.0.0.0+[hash] or [version]+[hash])
commands = [[*pip_install, "--extra-index-url", ARTIFACTORY_URL, "depthai=="+final_version],
[*pip_install, "."]]
success = False
for command in commands:
try:
success = subprocess.call(command) == 0
except (OSError, CalledProcessError) as e:
success = False
if success:
break

# If all commands failed
if not success:
print("Couldn't install dependencies as wheels and trying to compile from sources failed")
print("Check https://github.com/luxonis/depthai-python#dependencies on retrieving dependencies for compiling from sources")
2 changes: 0 additions & 2 deletions examples/requirements.txt

This file was deleted.

17 changes: 0 additions & 17 deletions examples/requirements_develop.py

This file was deleted.

10 changes: 8 additions & 2 deletions find_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import os
import re

version_depthai_core_path = "depthai-core/CMakeLists.txt"
version_depthai_python_path = "CMakeLists.txt"

project_root = os.path.dirname(__file__)
version_depthai_core_path = project_root + "/" + "depthai-core/CMakeLists.txt"
version_depthai_python_path = project_root + "/" + "CMakeLists.txt"

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

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

return package_version


def get_package_dev_version(commit_hash):
return get_package_version() + ".dev+" + commit_hash
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
if os.environ.get('CI') != None :
### If CI build, respect 'BUILD_COMMIT_HASH' to determine final version if set
final_version = find_version.get_package_version()
if os.environ.get('BUILD_COMMIT_HASH') != None :
final_version = final_version + '+' + os.environ['BUILD_COMMIT_HASH']
if os.environ.get('BUILD_COMMIT_HASH') != None:
final_version = find_version.get_package_dev_version(os.environ['BUILD_COMMIT_HASH'])
with open(version_file, 'w') as vf :
vf.write("__version__ = '" + final_version + "'")
elif os.path.exists(".git"):
### else if .git folder exists, create depthai with commit hash retrieved from git rev-parse HEAD
commit_hash = ''
commit_hash = 'dev'
try:
commit_hash = (
subprocess.check_output(
Expand All @@ -36,8 +36,8 @@
)
except subprocess.CalledProcessError as e:
# cannot get commit hash, leave empty
commit_hash = ''
final_version = find_version.get_package_version() + '+' + commit_hash
commit_hash = 'dev'
final_version = find_version.get_package_dev_version(commit_hash)

with open(version_file, 'w') as vf :
vf.write("__version__ = '" + final_version + "'")
Expand All @@ -46,7 +46,7 @@
# If not generated, generate from find_version
if os.path.isfile(version_file) == False :
# generate from find_version
final_version = find_version.get_package_version()
final_version = find_version.get_package_dev_version('dev')
with open(version_file, 'w') as vf :
vf.write("__version__ = '" + final_version + "'")

Expand Down

0 comments on commit 21037f4

Please sign in to comment.