-
Notifications
You must be signed in to change notification settings - Fork 5
/
wscript
121 lines (83 loc) · 3.38 KB
/
wscript
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
#! /usr/bin/env python
# encoding: utf-8
import os
import waflib
from waflib.Build import BuildContext
top = "."
VERSION = "2.3.0"
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(
"--pytest_basetemp",
default="pytest_temp",
help="Set the prefix folder where pytest executes the tests",
)
def configure(conf):
pass
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() as venv:
venv.run(cmd="python -m pip install wheel")
venv.run(cmd="python setup.py bdist_wheel --universal", cwd=bld.path)
# Run the unit-tests
if bld.options.run_tests:
_pytest(bld=bld, venv=venv)
# 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", "versjon.egg-info")
if os.path.isdir(egg_info):
waflib.extras.wurf.directory.remove_directory(path=egg_info)
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]
waflib.Logs.info("Wheel %s", wheel)
return wheel
def upload(bld):
"""Upload the built wheel to PyPI (the Python Package Index)"""
with bld.create_virtualenv() as venv:
venv.run("python -m pip install twine")
wheel = _find_wheel(ctx=bld)
venv.run(f"python -m twine upload {wheel}")
def _pytest(bld, venv):
# To update the requirements.txt just delete it - a fresh one
# will be generated from test/requirements.in
if not os.path.isfile("test/requirements.txt"):
venv.run("python -m pip install pip-tools")
venv.run(
"pip-compile setup.py test/requirements.in "
"--output-file test/requirements.txt"
)
venv.run("python -m pip install -r test/requirements.txt")
# Install our python wheel in the virtualenv for testing
wheel = _find_wheel(ctx=bld)
venv.run(f"python -m pip install {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
venv.run(f"python -B -m pytest {test_filter} --basetemp {basetemp}")
# Check the package
venv.run(f"twine check {wheel}")