Skip to content

Commit 5862456

Browse files
committed
Allow passing positional arguments to nox sessions
All sessions can now take positional arguments, which will be forwarded to the command run by the session. This is usually very useful to check individual files, or pass extra arguments, like: nox -R -s pytest_max -- -s tests/my/test_this.py Sessions will not process the pre-defined files when positional arguments are passed, so when using positional arguments you should always include paths to check, except for pytest_xxx sessions, which still if files are omitted, all files will be processed, so it can be used to use custom options only too. For example: nox -R -s pytest_max -- -sx Signed-off-by: Leandro Lucarella <[email protected]>
1 parent bb114aa commit 5862456

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

noxfile.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def formatting(session: nox.Session, install_deps: bool = True) -> None:
5353
if install_deps:
5454
session.install(*FMT_DEPS)
5555

56-
session.run("black", "--check", *source_file_paths(session))
57-
session.run("isort", "--check", *source_file_paths(session))
56+
paths = source_file_paths(session)
57+
session.run("black", "--check", *paths)
58+
session.run("isort", "--check", *paths)
5859

5960

6061
@nox.session
@@ -65,13 +66,6 @@ def mypy(session: nox.Session, install_deps: bool = True) -> None:
6566
# fast local tests with `nox -R -e mypy`.
6667
session.install("-e", ".", "mypy", *PYTEST_DEPS)
6768

68-
# Since we use other packages in the frequenz namespace, we need to run the
69-
# checks for frequenz.sdk from the installed package instead of the src
70-
# directory.
71-
mypy_paths = [
72-
path for path in source_file_paths(session) if not path.startswith("src")
73-
]
74-
7569
mypy_cmd = [
7670
"mypy",
7771
"--ignore-missing-imports",
@@ -83,9 +77,21 @@ def mypy(session: nox.Session, install_deps: bool = True) -> None:
8377
"--strict",
8478
]
8579

80+
# If we have session arguments, we just use those...
81+
if session.posargs:
82+
session.run(*mypy_cmd, *session.posargs)
83+
return
84+
8685
# Runs on the installed package
8786
session.run(*mypy_cmd, "-p", "frequenz.sdk")
87+
8888
# Runs on the rest of the source folders
89+
# Since we use other packages in the frequenz namespace, we need to run the
90+
# checks for frequenz.sdk from the installed package instead of the src
91+
# directory.
92+
mypy_paths = [
93+
path for path in source_file_paths(session) if not path.startswith("src")
94+
]
8995
session.run(*mypy_cmd, *mypy_paths)
9096

9197

@@ -97,10 +103,11 @@ def pylint(session: nox.Session, install_deps: bool = True) -> None:
97103
# fast local tests with `nox -R -e pylint`.
98104
session.install("-e", ".", "pylint", *PYTEST_DEPS)
99105

106+
paths = source_file_paths(session)
100107
session.run(
101108
"pylint",
102109
"--extension-pkg-whitelist=pydantic",
103-
*source_file_paths(session),
110+
*paths,
104111
)
105112

106113

@@ -110,12 +117,14 @@ def docstrings(session: nox.Session, install_deps: bool = True) -> None:
110117
if install_deps:
111118
session.install(*DOCSTRING_DEPS, "toml")
112119

113-
session.run("pydocstyle", *source_file_paths(session))
120+
paths = source_file_paths(session)
121+
session.run("pydocstyle", *paths)
114122

115123
# Darglint checks that function argument and return values are documented.
116124
# This is needed only for the `src` dir, so we exclude the other top level
117-
# dirs that contain code.
118-
darglint_paths = filter(
125+
# dirs that contain code, unless some paths were specified by argument, in
126+
# which case we use those untouched.
127+
darglint_paths = session.posargs or filter(
119128
lambda path: not (path.startswith("tests") or path.startswith("benchmarks")),
120129
source_file_paths(session),
121130
)
@@ -158,4 +167,5 @@ def _pytest_impl(
158167
"--cov=frequenz.sdk",
159168
"--cov-report=term",
160169
f"--cov-report=html:.htmlcov-{max_or_min_deps}",
170+
*session.posargs,
161171
)

0 commit comments

Comments
 (0)