Skip to content

Commit 0923a89

Browse files
committed
add format session to noxfile
1 parent b907222 commit 0923a89

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

noxfile.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,11 @@
1414
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
1515

1616

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", ".")
3822

3923

4024
@nox.session(reuse_venv=True)
@@ -54,7 +38,7 @@ def example(session: Session) -> None:
5438
@nox.session(reuse_venv=True)
5539
def docs(session: Session) -> None:
5640
"""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")
5842
install_idom_dev(session, extras="all")
5943
session.run(
6044
"python",
@@ -103,7 +87,7 @@ def test(session: Session) -> None:
10387
def test_python(session: Session) -> None:
10488
"""Run the Python-based test suite"""
10589
session.env["IDOM_DEBUG_MODE"] = "1"
106-
session.install("-r", "requirements/test-env.txt")
90+
install_requirements_file(session, "test-env")
10791

10892
pytest_args = get_posargs("pytest", session)
10993
if "--no-cov" in pytest_args:
@@ -118,16 +102,16 @@ def test_python(session: Session) -> None:
118102
@nox.session
119103
def test_types(session: Session) -> None:
120104
"""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")
124108
session.run("mypy", "--strict", "src/idom")
125109

126110

127111
@nox.session
128112
def test_style(session: Session) -> None:
129113
"""Check that style guidelines are being followed"""
130-
session.install("-r", "requirements/check-style.txt")
114+
install_requirements_file(session, "check-style")
131115
session.run("flake8", "src/idom", "tests", "docs")
132116
black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist"
133117
session.run(
@@ -143,7 +127,7 @@ def test_style(session: Session) -> None:
143127
@nox.session
144128
def test_docs(session: Session) -> None:
145129
"""Verify that the docs build and that doctests pass"""
146-
session.install("-r", "requirements/build-docs.txt")
130+
install_requirements_file(session, "build-docs")
147131
install_idom_dev(session, extras="all")
148132
session.run("sphinx-build", "-b", "html", "docs/source", "docs/build")
149133
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]:
181165
print(f"- {msg} - {sha_repr}")
182166

183167

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+
184197
def install_idom_dev(session: Session, extras: str = "stable") -> None:
185198
session.install("-e", f".[{extras}]")
186199
if "--no-restore" not in session.posargs:

0 commit comments

Comments
 (0)