Skip to content

Commit ce9523b

Browse files
committed
Removing flake8 dependency and including ruff
1 parent c384c13 commit ce9523b

File tree

9 files changed

+680
-1300
lines changed

9 files changed

+680
-1300
lines changed

cookiecutter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"package_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_').replace('project', 'package') }}",
88
"module_name": "{{ cookiecutter.package_name.lower().replace(' ', '_').replace('-', '_').replace('package', 'module') }}",
99
"project_short_description": "Python template with some awesome tools to quickstart any Python project",
10+
"minimum_coverage": 100,
11+
"include_examples": "true",
1012
"version": "0.1.0",
1113
"license": ["MIT", "BSD_3_Clause", "Apache_2.0", "GPL_3.0", "Proprietary"]
1214
}

{{cookiecutter.project_slug}}/.flake8

Lines changed: 0 additions & 18 deletions
This file was deleted.

{{cookiecutter.project_slug}}/docs/gen_pages.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""This module generates readme and feature files for mkdocs.
2+
3+
As part of the mkdocs-gen-file plugin, this module helps to automate
4+
readme generation using the README file and feature pages using the feature
5+
files if they do exist.
6+
"""
7+
18
from pathlib import Path
29

310
import mkdocs_gen_files
@@ -7,9 +14,10 @@
714
# Automagically injects README file into the documentation
815
readme_path = docs_parent_dir / "README.md"
916
if readme_path.exists():
10-
with open(readme_path, "r") as r:
11-
with mkdocs_gen_files.open("readme.md", "w") as f:
12-
f.write(r.read())
17+
with open(readme_path, "r") as r, mkdocs_gen_files.open(
18+
"readme.md", "w"
19+
) as f:
20+
f.write(r.read())
1321

1422

1523
# Injects feature files into the documentation
@@ -31,9 +39,9 @@
3139
) as gf:
3240
f_line_list = f.readlines()
3341
for line in f_line_list:
34-
if any([line.strip().startswith(l) for l in head_lines]):
42+
if any([line.strip().startswith(hl) for hl in head_lines]):
3543
write_line = f"### {line}\n"
36-
elif any([line.strip().startswith(l) for l in ignore_lines]):
44+
elif any([line.strip().startswith(il) for il in ignore_lines]):
3745
continue
3846
else:
3947
write_line = f"> {line}"

{{cookiecutter.project_slug}}/docs/mkdocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ theme:
1818
name: material
1919
palette:
2020
- media: '(prefers-color-scheme: light)'
21-
scheme: slate
21+
scheme: default
2222
primary: blue
2323
accent: amber
2424
toggle:
2525
icon: material/lightbulb-outline
2626
name: Switch to light mode
2727
- media: '(prefers-color-scheme: dark)'
28-
scheme: default
28+
scheme: slate
2929
primary: black
3030
accent: amber
3131
toggle:

{{cookiecutter.project_slug}}/poetry.lock

Lines changed: 597 additions & 1205 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,13 @@ python = "^3.10"
1717

1818
[tool.poetry.group.dev.dependencies]
1919
pre-commit = "^2.18.1"
20-
isort = "^5.10.1"
2120
black = {version = "^22.3.0", allow-prereleases = true}
2221
xdoctest = "^1.0.0"
23-
Pygments = "^2.11.2"
24-
darglint = "^1.8.1"
25-
pylint = "^2.13.4"
2622
poethepoet = "^0.16.4"
27-
mypy = "^0.942"
28-
flake8 = "^4.0.1"
29-
flake8-docstrings = "^1.6.0"
30-
flake8-todos = "^0.1.5"
31-
flake8-logging-format = "^0.6.0"
32-
flake8-builtins = "^1.5.3"
33-
flake8-pytest-style = "^1.6.0"
34-
flake8-bugbear = "^22.3.23"
35-
flake8-bandit = "^3.0.0"
36-
flake8-annotations = "^2.8.0"
37-
flake8-black = "^0.3.2"
38-
flake8-mypy = "^17.8.0"
39-
flake8-simplify = "^0.19.3"
40-
flake8-isort = "^5.0.0"
41-
pep8-naming = "^0.12.1"
23+
ruff = "^0.0.253"
4224
pytest = "7.1.1"
4325
pytest-html = "^3.1.1"
4426
pytest-sugar = "^0.9.6"
45-
pytest-flake8 = "^1.1.1"
4627
pytest-reverse = "^1.5.0"
4728
pytest-cov = "^3.0.0"
4829
pytest-bdd = "^6.1.1"
@@ -51,59 +32,70 @@ mkdocs-material = "^8.5.10"
5132
mkdocs-gen-files = "^0.4.0"
5233
mkdocs-awesome-pages-plugin = "^2.8.0"
5334
mkapi = "^1.0.14"
54-
mako = "^1.2.3"
5535

5636
[tool.poetry.scripts]
57-
-x = "poethepoet:main"
37+
-c = "poethepoet:main"
5838

5939
[build-system]
6040
requires = ["poetry-core>=1.0.0"]
6141
build-backend = "poetry.core.masonry.api"
6242

63-
[tool.isort]
64-
multi_line_output = 3
65-
include_trailing_comma = true
66-
force_grid_wrap = 0
67-
use_parentheses = true
68-
line_length = 79
69-
7043
[tool.black]
7144
line-length = 79
7245
target-version = ['py310']
7346
include = '\.pyi?$'
74-
exclude = '''
7547

76-
(
77-
/(
78-
\.eggs # exclude a few common directories in the
79-
| \.git # root of the project
80-
| \.hg
81-
| \.mypy_cache
82-
| \.tox
83-
| \.venv
84-
| _build
85-
| buck-out
86-
| build
87-
| dist
88-
| docs
89-
)/
90-
| foo.py # also separately exclude a file named foo.py in
91-
# the root of the project
92-
)
93-
'''
48+
[tool.ruff]
49+
exclude = [
50+
"docs/",
51+
".git",
52+
".nox",
53+
"__pycache__",
54+
"docs/source/conf.py",
55+
"old",
56+
"build",
57+
"dist",
58+
]
59+
ignore = ["E501"]
60+
line-length = 79
61+
select = [
62+
"C9",
63+
"E",
64+
"F",
65+
"W",
66+
"D",
67+
"G",
68+
"A",
69+
"PT",
70+
"S",
71+
"B",
72+
"ANN",
73+
"SIM",
74+
"I",
75+
"N",
76+
]
77+
78+
79+
[tool.ruff.mccabe]
80+
max-complexity = 10
81+
82+
[tool.ruff.pydocstyle]
83+
convention = "google"
84+
85+
[tool.ruff.per-file-ignores]
86+
"tests/*" = ["S101"]
9487

9588
[tool.pytest.ini_options]
9689
minversion = "6.0"
9790
addopts = """
9891
--verbose \
9992
--maxfail=1 \
100-
--flake8 \
10193
--reverse \
10294
--color=yes \
10395
--cov={{cookiecutter.package_name}} \
10496
--html=docs/pytest_report.html \
10597
--self-contained-html \
106-
--cov-fail-under=100 \
98+
--cov-fail-under={{cookiecutter.minimum_coverage}} \
10799
--cov-report term-missing \
108100
--cov-report html:docs/cov-report \
109101
--doctest-modules \
@@ -129,26 +121,15 @@ exclude_lines = [
129121
"if __name__ == .__main__.:"
130122
]
131123

