Make handling of setuptools-scm in setup more robust

Fixes #181
openapi3
Cristi Vîjdea 2018-08-07 17:19:58 +03:00
parent 8de704d7ae
commit e80101d98c
1 changed files with 58 additions and 56 deletions

View File

@ -19,26 +19,8 @@ requirements_setup = read_req('setup.txt')
requirements_validation = read_req('validation.txt')
try:
# this is a workaround for being able to install the package from source without working from a git checkout
# it is needed for building succesfully on Heroku
from setuptools_scm import get_version
except ImportError:
get_version = None
try:
version = get_version()
version_kwargs = {'use_scm_version': True}
except Exception:
if any(any(dist in arg for dist in ['sdist', 'bdist']) for arg in sys.argv):
raise
import time
timestamp_ms = int(time.time() * 1000)
timestamp_str = hex(timestamp_ms)[2:].zfill(16)
version_kwargs = {'version': '0.0.0rc0+dummy.' + timestamp_str}
setup(
def drf_yasg_setup(**kwargs):
setup(
name='drf-yasg',
packages=find_packages('src'),
package_dir={'': 'src'},
@ -78,5 +60,25 @@ setup(
'Topic :: Documentation',
'Topic :: Software Development :: Code Generators',
],
**version_kwargs
)
**kwargs
)
try:
drf_yasg_setup(use_scm_version=True)
except LookupError as e:
if os.getenv('CI', 'false') == 'true' or os.getenv('TRAVIS', 'false') == 'true':
raise
if 'setuptools-scm' in str(e):
import time
timestamp_ms = int(time.time() * 1000)
timestamp_str = hex(timestamp_ms)[2:].zfill(16)
dummy_version = '0.0.0rc0+noscm' + timestamp_str
drf_yasg_setup(version=dummy_version)
print(str(e), file=sys.stderr)
print("failed to detect version, build was done using dummy version " + dummy_version, file=sys.stderr)
else:
raise