From fc28f58c77080e94215719ba4f2aa3f3162c8300 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 17 Oct 2019 20:48:52 +0200 Subject: [PATCH 1/2] Generate version.py if it does not exist --- setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae651125..ee823df9 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,14 @@ from distutils.core import setup -import cdist import os import re +import subprocess + + +if not os.path.exists(os.path.join('cdist', 'version.py')): + subprocess.run([os.path.join('bin', 'build-helper'), 'version', ]) + + +import cdist def data_finder(data_dir): From 2d0af7b7ccc34d450a1b0cfb6532f6d2439ee7a4 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Oct 2019 10:24:11 +0200 Subject: [PATCH 2/2] Generate verions.py only if git cloned repo --- setup.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ee823df9..2bb1e16d 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,24 @@ from distutils.core import setup +from distutils.errors import DistutilsError import os import re import subprocess -if not os.path.exists(os.path.join('cdist', 'version.py')): - subprocess.run([os.path.join('bin', 'build-helper'), 'version', ]) +# We have it only if it is a git cloned repo. +build_helper = os.path.join('bin', 'build-helper') +# Version file path. +version_file = os.path.join('cdist', 'version.py') +# If we have build-helper we could be a git repo. +if os.path.exists(build_helper): + # Try to generate version.py. + rv = subprocess.run([build_helper, 'version', ]) + if rv.returncode != 0: + raise DistutilsError("Failed to generate {}".format(version_file)) +else: + # Otherwise, version.py should be present. + if not os.path.exists(version_file): + raise DistutilsError("Missing version file {}".format(version_file)) import cdist