Skip to content

Commit 3040992

Browse files
authored
Create lint session for nox (#190)
* Create lint session for nox Move black, flake8, and isort actions into the `noxfile.py` alongside the existing mypy session. This will give the dev control over when these checks are run, allowing pre-commit to be optional in the local environment. There is a speed drawback as pre-commit runs on edited files only and nox will run on all file. The pre-commit config will remain and is always an option locally and in pre-commit.ci. * Update CI to use nox lint session * Remove black config * Add verbose flag to isort run
1 parent a7743de commit 3040992

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

.github/workflows/python-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ jobs:
8787
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
8888
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
8989
90-
mypy-check:
91-
name: "mypy strict enforcement"
90+
linting:
91+
name: "Check linting and formatting requirements"
9292
runs-on: "ubuntu-latest"
9393
steps:
9494
- name: "Repo checkout"
@@ -101,8 +101,8 @@ jobs:
101101

102102
- name: "Install nox"
103103
run: |
104-
python -m pip install --upgrade pip nox
104+
python -m pip install --upgrade nox
105105
106-
- name: "Enforce strict type annotations with mypy"
106+
- name: "Run formatters and linters"
107107
run: |
108-
nox --session mypy
108+
nox --session lint

noxfile.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
TESTS_PATH = "tests"
1414
COVERAGE_FAIL_UNDER = 50
1515
DEFAULT_PYTHON = "3.12"
16-
VENV_PATH = ".venv"
16+
VENV_PATH = "./.venv"
17+
LINT_PATH = "./src"
1718
REQUIREMENTS_PATH = "./requirements"
1819

1920
# What we allowed to clean (delete)
@@ -33,10 +34,7 @@
3334

3435
# Define the default sessions run when `nox` is called on the CLI
3536
nox.options.default_venv_backend = "virtualenv"
36-
nox.options.sessions = [
37-
"test",
38-
"mypy",
39-
]
37+
nox.options.sessions = ["lint", "test"]
4038

4139

4240
@nox.session(python=False)
@@ -104,15 +102,31 @@ def coverage_combine(session: nox.Session) -> None:
104102
coverage("json")
105103

106104

107-
@nox.session(python=DEFAULT_PYTHON)
108-
def mypy(session: nox.Session) -> None:
109-
"""Run mypy against package and all required dependencies."""
105+
@nox.session(name="lint")
106+
def run_linters_and_formatters(session: nox.Session) -> None:
107+
"""Run code formatters, linters, and type checking against all files."""
110108
print_standard_logs(session)
111109

112-
session.install(".")
113-
session.install("-r", "requirements/requirements.txt")
114-
session.install("-r", "requirements/requirements-dev.txt")
115-
session.run("mypy", "-p", MODULE_NAME, "--no-incremental")
110+
session.install(".", "-r", f"{REQUIREMENTS_PATH}/requirements-dev.txt")
111+
112+
python = partial(session.run, "python", "-m")
113+
114+
# Handle anything tool that applies corrections first.
115+
python(
116+
"isort",
117+
"--verbose",
118+
"--force-single-line-imports",
119+
"--profile",
120+
"black",
121+
"--add-import",
122+
"from __future__ import annotations",
123+
LINT_PATH,
124+
)
125+
python("black", "--verbose", LINT_PATH)
126+
127+
# Linters: aka, things that yell but want you to fix things
128+
python("flake8", "--show-source", "--verbose", LINT_PATH)
129+
python("mypy", "--no-incremental", "--package", MODULE_NAME)
116130

117131

118132
@nox.session(python=DEFAULT_PYTHON)

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ homepage = "https://github.com/[ORG NAME]/[REPO NAME]"
3030
[tool.setuptools_scm]
3131
# Purposely left empty
3232

33-
[tool.black]
34-
line-length = 100
35-
target-version = ['py39']
36-
3733
[tool.setuptools.package-data]
3834
"module_name" = ["py.typed"]
3935

0 commit comments

Comments
 (0)