11# License: MIT
22# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
33
4+ """Project's noxfile.
5+
6+ For more information please see nox documentation:
7+ https://nox.thea.codes/en/stable/
8+ """
9+
410from typing import List
5- import nox
611
12+ import nox
713
814FMT_DEPS = ["black" , "isort" ]
9- LINT_DEPS = ["mypy" , "pylint" ]
1015DOCSTRING_DEPS = ["pydocstyle" , "darglint" ]
1116PYTEST_DEPS = ["pytest" , "pytest-cov" , "pytest-mock" , "pytest-asyncio" , "time-machine" ]
1217
1318
14- def source_file_paths (session : nox .Session ) -> List [str ]:
19+ def _source_file_paths (session : nox .Session ) -> List [str ]:
1520 """Return the file paths to run the checks on.
1621
17- If positional arguments are present, we use those as the file paths, and if
18- not, we use all source files."""
22+ If positional arguments are present in the nox session, we use those as the
23+ file paths, and if not, we use all source files.
24+
25+ Args:
26+ session: the nox session.
27+
28+ Returns:
29+ the file paths to run the checks on.
30+ """
1931 if session .posargs :
2032 return session .posargs
2133 return [
22- "benchmarks" ,
23- "docs" ,
24- "examples" ,
25- "src" ,
26- "tests" ,
27- ]
34+ "benchmarks" ,
35+ "docs" ,
36+ "examples" ,
37+ "src" ,
38+ "tests" ,
39+ "noxfile.py" ,
40+ ]
2841
2942
3043# Run all checks except `ci_checks` by default. When running locally with just
@@ -46,9 +59,13 @@ def ci_checks_max(session: nox.Session) -> None:
4659 This is faster than running the checks separately, so it is suitable for CI.
4760
4861 This does NOT run pytest_min, so that needs to be run separately as well.
62+
63+ Args:
64+ session: the nox session.
4965 """
50- session .install (".[docs]" , * PYTEST_DEPS , * FMT_DEPS , * LINT_DEPS ,
51- * DOCSTRING_DEPS )
66+ session .install (
67+ ".[docs]" , "mypy" , "pylint" , "nox" , * PYTEST_DEPS , * FMT_DEPS , * DOCSTRING_DEPS
68+ )
5269
5370 formatting (session , False )
5471 mypy (session , False )
@@ -59,22 +76,32 @@ def ci_checks_max(session: nox.Session) -> None:
5976
6077@nox .session
6178def formatting (session : nox .Session , install_deps : bool = True ) -> None :
62- """Check code formatting with black and isort."""
79+ """Check code formatting with black and isort.
80+
81+ Args:
82+ session: the nox session.
83+ install_deps: True if dependencies should be installed.
84+ """
6385 if install_deps :
6486 session .install (* FMT_DEPS )
6587
66- paths = source_file_paths (session )
88+ paths = _source_file_paths (session )
6789 session .run ("black" , "--check" , * paths )
6890 session .run ("isort" , "--check" , * paths )
6991
7092
7193@nox .session
7294def mypy (session : nox .Session , install_deps : bool = True ) -> None :
73- """Check type hints with mypy."""
95+ """Check type hints with mypy.
96+
97+ Args:
98+ session: the nox session.
99+ install_deps: True if dependencies should be installed.
100+ """
74101 if install_deps :
75102 # install the package itself as editable, so that it is possible to do
76103 # fast local tests with `nox -R -e mypy`.
77- session .install ("-e" , "." , "mypy" , * PYTEST_DEPS )
104+ session .install ("-e" , ".[docs] " , "mypy" , "nox " , * PYTEST_DEPS )
78105
79106 mypy_cmd = [
80107 "mypy" ,
@@ -100,20 +127,25 @@ def mypy(session: nox.Session, install_deps: bool = True) -> None:
100127 # checks for frequenz.sdk from the installed package instead of the src
101128 # directory.
102129 mypy_paths = [
103- path for path in source_file_paths (session ) if not path .startswith ("src" )
130+ path for path in _source_file_paths (session ) if not path .startswith ("src" )
104131 ]
105132 session .run (* mypy_cmd , * mypy_paths )
106133
107134
108135@nox .session
109136def pylint (session : nox .Session , install_deps : bool = True ) -> None :
110- """Check for code smells with pylint."""
137+ """Check for code smells with pylint.
138+
139+ Args:
140+ session: the nox session.
141+ install_deps: True if dependencies should be installed.
142+ """
111143 if install_deps :
112144 # install the package itself as editable, so that it is possible to do
113145 # fast local tests with `nox -R -e pylint`.
114- session .install ("-e" , ".[docs]" , "pylint" , * PYTEST_DEPS )
146+ session .install ("-e" , ".[docs]" , "pylint" , "nox" , * PYTEST_DEPS )
115147
116- paths = source_file_paths (session )
148+ paths = _source_file_paths (session )
117149 session .run (
118150 "pylint" ,
119151 "--extension-pkg-whitelist=pydantic" ,
@@ -123,11 +155,16 @@ def pylint(session: nox.Session, install_deps: bool = True) -> None:
123155
124156@nox .session
125157def docstrings (session : nox .Session , install_deps : bool = True ) -> None :
126- """Check docstring tone with pydocstyle and param descriptions with darglint."""
158+ """Check docstring tone with pydocstyle and param descriptions with darglint.
159+
160+ Args:
161+ session: the nox session.
162+ install_deps: True if dependencies should be installed.
163+ """
127164 if install_deps :
128165 session .install (* DOCSTRING_DEPS , "toml" )
129166
130- paths = source_file_paths (session )
167+ paths = _source_file_paths (session )
131168 session .run ("pydocstyle" , * paths )
132169
133170 # Darglint checks that function argument and return values are documented.
@@ -136,7 +173,7 @@ def docstrings(session: nox.Session, install_deps: bool = True) -> None:
136173 # which case we use those untouched.
137174 darglint_paths = session .posargs or filter (
138175 lambda path : not (path .startswith ("tests" ) or path .startswith ("benchmarks" )),
139- source_file_paths (session ),
176+ _source_file_paths (session ),
140177 )
141178 session .run (
142179 "darglint" ,
@@ -147,29 +184,37 @@ def docstrings(session: nox.Session, install_deps: bool = True) -> None:
147184
148185@nox .session
149186def pytest_max (session : nox .Session , install_deps : bool = True ) -> None :
150- """Test the code against max dependency versions with pytest."""
187+ """Test the code against max dependency versions with pytest.
188+
189+ Args:
190+ session: the nox session.
191+ install_deps: True if dependencies should be installed.
192+ """
151193 if install_deps :
152194 # install the package itself as editable, so that it is possible to do
153195 # fast local tests with `nox -R -e pytest_max`.
154196 session .install ("-e" , "." , * PYTEST_DEPS )
155197
156- _pytest_impl (session , "max" , install_deps )
198+ _pytest_impl (session , "max" )
157199
158200
159201@nox .session
160202def pytest_min (session : nox .Session , install_deps : bool = True ) -> None :
161- """Test the code against min dependency versions with pytest."""
203+ """Test the code against min dependency versions with pytest.
204+
205+ Args:
206+ session: the nox session.
207+ install_deps: True if dependencies should be installed.
208+ """
162209 if install_deps :
163210 # install the package itself as editable, so that it is possible to do
164211 # fast local tests with `nox -R -e pytest_min`.
165212 session .install ("-e" , "." , * PYTEST_DEPS , "-r" , "minimum-requirements-ci.txt" )
166213
167- _pytest_impl (session , "min" , install_deps )
214+ _pytest_impl (session , "min" )
168215
169216
170- def _pytest_impl (
171- session : nox .Session , max_or_min_deps : str , install_deps : bool
172- ) -> None :
217+ def _pytest_impl (session : nox .Session , max_or_min_deps : str ) -> None :
173218 session .run (
174219 "pytest" ,
175220 "-W=all" ,
0 commit comments