summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlan Rominger <arominge@redhat.com>2023-05-10 20:20:56 +0200
committerGitHub <noreply@github.com>2023-05-10 20:20:56 +0200
commit85e7189ee369c9b08e5301180a3c86fe31029bdb (patch)
treebc11e27de51dba0ad20f12e11b8d7bc4bdb27c3e /tools
parentFix 400 error from job labels sublist (#13972) (diff)
downloadawx-85e7189ee369c9b08e5301180a3c86fe31029bdb.tar.xz
awx-85e7189ee369c9b08e5301180a3c86fe31029bdb.zip
Add error handling to scm_version.py script (#13521)
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
Diffstat (limited to 'tools')
-rw-r--r--tools/scripts/scm_version.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/tools/scripts/scm_version.py b/tools/scripts/scm_version.py
index 8bff3b4599..b4fa6a6966 100644
--- a/tools/scripts/scm_version.py
+++ b/tools/scripts/scm_version.py
@@ -1,7 +1,6 @@
import os
import sys
import subprocess
-import traceback
try:
from setuptools_scm import get_version
@@ -9,8 +8,13 @@ except ModuleNotFoundError:
sys.stderr.write("Unable to import setuptools-scm, attempting to install now...\n")
os.environ['PIP_DISABLE_PIP_VERSION_CHECK'] = '1'
- subprocess.check_output([sys.executable, '-m', 'ensurepip'])
- subprocess.check_output([sys.executable, '-m', 'pip', 'install', 'setuptools-scm'])
+ 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