|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import nox |
| 4 | + |
| 5 | +nox.options.reuse_existing_virtualenvs = True # Reuse virtual environments |
| 6 | +nox.options.sessions = ["precommit"] |
| 7 | + |
| 8 | + |
| 9 | +def get_paths(session): |
| 10 | + package_path = Path(session.bin).parent.parent.parent |
| 11 | + return { |
| 12 | + "all": [ |
| 13 | + package_path / "geospatial_tools", |
| 14 | + package_path / "tests", |
| 15 | + package_path / "scripts", |
| 16 | + ], |
| 17 | + "module": [ |
| 18 | + package_path / "geospatial_tools", |
| 19 | + package_path / "scripts", |
| 20 | + ], |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | +# |
| 25 | +# Sessions |
| 26 | +# |
| 27 | + |
| 28 | + |
| 29 | +@nox.session() |
| 30 | +def pylint(session): |
| 31 | + paths = get_paths(session) |
| 32 | + session.run("poetry", "run", "pylint", *paths["module"], external=True) |
| 33 | + |
| 34 | + |
| 35 | +@nox.session() |
| 36 | +def flake8(session): |
| 37 | + paths = get_paths(session) |
| 38 | + session.run("poetry", "run", "flake8", *paths["all"], external=True) |
| 39 | + |
| 40 | + |
| 41 | +@nox.session() |
| 42 | +def docformatter(session): |
| 43 | + paths = get_paths(session) |
| 44 | + session.run( |
| 45 | + "poetry", |
| 46 | + "run", |
| 47 | + "docformatter", |
| 48 | + "--config", |
| 49 | + f"{paths['all'][0].parent}/pyproject.toml", |
| 50 | + *paths["all"], |
| 51 | + external=True, |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +@nox.session() |
| 56 | +def check(session): |
| 57 | + paths = get_paths(session) |
| 58 | + session.run("poetry", "run", "black", "--check", *paths["all"], external=True) |
| 59 | + session.run("poetry", "run", "isort", *paths["all"], "--check", external=True) |
| 60 | + session.run("poetry", "run", "flynt", *paths["all"], external=True) |
| 61 | + session.run( |
| 62 | + "poetry", |
| 63 | + "run", |
| 64 | + "docformatter", |
| 65 | + "--config", |
| 66 | + f"{paths['all'][0].parent}/pyproject.toml", |
| 67 | + *paths["all"], |
| 68 | + external=True, |
| 69 | + ) |
| 70 | + session.run("poetry", "run", "flake8", *paths["all"], external=True) |
| 71 | + session.run("poetry", "run", "pylint", *paths["module"], external=True) |
| 72 | + |
| 73 | + |
| 74 | +@nox.session() |
| 75 | +def fix(session): |
| 76 | + paths = get_paths(session) |
| 77 | + session.run("poetry", "run", "black", *paths["all"], external=True) |
| 78 | + session.run("poetry", "run", "isort", *paths["all"], external=True) |
| 79 | + session.run("poetry", "run", "flynt", *paths["all"], external=True) |
| 80 | + session.run( |
| 81 | + "poetry", |
| 82 | + "run", |
| 83 | + "docformatter", |
| 84 | + "--in-place", |
| 85 | + "--config", |
| 86 | + f"{paths['all'][0].parent}/pyproject.toml", |
| 87 | + *paths["all"], |
| 88 | + external=True, |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +@nox.session() |
| 93 | +def precommit(session): |
| 94 | + session.run("poetry", "run", "pre-commit", "run", "--all-files", external=True) |
| 95 | + |
| 96 | + |
| 97 | +@nox.session() |
| 98 | +def black(session): |
| 99 | + paths = get_paths(session) |
| 100 | + session.run("poetry", "run", "black", "--check", *paths["all"], external=True) |
| 101 | + |
| 102 | + |
| 103 | +@nox.session() |
| 104 | +def isort(session): |
| 105 | + paths = get_paths(session) |
| 106 | + session.run("poetry", "run", "isort", *paths["all"], "--check", external=True) |
| 107 | + |
| 108 | + |
| 109 | +@nox.session() |
| 110 | +def flynt(session): |
| 111 | + paths = get_paths(session) |
| 112 | + session.run("poetry", "run", "flynt", *paths["all"], external=True) |
| 113 | + |
| 114 | + |
| 115 | +@nox.session() |
| 116 | +def test(session): |
| 117 | + session.run("poetry", "run", "pytest", external=True) |
| 118 | + |
| 119 | + |
| 120 | +@nox.session() |
| 121 | +def test_custom(session): |
| 122 | + session.run( |
| 123 | + "poetry", "run", "pytest", external=True, *session.posargs |
| 124 | + ) # Pass additional arguments directly to pytest |
| 125 | + |
| 126 | + |
| 127 | +@nox.session() |
| 128 | +def test_nb(session): |
| 129 | + session.run( |
| 130 | + "poetry", |
| 131 | + "run", |
| 132 | + "pytest", |
| 133 | + "--nbval", |
| 134 | + "tests/test_notebooks/", |
| 135 | + "--nbval-sanitize-with=tests/test_notebooks/sanitize_file.cfg", |
| 136 | + external=True, |
| 137 | + ) |
0 commit comments