-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
79 lines (67 loc) · 2.59 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python2.7
from setuptools import setup
from pip.req import parse_requirements
from pip.download import PipSession
import os
import sys
import re
import subprocess
install_reqs = parse_requirements('requirements.txt',
session=PipSession())
packages = []
for root, dirs, files in os.walk('mezzapp'):
if '__init__.py' in files:
packages.append(re.sub('%[%A-z0-9_]+', '', root.replace('/', '.')))
is_build = len(sys.argv) > 1 and sys.argv[1] == 'sdist'
def get_version():
# Skip VERSION.txt if building a package.
if not is_build and os.path.exists("VERSION.txt"):
with open("VERSION.txt") as ver_file:
return ver_file.read()
else:
# Build version from latest tag.
raw_git_branch = os.environ.get('GIT_BRANCH', 'localbuild')
branch_match = re.match('origin\/pull\/(\d+)/(.+)', raw_git_branch)
if branch_match:
gitbranch = "pull{}{}".format(branch_match.group(1),
branch_match.group(2))
else:
gitbranch = os.path.basename(raw_git_branch)
gitcommit = os.environ.get('GIT_COMMIT')
if not gitcommit:
gitcommit = subprocess.check_output(
"git rev-parse HEAD", shell=True)
gitcommit.rstrip()
gitdescribe = subprocess.check_output(
"git describe --tags", shell=True)
gitdescribe.rstrip()
buildnumber = os.environ.get('BUILD_NUMBER', '0')
tagsearch = re.search('(.*)-(\d*)-(.*)', gitdescribe)
if tagsearch:
return "{}-c{}-build{}-{}-{}".format(
tagsearch.group(1), tagsearch.group(2), buildnumber,
gitbranch, gitcommit[0:8])
else:
return "{}-build{}-{}-{}".format(
gitdescribe, buildnumber, gitbranch, gitcommit[0:8])
version = get_version()
# Write out VERSION.txt if building a package.
if is_build:
with open("VERSION.txt", "w") as ver_txt:
print "Saving version: %s" % version
ver_txt.write(version)
job_url = os.environ.get("JOB_URL")
build_number = os.environ.get("BUILD_NUMBER")
if job_url and build_number:
url = "{}{}/".format(job_url, build_number)
else:
url = "https://github.com/stormsherpa/openwest2015-mezzapp"
setup(name="Mezzapp",
version=version,
url=url,
description="App for installing mezzanine site",
author="Shaun Kruger",
author_email="[email protected]",
include_package_data=True,
packages=packages,
install_requires=[str(ir.req) for ir in install_reqs])