mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 15:02:07 -03:30
raise Exception in the case that return code is non-zero this approach has shown itself to be the most consistently reliable across multiple ecosystems
23 lines
921 B
Python
23 lines
921 B
Python
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
try:
|
|
from setuptools_scm import get_version
|
|
except ModuleNotFoundError:
|
|
sys.stderr.write("Unable to import setuptools-scm, attempting to install now...\n")
|
|
|
|
os.environ['PIP_DISABLE_PIP_VERSION_CHECK'] = '1'
|
|
COMMANDS = ([sys.executable, '-m', 'ensurepip'], [sys.executable, '-m', 'pip', 'install', 'setuptools-scm'])
|
|
for cmd in COMMANDS:
|
|
# capture_output because we only want to print version to stdout if successful
|
|
result = subprocess.run(cmd, capture_output=True)
|
|
if result.returncode:
|
|
# failed, we have no version, so print output so that users can debug
|
|
raise Exception(f'\nCommand `{" ".join(cmd)}` failed (rc={result.returncode}).\n\nstdout:\n{result.stdout}\n\nstderr:\n{result.stderr}')
|
|
|
|
from setuptools_scm import get_version
|
|
|
|
version = get_version(root='../..', relative_to=__file__)
|
|
print(version)
|