|
1 | 1 | """File with common jobs definitions. Run them with 'pdm run nox -e [job_name]'.""" |
2 | 2 | import os |
| 3 | +import tempfile |
3 | 4 |
|
4 | 5 | import nox |
5 | 6 | from nox.sessions import Session |
6 | 7 |
|
7 | 8 | os.environ.update(PDM_IGNORE_SAVED_PYTHON="1", PDM_USE_VENV="1") |
8 | 9 |
|
9 | | -PYSRC = [ |
10 | | - "src/", |
11 | | - "noxfile.py", |
12 | | - "tests/" |
13 | | -] |
| 10 | +PYSRC = ["src/", "noxfile.py", "tests/"] |
| 11 | + |
14 | 12 |
|
15 | 13 | @nox.session |
16 | 14 | def test(session: Session) -> None: |
17 | 15 | """Run tests. |
18 | 16 |
|
19 | 17 | Args: |
20 | 18 | session (Session): nox session object |
21 | | - """ |
| 19 | + """ |
22 | 20 | session.run_always("pdm", "install", "-G", "ci-tests", external=True) |
23 | 21 | session.run("pytest", "tests/") |
24 | 22 |
|
@@ -56,3 +54,18 @@ def check_types(session: Session) -> None: |
56 | 54 | session.run_always("pdm", "install", "-G", "ci-quality", external=True) |
57 | 55 | session.run("mypy", "--config-file", "config/mypy.ini", *PYSRC) |
58 | 56 |
|
| 57 | + |
| 58 | +@nox.session |
| 59 | +def check_safety(session: Session) -> None: |
| 60 | + """Run safety checks. |
| 61 | + |
| 62 | + Args: |
| 63 | + session (Session): nox session object |
| 64 | + """ |
| 65 | + session.run_always("pdm", "install", "-G", "ci-quality", external=True) |
| 66 | + session.run("bandit", "--configfile", "config/bandit.toml", *PYSRC) |
| 67 | + with tempfile.NamedTemporaryFile() as requirements: |
| 68 | + session.run( |
| 69 | + "pdm", "export", "-f", "requirements", "-o", requirements.name, "--without-hashes", external=True |
| 70 | + ) |
| 71 | + session.run("safety", "check", f"--file={requirements.name}", "--full-report") |
0 commit comments