132-
[tool.mypy]
133-
warn_return_any = true
134-
warn_unused_configs = true
135-
warn_redundant_casts = true
136-
disallow_untyped_defs = true
137-
disallow_any_generics = true
138-
disallow_incomplete_defs = true
139-
no_implicit_optional = true
140-
warn_unused_ignores = true
141-
show_error_context = true
142-
error_summary = true
143-
pretty = true
144-
145124
[tool.poe.tasks]
146125
install = "poetry install --only main"
147126
install-dev = "poetry install"
148127
run = "python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}"
149128
test = "pytest"
150129
pre-commit = "pre-commit run --all-files"
151-
lint = "flake8"
130+
lint-ruff = "ruff check **/*.py --fix"
131+
lint-black = "black **/*.py"
132+
lint = ["lint-black", "lint-ruff"]
152133
doc = "mkdocs serve --use-directory-urls -f docs/mkdocs.yaml"
153134
doc-html = "mkdocs build --no-directory-urls -f docs/mkdocs.yaml"
154135
doc-publish = """mkdocs gh-deploy \
@@ -171,4 +152,3 @@ args = [
171152
{ name = "build-platform", default = "linux/amd64" },
172153
{ name = "target", default = "prod" },
173154
]
174-

{{cookiecutter.project_slug}}/tests/scenarios/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ def pytest_configure(config: pytest.Config) -> None:
2121
2222
"""
2323
conftest_dir = Path(__file__).parent
24-
caller_module_path = get_caller_module_path()
25-
features_base_dir = get_features_base_dir(caller_module_path)
26-
features = get_features([features_base_dir])
24+
caller_module_path = Path(get_caller_module_path())
25+
features_base_dir = Path(get_features_base_dir(caller_module_path))
26+
if features_base_dir.exists():
27+
features = get_features([features_base_dir])
28+
else:
29+
features = []
2730

2831
for feat in features:
2932

{{cookiecutter.project_slug}}/tests/{{cookiecutter.package_name}}_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This file contains examples of how to write tests using pytest!
1+
{%- if cookiecutter.include_examples == "true" -%}"""This file contains examples of how to write tests using pytest!
22
33
Some good practices for writting great Python tests:
44
@@ -95,3 +95,5 @@ def test_divide_error(
9595
"""
9696
with pytest.raises(expected):
9797
m.Calculator.divide(a, b)
98+
{%- elif cookiecutter.include_examples != "true" -%}
99+
"""Pytest test module."""{% endif %}

{{cookiecutter.project_slug}}/{{cookiecutter.package_name}}/{{cookiecutter.module_name}}.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
{%- if cookiecutter.include_examples == "true" -%}
12
"""Module Docstring."""
23

34
import logging
45

56
# TODO({{cookiecutter.full_name}}): Check how to write todos!
67
# https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/issues/1337
78

8-
logger = logging.getLogger("test")
9+
logger = logging.getLogger("{{cookiecutter.module_name}}")
910
logger.info("This is a {word}", extra={"word": "Log"})
1011

1112

@@ -43,3 +44,13 @@ def divide(a: float, b: float) -> float:
4344

4445
if __name__ == "__main__":
4546
print("RUNNING!")
47+
{%- elif cookiecutter.include_examples != "true" -%}
48+
"""Module Docstring."""
49+
50+
import logging
51+
52+
logger = logging.getLogger("{{cookiecutter.module_name}}")
53+
54+
55+
if __name__ == "__main__":
56+
print("RUNNING!"){% endif %}

0 commit comments

Comments
 (0)