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