示例#1
0
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion

### NAME
MODULE_NAME = 'depthai'

### VERSION
here = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(here, "generated", "version.py")
os.makedirs(os.path.join(here, "generated"), exist_ok=True)
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 = 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 = 'dev'
    try:
        commit_hash = (
            subprocess.check_output(
                ["git", "rev-parse", "HEAD"], stderr=subprocess.STDOUT
            )
            .splitlines()[0]
            .decode()
        )
    except subprocess.CalledProcessError as e:
        # cannot get commit hash, leave empty
示例#2
0
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