Skip to content

Commit 0c1a6f3

Browse files
committed
Adding version.py
1 parent 0854494 commit 0c1a6f3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
except ImportError:
66
from distutils.core import setup
77

8+
version = '0.2.0'
9+
810
setup(
911
name='lambda-cron',
10-
version='0.2.0',
12+
version=version,
1113
author='MediaMath',
1214
author_email='jbravo@mediamath.com',
1315
description='Serverless cron tool to run on AWS',
1416
keywords='cron lambda aws serverless mediamath',
1517
url='https://github.com/mediaMath/lambda-cron',
16-
download_url='https://github.com/mediamath/lambda-cron/archive/v0.2.0.tar.gz',
18+
download_url='https://github.com/mediamath/lambda-cron/archive/v{0}.tar.gz'.format(version),
1719
packages=[
1820
'lambda_cron', 'lambda_cron.aws', 'lambda_cron.aws.lib', 'lambda_cron.cli', 'lambda_cron.cli.command'
1921
],

version.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Source: https://github.com/Changaco/version.py
2+
3+
from os.path import dirname, isdir, join
4+
import re
5+
from subprocess import CalledProcessError, check_output
6+
7+
8+
PREFIX = ''
9+
10+
tag_re = re.compile(r'\btag: %s([0-9][^,]*)\b' % PREFIX)
11+
version_re = re.compile('^Version: (.+)$', re.M)
12+
13+
14+
def get_version():
15+
# Return the version if it has been injected into the file by git-archive
16+
version = tag_re.search('$Format:%D$')
17+
if version:
18+
return version.group(1)
19+
20+
d = dirname(__file__)
21+
22+
if isdir(join(d, '.git')):
23+
# Get the version using "git describe".
24+
cmd = 'git describe --tags --match %s[0-9]* --dirty' % PREFIX
25+
try:
26+
version = check_output(cmd.split()).decode().strip()[len(PREFIX):]
27+
except CalledProcessError:
28+
raise RuntimeError('Unable to get version number from git tags')
29+
30+
# PEP 440 compatibility
31+
if '-' in version:
32+
if version.endswith('-dirty'):
33+
raise RuntimeError('The working tree is dirty')
34+
version = '.post'.join(version.split('-')[:2])
35+
36+
else:
37+
# Extract the version from the PKG-INFO file.
38+
with open(join(d, 'PKG-INFO')) as f:
39+
version = version_re.search(f.read()).group(1)
40+
41+
return version
42+
43+
44+
if __name__ == '__main__':
45+
print(get_version())

0 commit comments

Comments
 (0)