|
| 1 | +import tempfile |
| 2 | + |
| 3 | +import nox |
| 4 | + |
| 5 | +locations = "demo", "natrix", "tests", "noxfile.py" |
| 6 | + |
| 7 | + |
| 8 | +def install_with_constraints(session, *args, **kwargs): |
| 9 | + with tempfile.NamedTemporaryFile() as requirements: |
| 10 | + session.run( |
| 11 | + "poetry", |
| 12 | + "export", |
| 13 | + "--dev", |
| 14 | + "--format=requirements.txt", |
| 15 | + "--without-hashes", |
| 16 | + f"--output={requirements.name}", |
| 17 | + external=True, |
| 18 | + ) |
| 19 | + session.install(f"--constraint={requirements.name}", *args, **kwargs) |
| 20 | + |
| 21 | + |
| 22 | +@nox.session(python="3.7") |
| 23 | +def black(session): |
| 24 | + args = session.posargs or locations |
| 25 | + install_with_constraints(session, "black") |
| 26 | + session.run("black", *args) |
| 27 | + |
| 28 | + |
| 29 | +@nox.session(python="3.7") |
| 30 | +def lint(session): |
| 31 | + args = session.posargs or locations |
| 32 | + install_with_constraints( |
| 33 | + session, |
| 34 | + "flake8", |
| 35 | + "flake8-bandit", |
| 36 | + "flake8-black", |
| 37 | + "flake8-bugbear", |
| 38 | + "flake8-import-order", |
| 39 | + ) |
| 40 | + session.run("flake8", *args) |
| 41 | + |
| 42 | + |
| 43 | +@nox.session(python="3.7") |
| 44 | +def safety(session): |
| 45 | + with tempfile.NamedTemporaryFile() as requirements: |
| 46 | + session.run( |
| 47 | + "poetry", |
| 48 | + "export", |
| 49 | + "--dev", |
| 50 | + "--format=requirements.txt", |
| 51 | + "--without-hashes", |
| 52 | + f"--output={requirements.name}", |
| 53 | + external=True, |
| 54 | + ) |
| 55 | + install_with_constraints(session, "safety") |
| 56 | + session.run("safety", "check", f"--file={requirements.name}", "--full-report") |
| 57 | + |
| 58 | + |
| 59 | +@nox.session(python="3.7") |
| 60 | +def tests(session): |
| 61 | + args = session.posargs or ["--cov", "-m", "not e2e"] |
| 62 | + session.run("poetry", "install", "--no-dev", external=True) |
| 63 | + install_with_constraints(session, "pytest", "pytest-mock") |
| 64 | + session.run("pytest", *args) |
0 commit comments