Skip to content

Commit 9d544a5

Browse files
feat: Enable pep8-naming ruff rules (#283)
Fixes #282 Enable pep8-naming ruff rules, enforcing that projects follow convetional pep8 naming styles. See https://peps.python.org/pep-0008
1 parent 76c187c commit 9d544a5

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ lint.select = [
6262
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
6363
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
6464
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
65+
"N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n
6566
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
6667
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
6768
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up
6869
]
70+
71+
[tool.ruff.lint.per-file-ignores]
72+
# Ignore variable names inside the template because ruff doesn't
73+
# work well with jinja templating. Any violations of N rules inside
74+
# the template are caught by the tests.
75+
"template/**/*" = ["N"]

template/pyproject.toml.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ lint.select = [
109109
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
110110
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
111111
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
112+
"N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n
112113
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
113114
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
114115
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up

tests/test_example.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,21 @@ def __init__(self):
223223
run("ruff check")
224224

225225

226+
def test_pep8_naming(tmp_path: Path):
227+
code = """
228+
myVariable = "foo"
229+
"""
230+
231+
copy_project(tmp_path)
232+
run = make_venv(tmp_path)
233+
234+
src_file = tmp_path / "src" / "python_copier_template_example" / "bad_example.py"
235+
with src_file.open("w") as stream:
236+
stream.write(code)
237+
with pytest.raises(AssertionError, match=r"N816 .*"):
238+
run("ruff check")
239+
240+
226241
def test_pyright_works_in_standard_typing_mode(tmp_path: Path):
227242
copy_project(tmp_path, type_checker="pyright", strict_typing=False)
228243
pyproject_toml = tmp_path / "pyproject.toml"

0 commit comments

Comments
 (0)