4
4
import os
5
5
import re
6
6
from pathlib import Path
7
- from typing import Any , Callable
7
+ from typing import Any , Callable , TypeVar
8
8
9
9
import nox
10
10
from nox .sessions import Session
13
13
ROOT = Path (__file__ ).parent
14
14
SRC = ROOT / "src"
15
15
POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
16
+ TRUE_VALUES = {"true" , "True" , "TRUE" , "1" }
16
17
17
18
18
- def apply_standard_pip_upgrades (
19
- function : Callable [[Session ], Any ]
20
- ) -> Callable [[Session ], Any ]:
21
- @functools .wraps (function )
22
- def wrapper (session : Session ) -> None :
23
- session .install ("--upgrade" , "pip" , "setuptools" , "wheel" )
24
- return function (session )
19
+ _Return = TypeVar ("_Return" )
25
20
26
- return wrapper
21
+
22
+ def do_first (
23
+ first_session_func : Callable [[Session ], None ]
24
+ ) -> Callable [[Callable [[Session ], _Return ]], Callable [[Session ], _Return ]]:
25
+ """Decorator for functions defining session actions that should happen first
26
+
27
+ >>> @do_first
28
+ >>> def setup(session):
29
+ >>> ... # do some setup
30
+ >>>
31
+ >>> @setup
32
+ >>> def the_actual_session(session):
33
+ >>> ... # so actual work
34
+
35
+ This makes it quick an easy to define common setup actions.
36
+ """
37
+
38
+ def setup (
39
+ second_session_func : Callable [[Session ], _Return ]
40
+ ) -> Callable [[Session ], _Return ]:
41
+ @functools .wraps (second_session_func )
42
+ def wrapper (session : Session ) -> Any :
43
+ first_session_func (session )
44
+ return second_session_func (session )
45
+
46
+ return wrapper
47
+
48
+ return setup
49
+
50
+
51
+ @do_first
52
+ def apply_standard_pip_upgrades (session : Session ) -> None :
53
+ session .install ("--upgrade" , "pip" )
54
+
55
+
56
+ @do_first
57
+ def install_latest_npm_in_ci (session : Session ) -> None :
58
+ if os .environ .get ("CI" ) in TRUE_VALUES :
59
+ session .run ("npm" , "install" , "-g" , "npm@latest" )
27
60
28
61
29
62
@nox .session (reuse_venv = True )
30
63
@apply_standard_pip_upgrades
31
64
def format (session : Session ) -> None :
65
+ """Auto format Python and Javascript code"""
32
66
# format Python
33
67
install_requirements_file (session , "check-style" )
34
68
session .run ("black" , "." )
@@ -58,6 +92,7 @@ def example(session: Session) -> None:
58
92
59
93
60
94
@nox .session (reuse_venv = True )
95
+ @install_latest_npm_in_ci
61
96
@apply_standard_pip_upgrades
62
97
def docs (session : Session ) -> None :
63
98
"""Build and display documentation in the browser (automatically reloads on change)"""
@@ -115,23 +150,31 @@ def docs_in_docker(session: Session) -> None:
115
150
def test (session : Session ) -> None :
116
151
"""Run the complete test suite"""
117
152
session .notify ("test_python" , posargs = session .posargs )
118
- session .notify ("test_types" )
119
- session .notify ("test_style" )
120
153
session .notify ("test_docs" )
121
154
session .notify ("test_javascript" )
122
155
123
156
124
157
@nox .session
125
- def test_short (session : Session ) -> None :
126
- """Run a shortened version of the test suite"""
127
- session .notify ("test_python" , posargs = session .posargs )
128
- session .notify ("test_docs" )
129
- session .notify ("test_javascript" )
158
+ def test_python (session : Session ) -> None :
159
+ """Run all Python checks"""
160
+ session .notify ("test_python_suite" , posargs = session .posargs )
161
+ session .notify ("test_python_types" )
162
+ session .notify ("test_python_style" )
163
+ session .notify ("test_python_build" )
164
+
165
+
166
+ @nox .session
167
+ def test_javascript (session : Session ) -> None :
168
+ """Run all Javascript checks"""
169
+ session .notify ("test_javascript_suite" )
170
+ session .notify ("test_javascript_build" )
171
+ session .notify ("test_javascript_style" )
130
172
131
173
132
174
@nox .session
175
+ @install_latest_npm_in_ci
133
176
@apply_standard_pip_upgrades
134
- def test_python (session : Session ) -> None :
177
+ def test_python_suite (session : Session ) -> None :
135
178
"""Run the Python-based test suite"""
136
179
session .env ["IDOM_DEBUG_MODE" ] = "1"
137
180
install_requirements_file (session , "test-env" )
@@ -149,8 +192,8 @@ def test_python(session: Session) -> None:
149
192
150
193
@nox .session
151
194
@apply_standard_pip_upgrades
152
- def test_types (session : Session ) -> None :
153
- """Perform a static type analysis of the codebase"""
195
+ def test_python_types (session : Session ) -> None :
196
+ """Perform a static type analysis of the Python codebase"""
154
197
install_requirements_file (session , "check-types" )
155
198
install_requirements_file (session , "pkg-deps" )
156
199
install_requirements_file (session , "pkg-extras" )
@@ -159,8 +202,8 @@ def test_types(session: Session) -> None:
159
202
160
203
@nox .session
161
204
@apply_standard_pip_upgrades
162
- def test_style (session : Session ) -> None :
163
- """Check that style guidelines are being followed"""
205
+ def test_python_style (session : Session ) -> None :
206
+ """Check that Python style guidelines are being followed"""
164
207
install_requirements_file (session , "check-style" )
165
208
session .run ("flake8" , "src/idom" , "tests" , "docs" )
166
209
black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist"
@@ -176,6 +219,15 @@ def test_style(session: Session) -> None:
176
219
177
220
@nox .session
178
221
@apply_standard_pip_upgrades
222
+ def test_python_build (session : Session ) -> None :
223
+ """Test whether the Python package can be build for distribution"""
224
+ install_requirements_file (session , "build-pkg" )
225
+ session .run ("python" , "setup.py" , "bdist_wheel" , "sdist" )
226
+
227
+
228
+ @nox .session
229
+ @install_latest_npm_in_ci
230
+ @apply_standard_pip_upgrades
179
231
def test_docs (session : Session ) -> None :
180
232
"""Verify that the docs build and that doctests pass"""
181
233
install_requirements_file (session , "build-docs" )
@@ -192,19 +244,47 @@ def test_docs(session: Session) -> None:
192
244
"docs/build" ,
193
245
)
194
246
session .run ("sphinx-build" , "-b" , "doctest" , "docs/source" , "docs/build" )
247
+ # ensure docker image build works too
248
+ session .run ("docker" , "build" , "." , "--file" , "docs/Dockerfile" , external = True )
195
249
196
250
197
- @nox . session
198
- def test_javascript ( session : Session ) -> None :
199
- """Run the Javascript-based test suite and ensure it bundles succesfully"""
251
+ @do_first
252
+ @ install_latest_npm_in_ci
253
+ def setup_client_env ( session : Session ) -> None :
200
254
session .chdir (SRC / "client" )
201
255
session .run ("npm" , "install" , external = True )
256
+
257
+
258
+ @nox .session
259
+ @setup_client_env
260
+ def test_javascript_suite (session : Session ) -> None :
261
+ """Run the Javascript-based test suite and ensure it bundles succesfully"""
262
+ session .run ("npm" , "run" , "test" , external = True )
263
+
264
+
265
+ @nox .session
266
+ @setup_client_env
267
+ def test_javascript_build (session : Session ) -> None :
268
+ """Run the Javascript-based test suite and ensure it bundles succesfully"""
202
269
session .run ("npm" , "run" , "test" , external = True )
270
+
271
+
272
+ @nox .session
273
+ @setup_client_env
274
+ def test_javascript_style (session : Session ) -> None :
275
+ """Check that Javascript style guidelines are being followed"""
276
+ session .run ("npm" , "run" , "check-format" , external = True )
277
+
278
+
279
+ @nox .session
280
+ def build_js (session : Session ) -> None :
281
+ """Build javascript client code"""
282
+ session .chdir (SRC / "client" )
203
283
session .run ("npm" , "run" , "build" , external = True )
204
284
205
285
206
286
@nox .session
207
- def tag (session : Session ):
287
+ def tag (session : Session ) -> None :
208
288
"""Create a new git tag"""
209
289
try :
210
290
session .run (
@@ -265,12 +345,6 @@ def update_version(session: Session) -> None:
265
345
session .install ("-e" , "." )
266
346
267
347
268
- @nox .session
269
- def build_js (session : Session ) -> None :
270
- session .chdir (SRC / "client" )
271
- session .run ("npm" , "run" , "build" , external = True )
272
-
273
-
274
348
@nox .session (reuse_venv = True )
275
349
def latest_pull_requests (session : Session ) -> None :
276
350
"""A basic script for outputing changelog info"""
0 commit comments