11from __future__ import annotations
22
3+ import functools
34import os
45import re
56import subprocess
67from pathlib import Path
7- from typing import List , Tuple
8+ from typing import Any , Callable , Tuple
89
910import nox
1011from nox .sessions import Session
1415POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
1516
1617
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+
1729@nox .session (reuse_venv = True )
30+ @apply_standard_pip_upgrades
1831def format (session : Session ) -> None :
1932 install_requirements_file (session , "check-style" )
2033 session .run ("black" , "." )
2134 session .run ("isort" , "." )
2235
2336
2437@nox .session (reuse_venv = True )
38+ @apply_standard_pip_upgrades
2539def example (session : Session ) -> None :
2640 """Run an example"""
2741 if not session .posargs :
@@ -36,6 +50,7 @@ def example(session: Session) -> None:
3650
3751
3852@nox .session (reuse_venv = True )
53+ @apply_standard_pip_upgrades
3954def docs (session : Session ) -> None :
4055 """Build and display documentation in the browser (automatically reloads on change)"""
4156 install_requirements_file (session , "build-docs" )
@@ -85,29 +100,33 @@ def docs_in_docker(session: Session) -> None:
85100@nox .session
86101def test (session : Session ) -> None :
87102 """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" )
93107
94108
95109@nox .session
110+ @apply_standard_pip_upgrades
96111def test_suite (session : Session ) -> None :
97112 """Run the Python-based test suite"""
98113 session .env ["IDOM_DEBUG_MODE" ] = "1"
99114 install_requirements_file (session , "test-env" )
100115
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" )
103119 session .install (".[all]" )
104120 else :
121+ session .log ("Coverage will be checked" )
122+ posargs += ["--cov=src/idom" , "--cov-report" , "term" ]
105123 install_idom_dev (session , extras = "all" )
106124
107- session .run ("pytest" , "tests" , * pytest_args )
125+ session .run ("pytest" , "tests" , * posargs )
108126
109127
110128@nox .session
129+ @apply_standard_pip_upgrades
111130def test_types (session : Session ) -> None :
112131 """Perform a static type analysis of the codebase"""
113132 install_requirements_file (session , "check-types" )
@@ -117,6 +136,7 @@ def test_types(session: Session) -> None:
117136
118137
119138@nox .session
139+ @apply_standard_pip_upgrades
120140def test_style (session : Session ) -> None :
121141 """Check that style guidelines are being followed"""
122142 install_requirements_file (session , "check-style" )
@@ -133,6 +153,7 @@ def test_style(session: Session) -> None:
133153
134154
135155@nox .session
156+ @apply_standard_pip_upgrades
136157def test_docs (session : Session ) -> None :
137158 """Verify that the docs build and that doctests pass"""
138159 install_requirements_file (session , "build-docs" )
@@ -173,29 +194,6 @@ def parse_commit_reference(commit_ref: str) -> Tuple[str, str, str]:
173194 print (f"- { msg } - { sha_repr } " )
174195
175196
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-
199197def install_requirements_file (session : Session , name : str ) -> None :
200198 file_path = HERE / "requirements" / (name + ".txt" )
201199 assert file_path .exists (), f"requirements file { file_path } does not exist"
0 commit comments