14
14
POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
15
15
16
16
17
- def get_posargs (name : str , session : Session ) -> List [str ]:
18
- """Find named positional arguments
19
-
20
- Positional args of the form `name[arg1,arg2]` will be parsed as ['arg1', 'arg2'] if
21
- the given `name` matches. Any args not matching that pattern will be added to the
22
- list of args as well. Thus the following:
23
-
24
- --param session_1[arg1,arg2] session_2[arg3,arg4]
25
-
26
- where `name` is session_1 would produce ['--param', 'arg1', 'arg2']
27
- """
28
- collected_args : List [str ] = []
29
- for arg in session .posargs :
30
- match = POSARGS_PATTERN .match (arg )
31
- if match is not None :
32
- found_name , found_args = match .groups ()
33
- if name == found_name :
34
- collected_args .extend (map (str .strip , found_args .split ("," )))
35
- else :
36
- collected_args .append (arg )
37
- return collected_args
17
+ @nox .session (reuse_venv = True )
18
+ def format (session : Session ) -> None :
19
+ install_requirements_file (session , "check-style" )
20
+ session .run ("black" , "." )
21
+ session .run ("isort" , "." )
38
22
39
23
40
24
@nox .session (reuse_venv = True )
@@ -54,7 +38,7 @@ def example(session: Session) -> None:
54
38
@nox .session (reuse_venv = True )
55
39
def docs (session : Session ) -> None :
56
40
"""Build and display documentation in the browser (automatically reloads on change)"""
57
- session . install ( "-r" , "requirements/ build-docs.txt " )
41
+ install_requirements_file ( session , "build-docs" )
58
42
install_idom_dev (session , extras = "all" )
59
43
session .run (
60
44
"python" ,
@@ -103,7 +87,7 @@ def test(session: Session) -> None:
103
87
def test_python (session : Session ) -> None :
104
88
"""Run the Python-based test suite"""
105
89
session .env ["IDOM_DEBUG_MODE" ] = "1"
106
- session . install ( "-r" , "requirements/ test-env.txt " )
90
+ install_requirements_file ( session , "test-env" )
107
91
108
92
pytest_args = get_posargs ("pytest" , session )
109
93
if "--no-cov" in pytest_args :
@@ -118,16 +102,16 @@ def test_python(session: Session) -> None:
118
102
@nox .session
119
103
def test_types (session : Session ) -> None :
120
104
"""Perform a static type analysis of the codebase"""
121
- session . install ( "-r" , "requirements/ check-types.txt " )
122
- session . install ( "-r" , "requirements/ pkg-deps.txt " )
123
- session . install ( "-r" , "requirements/ pkg-extras.txt " )
105
+ install_requirements_file ( session , "check-types" )
106
+ install_requirements_file ( session , "pkg-deps" )
107
+ install_requirements_file ( session , "pkg-extras" )
124
108
session .run ("mypy" , "--strict" , "src/idom" )
125
109
126
110
127
111
@nox .session
128
112
def test_style (session : Session ) -> None :
129
113
"""Check that style guidelines are being followed"""
130
- session . install ( "-r" , "requirements/ check-style.txt " )
114
+ install_requirements_file ( session , "check-style" )
131
115
session .run ("flake8" , "src/idom" , "tests" , "docs" )
132
116
black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist"
133
117
session .run (
@@ -143,7 +127,7 @@ def test_style(session: Session) -> None:
143
127
@nox .session
144
128
def test_docs (session : Session ) -> None :
145
129
"""Verify that the docs build and that doctests pass"""
146
- session . install ( "-r" , "requirements/ build-docs.txt " )
130
+ install_requirements_file ( session , "build-docs" )
147
131
install_idom_dev (session , extras = "all" )
148
132
session .run ("sphinx-build" , "-b" , "html" , "docs/source" , "docs/build" )
149
133
session .run ("sphinx-build" , "-b" , "doctest" , "docs/source" , "docs/build" )
@@ -181,6 +165,35 @@ def parse_commit_reference(commit_ref: str) -> Tuple[str, str, str]:
181
165
print (f"- { msg } - { sha_repr } " )
182
166
183
167
168
+ def get_posargs (name : str , session : Session ) -> List [str ]:
169
+ """Find named positional arguments
170
+
171
+ Positional args of the form `name[arg1,arg2]` will be parsed as ['arg1', 'arg2'] if
172
+ the given `name` matches. Any args not matching that pattern will be added to the
173
+ list of args as well. Thus the following:
174
+
175
+ --param session_1[arg1,arg2] session_2[arg3,arg4]
176
+
177
+ where `name` is session_1 would produce ['--param', 'arg1', 'arg2']
178
+ """
179
+ collected_args : List [str ] = []
180
+ for arg in session .posargs :
181
+ match = POSARGS_PATTERN .match (arg )
182
+ if match is not None :
183
+ found_name , found_args = match .groups ()
184
+ if name == found_name :
185
+ collected_args .extend (map (str .strip , found_args .split ("," )))
186
+ else :
187
+ collected_args .append (arg )
188
+ return collected_args
189
+
190
+
191
+ def install_requirements_file (session : Session , name : str ) -> None :
192
+ file_path = HERE / "requirements" / (name + ".txt" )
193
+ assert file_path .exists (), f"requirements file { file_path } does not exist"
194
+ session .install ("-r" , str (file_path ))
195
+
196
+
184
197
def install_idom_dev (session : Session , extras : str = "stable" ) -> None :
185
198
session .install ("-e" , f".[{ extras } ]" )
186
199
if "--no-restore" not in session .posargs :
0 commit comments