Skip to content

Commit 830cc92

Browse files
committed
#465 Use minimal version from git or from default
* do not use setuptools_scm * collect git describe and fallback to default version * get version as installed in scancode or fallback to default too. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 410d3ab commit 830cc92

6 files changed

Lines changed: 60 additions & 42 deletions

File tree

etc/conf/base.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ wheel
55
pip
66
wincertstore
77
six
8-
setuptools-scm
98

109
# Self
1110
-e .

setup.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,59 @@
1616
from setuptools import setup
1717

1818

19+
version = '2.0.0rc3'
20+
21+
22+
def get_version(default=version, template='{tag}.{distance}+{commit}{dirty}'):
23+
"""
24+
Return a version collected from git if possible or fall back to an hard-coded
25+
version otherwise.
26+
"""
27+
try:
28+
tag, distance, commit, dirty = get_git_version()
29+
if not distance and not dirty:
30+
# we are from a clean Git tag: use tag
31+
return tag
32+
33+
distance = 'dev{}'.format(distance)
34+
if dirty:
35+
time_stamp = get_time_stamp()
36+
dirty = '.dirty.' + get_time_stamp()
37+
else:
38+
dirty = ''
39+
40+
return template.format(**locals())
41+
except:
42+
# no git data: use default version
43+
return default
44+
45+
46+
def get_time_stamp():
47+
"""
48+
Return a numeric UTC time stamp without microseconds.
49+
"""
50+
from datetime import datetime
51+
return (datetime.isoformat(datetime.utcnow()).split('.')[0]
52+
.replace('T', '').replace(':', '').replace('-', ''))
53+
54+
55+
def get_git_version():
56+
"""
57+
Return version parts from Git or raise an exception.
58+
"""
59+
from subprocess import check_output, STDOUT
60+
# this may fail with exceptions
61+
cmd = 'git', 'describe', '--tags', '--long', '--dirty',
62+
version = check_output(cmd, stderr=STDOUT).strip()
63+
dirty = version.endswith('-dirty')
64+
tag, distance, commit = version.split('-')[:3]
65+
# lower tag and strip V prefix in tags
66+
tag = tag.lower().lstrip('v ').strip()
67+
# strip leading g from git describe commit
68+
commit = commit.lstrip('g').strip()
69+
return tag, int(distance), commit, dirty
70+
71+
1972
def read(*names, **kwargs):
2073
return io.open(
2174
join(dirname(__file__), *names),
@@ -28,11 +81,10 @@ def read(*names, **kwargs):
2881
re.sub(':obj:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst'))
2982
)
3083

84+
3185
setup(
3286
name='scancode-toolkit',
33-
version='2.0.0rc3',
34-
use_scm_version=True,
35-
setup_requires=['setuptools_scm'],
87+
version=get_version(),
3688
license='Apache-2.0 with ScanCode acknowledgment and CC0-1.0 and others',
3789
description='ScanCode is a tool to scan code for license, copyright and other interesting facts.',
3890
long_description=long_description,

src/scancode/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
fileutils.create_dir(scans_cache_dir)
4646

4747

48-
__version__ = '2.0.0rc3'
49-
48+
from pkg_resources import get_distribution, DistributionNotFound
5049
try:
51-
from setuptools_scm import get_version
52-
__version__ = get_version(root=root_dir, relative_to=__file__)
53-
except:
54-
pass
55-
50+
__version__ = get_distribution('scancode-toolkit').version
51+
except DistributionNotFound:
52+
# package is not installed ??
53+
__version__ = '2.0.0rc3'
-468 KB
Binary file not shown.

thirdparty/base/setuptools_scm.ABOUT

Lines changed: 0 additions & 12 deletions
This file was deleted.

thirdparty/base/setuptools_scm.LICENSE

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)