1
1
from __future__ import annotations
2
2
3
+ import functools
3
4
import os
4
5
import re
5
6
import subprocess
6
7
from pathlib import Path
7
- from typing import List , Tuple
8
+ from typing import Any , Callable , Tuple
8
9
9
10
import nox
10
11
from nox .sessions import Session
14
15
POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
15
16
16
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 )
25
+
26
+ return wrapper
27
+
28
+
17
29
@nox .session (reuse_venv = True )
30
+ @apply_standard_pip_upgrades
18
31
def format (session : Session ) -> None :
19
32
install_requirements_file (session , "check-style" )
20
33
session .run ("black" , "." )
21
34
session .run ("isort" , "." )
22
35
23
36
24
37
@nox .session (reuse_venv = True )
38
+ @apply_standard_pip_upgrades
25
39
def example (session : Session ) -> None :
26
40
"""Run an example"""
27
41
if not session .posargs :
@@ -36,6 +50,7 @@ def example(session: Session) -> None:
36
50
37
51
38
52
@nox .session (reuse_venv = True )
53
+ @apply_standard_pip_upgrades
39
54
def docs (session : Session ) -> None :
40
55
"""Build and display documentation in the browser (automatically reloads on change)"""
41
56
install_requirements_file (session , "build-docs" )
@@ -85,29 +100,33 @@ def docs_in_docker(session: Session) -> None:
85
100
@nox .session
86
101
def test (session : Session ) -> None :
87
102
"""Run the complete test suite"""
88
- session .install ("--upgrade" , "pip" , "setuptools" , "wheel" )
89
- test_suite (session )
90
- test_types (session )
91
- test_style (session )
92
- test_docs (session )
103
+ session .notify ("test_suite" , posargs = session .posargs )
104
+ session .notify ("test_types" )
105
+ session .notify ("test_style" )
106
+ session .notify ("test_docs" )
93
107
94
108
95
109
@nox .session
110
+ @apply_standard_pip_upgrades
96
111
def test_suite (session : Session ) -> None :
97
112
"""Run the Python-based test suite"""
98
113
session .env ["IDOM_DEBUG_MODE" ] = "1"
99
114
install_requirements_file (session , "test-env" )
100
115
101
- pytest_args = get_posargs ("pytest" , session )
102
- if "--no-cov" in pytest_args :
116
+ posargs = session .posargs
117
+ if "--no-cov" in session .posargs :
118
+ session .log ("Coverage won't be checked" )
103
119
session .install (".[all]" )
104
120
else :
121
+ session .log ("Coverage will be checked" )
122
+ posargs += ["--cov=src/idom" , "--cov-report" , "term" ]
105
123
install_idom_dev (session , extras = "all" )
106
124
107
- session .run ("pytest" , "tests" , * pytest_args )
125
+ session .run ("pytest" , "tests" , * posargs )
108
126
109
127
110
128
@nox .session
129
+ @apply_standard_pip_upgrades
111
130
def test_types (session : Session ) -> None :
112
131
"""Perform a static type analysis of the codebase"""
113
132
install_requirements_file (session , "check-types" )
@@ -117,6 +136,7 @@ def test_types(session: Session) -> None:
117
136
118
137
119
138
@nox .session
139
+ @apply_standard_pip_upgrades
120
140
def test_style (session : Session ) -> None :
121
141
"""Check that style guidelines are being followed"""
122
142
install_requirements_file (session , "check-style" )
@@ -133,6 +153,7 @@ def test_style(session: Session) -> None:
133
153
134
154
135
155
@nox .session
156
+ @apply_standard_pip_upgrades
136
157
def test_docs (session : Session ) -> None :
137
158
"""Verify that the docs build and that doctests pass"""
138
159
install_requirements_file (session , "build-docs" )
@@ -173,29 +194,6 @@ def parse_commit_reference(commit_ref: str) -> Tuple[str, str, str]:
173
194
print (f"- { msg } - { sha_repr } " )
174
195
175
196
176
- def get_posargs (name : str , session : Session ) -> List [str ]:
177
- """Find named positional arguments
178
-
179
- Positional args of the form `name[arg1,arg2]` will be parsed as ['arg1', 'arg2'] if
180
- the given `name` matches. Any args not matching that pattern will be added to the
181
- list of args as well. Thus the following:
182
-
183
- --param session_1[arg1,arg2] session_2[arg3,arg4]
184
-
185
- where `name` is session_1 would produce ['--param', 'arg1', 'arg2']
186
- """
187
- collected_args : List [str ] = []
188
- for arg in session .posargs :
189
- match = POSARGS_PATTERN .match (arg )
190
- if match is not None :
191
- found_name , found_args = match .groups ()
192
- if name == found_name :
193
- collected_args .extend (map (str .strip , found_args .split ("," )))
194
- else :
195
- collected_args .append (arg )
196
- return collected_args
197
-
198
-
199
197
def install_requirements_file (session : Session , name : str ) -> None :
200
198
file_path = HERE / "requirements" / (name + ".txt" )
201
199
assert file_path .exists (), f"requirements file { file_path } does not exist"
0 commit comments