|
1 | | -# noxfile.py |
2 | 1 | import nox |
3 | 2 | import sys |
4 | 3 | import os |
|
11 | 10 | "src/*.so", |
12 | 11 | ) |
13 | 12 |
|
14 | | -# Optional: set defaults so `nox` with no args runs tests. |
15 | | -# Comment this out if you don't want defaults. |
| 13 | +# Make `nox` default to running tests if you just do `nox` |
16 | 14 | nox.options.sessions = ["test"] |
17 | 15 |
|
18 | | -@nox.session(python=False) # run in the current environment |
19 | | -def clean(session): |
20 | | - """Clean build artifacts and uninstall arraykit.""" |
| 16 | +# ----- helpers (not sessions) ----- |
| 17 | + |
| 18 | +def do_clean(session: nox.Session) -> None: |
| 19 | + # uninstall arraykit |
21 | 20 | session.run( |
22 | 21 | sys.executable, "-m", "pip", |
23 | 22 | "--disable-pip-version-check", "uninstall", "--yes", "arraykit", |
24 | 23 | external=True |
25 | 24 | ) |
| 25 | + # remove artifacts |
26 | 26 | for artifact in sorted(ARTIFACTS): |
27 | 27 | session.run("rm", "-rf", artifact, external=True) |
28 | 28 |
|
29 | | -@nox.session(python=False) |
30 | | -def build(session): |
31 | | - """Build/install locally without build isolation (keeps verbose for warnings).""" |
| 29 | +def do_build(session: nox.Session) -> None: |
| 30 | + # keep -v to see warnings; no build isolation to match your invoke cmd |
32 | 31 | session.run( |
33 | 32 | sys.executable, "-m", "pip", |
34 | 33 | "--disable-pip-version-check", "-v", |
35 | 34 | "install", "--no-build-isolation", ".", |
36 | 35 | external=True |
37 | 36 | ) |
38 | 37 |
|
39 | | -@nox.session(python=False) |
40 | | -def test(session): |
41 | | - """Run pytest with native traceback.""" |
| 38 | +def do_test(session: nox.Session) -> None: |
42 | 39 | session.run( |
43 | | - "pytest", "-s", "--disable-pytest-warnings", "--tb=native", |
44 | | - external=True |
| 40 | + "pytest", |
| 41 | + "-s", |
| 42 | + "--disable-pytest-warnings", |
| 43 | + "--tb=native", |
| 44 | + external=True, |
45 | 45 | ) |
46 | 46 |
|
47 | | -@nox.session(python=False) |
48 | | -def performance(session): |
49 | | - """Run performance benches. Pass names via env: NAMES='foo,bar' nox -s performance""" |
50 | | - names = os.environ.get("NAMES", "") |
| 47 | +def do_performance(session: nox.Session) -> None: |
| 48 | + """Run performance benchmarks.""" |
51 | 49 | args = [sys.executable, "-m", "performance"] |
52 | | - if names: |
53 | | - args.extend(["--names", names]) |
| 50 | + |
| 51 | + if session.posargs: |
| 52 | + args.extend(["--names"] + session.posargs) |
| 53 | + |
54 | 54 | session.run(*args, external=True) |
55 | 55 |
|
| 56 | +def do_lint(session: nox.Session) -> None: |
| 57 | + session.run( |
| 58 | + "pylint", |
| 59 | + "-f", "colorized", |
| 60 | + "*.py", "performance", "src", "test", |
| 61 | + external=True, |
| 62 | + ) |
| 63 | + |
| 64 | +# ----- sessions ----- |
| 65 | + |
| 66 | +@nox.session(python=False) # use current environment |
| 67 | +def clean(session): |
| 68 | + """Clean build artifacts and uninstall arraykit.""" |
| 69 | + do_clean(session) |
| 70 | + |
| 71 | +@nox.session(python=False) |
| 72 | +def build(session): |
| 73 | + """Clean then build/install locally (like invoke: build depends on clean).""" |
| 74 | + do_clean(session) |
| 75 | + do_build(session) |
| 76 | + |
| 77 | +@nox.session(python=False) |
| 78 | +def test(session): |
| 79 | + """Build then run pytest (like invoke: test depends on build).""" |
| 80 | + do_build(session) |
| 81 | + do_test(session) |
| 82 | + |
| 83 | +@nox.session(python=False) |
| 84 | +def performance(session): |
| 85 | + """Build then run performance benches (like invoke: performance depends on build).""" |
| 86 | + do_build(session) |
| 87 | + do_performance(session) |
| 88 | + |
56 | 89 | @nox.session(python=False) |
57 | 90 | def lint(session): |
58 | 91 | """Run pylint static analysis.""" |
59 | | - session.run( |
60 | | - "pylint", "-f", "colorized", "*.py", "performance", "src", "test", |
61 | | - external=True |
62 | | - ) |
| 92 | + do_lint(session) |
0 commit comments