-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwscript
More file actions
242 lines (177 loc) · 7.21 KB
/
wscript
File metadata and controls
242 lines (177 loc) · 7.21 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#! /usr/bin/env python
# encoding: utf-8
from waflib.Build import BuildContext
import os
import sys
import shutil
import hashlib
import subprocess
from waflib.Configure import conf
from waflib import Logs
import waflib
top = "."
VERSION = "9.1.2"
class UploadContext(BuildContext):
cmd = "upload"
fun = "upload"
def options(opt):
opt.add_option(
"--run_tests", default=False, action="store_true", help="Run all unit tests"
)
opt.add_option(
"--stepwise", default=False, action="store_true", help="Run until first failure"
)
opt.add_option(
"--pytest_basetemp",
default="pytest_temp",
help="Set the prefix folder where pytest executes the tests",
)
opt.add_option(
"--run_download_tests",
default=False,
action="store_true",
help="Run the unit tests that use network resources" " (downloading Doxygen",
)
opt.add_option(
"--run_ensure_doxygen",
default=False,
action="store_true",
help="Ensure that doxygen is available (will retrieve a fresh copy)",
)
opt.add_option(
"--test_filter",
default=None,
action="store",
help="Runs all tests that include the substring specified."
"Wildcards not allowed. (Used with --run_tests)",
)
def build(bld):
# Create a virtualenv in the source folder and build universal wheel
# Make sure the virtualenv Python module is in path
with bld.create_virtualenv(cwd=bld.path.abspath()) as venv:
venv.run("pip install wheel setuptools")
venv.run(cmd="python setup.py bdist_wheel --universal", cwd=bld.path)
# Delete the egg-info directory, do not understand why this is created
# when we build a wheel. But, it is - perhaps in the future there will
# be some way to disable its creation.
egg_info = os.path.join("src", "wurfapi.egg-info")
if os.path.isdir(egg_info):
waflib.extras.wurf.directory.remove_directory(path=egg_info)
# Run the unit-tests
if bld.options.run_tests:
_pytest(bld=bld)
def _find_wheel(ctx):
"""Find the .whl file in the dist folder."""
wheel = ctx.path.ant_glob("dist/*-" + VERSION + "-*.whl")
if not len(wheel) == 1:
ctx.fatal("No wheel found (or version mismatch)")
else:
wheel = wheel[0]
Logs.info("Wheel %s", wheel)
return wheel
def upload(bld):
"""Upload the built wheel to PyPI (the Python Package Index)"""
with bld.create_virtualenv(cwd=bld.path.abspath()) as venv:
venv.run("pip install twine")
wheel = _find_wheel(ctx=bld)
venv.run("python -m twine upload {}".format(wheel))
def _create_venv(ctx, location):
requirements_txt = os.path.join(location, "requirements.txt")
requirements_in = os.path.join(location, "requirements.in")
if not os.path.isfile(requirements_txt):
with ctx.create_virtualenv() as venv:
venv.run("python -m pip install pip-tools")
venv.run(
"pip-compile {} --output-file {}".format(
requirements_in, requirements_txt
)
)
# Hash the requirements.txt
sha1 = hashlib.sha1(
(open(requirements_txt, "r").read()).encode("utf-8")
).hexdigest()[:6]
# venv name
name = "venv-{}-{}".format(location, sha1)
if os.path.isdir(name):
# If directly already exits we should already have installed everything
pip_install = False
else:
pip_install = True
# Crate the venv
venv = ctx.create_virtualenv(name=name, overwrite=False)
venv.run("python -m pip install setuptools")
if pip_install:
venv.env["PIP_IGNORE_INSTALLED"] = ""
venv.run("python -m pip install -r {}".format(requirements_txt))
return venv
def _pytest(bld):
venv = _create_venv(ctx=bld, location="test")
# Install the pytest-testdirectory plugin in the virtualenv
wheel = _find_wheel(ctx=bld)
venv.run(cmd="python -m pip install --force-reinstall {}".format(wheel))
# We override the pytest temp folder with the basetemp option,
# so the test folders will be available at the specified location
# on all platforms. The default location is the "pytest" local folder.
basetemp = os.path.abspath(os.path.expanduser(bld.options.pytest_basetemp))
# We need to manually remove the previously created basetemp folder,
# because pytest uses os.listdir in the removal process, and that fails
# if there are any broken symlinks in that folder.
if os.path.exists(basetemp):
waflib.extras.wurf.directory.remove_directory(path=basetemp)
# Run all tests by just passing the test directory. Specific tests can
# be enabled by specifying the full path e.g.:
#
# 'test/test_run.py::test_create_context'
#
test_filter = "test"
# Main test command
command = f"python -B -m pytest {test_filter} --basetemp {basetemp}"
# Skip the tests that have the "download_test" marker
command += ' -m "not download_test and not ensure_doxygen"'
# Adds the test filter if specified
if bld.options.test_filter:
command += ' -k "{}"'.format(bld.options.test_filter)
# Adds the test filter if specified
if bld.options.stepwise:
command += " --stepwise"
# Make python not write any .pyc files. These may linger around
# in the file system and make some tests pass although their .py
# counter-part has been e.g. deleted
venv.run(cmd=command, cwd=bld.path)
if bld.options.run_download_tests:
# Main test command
command = "python -B -m pytest {} --basetemp {}".format(
testdir.abspath(), os.path.join(basetemp, "download_tests")
)
# Skip the tests that have the "download_test" marker
command += ' -m "download_test"'
# Make python not write any .pyc files. These may linger around
# in the file system and make some tests pass although their .py
# counter-part has been e.g. deleted
venv.run(cmd=command, cwd=bld.path)
if bld.options.run_ensure_doxygen:
# Main test command
command = "python -B -m pytest {} --basetemp {}".format(
testdir.abspath(), os.path.join(basetemp, "ensure_doxygen")
)
# Skip the tests that have the "download_test" marker
command += ' -m "ensure_doxygen"'
# Make python not write any .pyc files. These may linger around
# in the file system and make some tests pass although their .py
# counter-part has been e.g. deleted
venv.run(cmd=command, cwd=bld.path)
# Check readme
# https://stackoverflow.com/a/49107899/1717320
venv.run(cmd="python setup.py check -r -s", cwd=bld.path)
venv.run(cmd="pip install collective.checkdocs")
venv.run(cmd="python setup.py checkdocs", cwd=bld.path)
class ReleaseContext(BuildContext):
cmd = "prepare_release"
fun = "prepare_release"
def prepare_release(ctx):
"""Prepare a release."""
# Rewrite version
with ctx.rewrite_file(filename="src/wurfapi/wurfapi_directive.py") as f:
pattern = r'VERSION = "\d+\.\d+\.\d+"'
replacement = 'VERSION = "{}"'.format(VERSION)
f.regex_replace(pattern=pattern, replacement=replacement)