-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
156 lines (132 loc) · 4.66 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Copyright (C) 2023 Adobe
"""
from __future__ import print_function
import importlib.machinery
import os
import subprocess
import sys
import types
from setuptools import setup, find_packages
BASE_VERSION = "3.13"
SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
BUILDRUNNER_DIR = os.path.join(SOURCE_DIR, "buildrunner")
VERSION_FILE = os.path.join(BUILDRUNNER_DIR, "version.py")
THIS_DIR = os.path.dirname(__file__)
def read_requirements(filename):
"""
:param filename:
"""
requires = []
dep_links = []
try:
with open(os.path.join(THIS_DIR, filename)) as robj:
lnr = 0
for line in robj.readlines():
lnr += 1
_line = line.strip()
if not _line:
continue
if _line.startswith("#"):
continue
if _line.startswith("--extra-index-url"):
args = _line.split(None, 1)
if len(args) != 2:
print(
'ERROR: option "--extra-index-url" must have a URL argument: {}:{}'.format(
filename, lnr
),
file=sys.stderr,
)
continue
dep_links.append(args[1])
elif _line[0].isalpha():
# See note in Dockerfile for why this replacement is done
requires.append(_line.replace("jaraco-classes", "jaraco.classes"))
else:
print(
'ERROR: {}:{}:"{}" does not appear to be a requirement'.format(
filename, lnr, _line
),
file=sys.stderr,
)
except IOError as err:
sys.stderr.write('Failure reading "{0}": {1}\n'.format(filename, err))
sys.exit(err.errno)
return requires, dep_links
REQUIRES, DEP_LINKS = read_requirements("requirements.txt")
requirements, dependency_links = read_requirements("test_requirements.txt")
TEST_REQUIRES = requirements
DEP_LINKS.extend(dependency_links)
def get_version():
"""
Call out to the git command line to get the current commit "number".
"""
if os.path.exists(VERSION_FILE):
# Read version from file
loader = importlib.machinery.SourceFileLoader(
"buildrunner_version", VERSION_FILE
)
version_mod = types.ModuleType(loader.name)
loader.exec_module(version_mod)
existing_version = version_mod.__version__ # pylint: disable=no-member
return existing_version
# Generate the version from the base version and the git commit number, then store it in the file
try:
cmd = subprocess.Popen(
args=[
"git",
"rev-list",
"--count",
"HEAD",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf8",
)
stdout = cmd.communicate()[0]
output = stdout.strip()
if cmd.returncode == 0:
new_version = "{0}.{1}".format(BASE_VERSION, output)
# write the version file
if os.path.exists(BUILDRUNNER_DIR):
with open(VERSION_FILE, "w", encoding="utf8") as _fobj:
_fobj.write("__version__ = '%s'\n" % new_version)
return new_version
except Exception as exc: # pylint: disable=broad-except
print(f"Could not generate version from git commits: {exc}")
# If all else fails, use development version
return f"{BASE_VERSION}.DEVELOPMENT"
with open(os.path.join(os.path.dirname(__file__), "README.rst")) as fobj:
long_description = fobj.read().strip()
setup(
name="buildrunner",
version=get_version(),
author="Adobe",
author_email="[email protected]",
license="MIT",
url="https://github.com/adobe/buildrunner",
description="Docker-based build tool",
long_description=long_description,
long_description_content_type="text/x-rst",
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
scripts=[
"bin/buildrunner",
"bin/buildrunner-cleanup",
],
package_data={
"buildrunner": ["SourceDockerfile"],
"buildrunner.sshagent": [
"SSHAgentProxyImage/Dockerfile",
"SSHAgentProxyImage/run.sh",
"SSHAgentProxyImage/login.sh",
],
},
install_requires=REQUIRES,
tests_require=TEST_REQUIRES,
dependency_links=DEP_LINKS,
test_suite="tests",
)
# Local Variables:
# fill-column: 100
# End: