Skip to content

Commit

Permalink
add copier template for pre-commit and lint codebase (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas authored Nov 30, 2023
1 parent 701e00d commit d0ed157
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 81 deletions.
9 changes: 9 additions & 0 deletions .copier-answers/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 418d39a
_src_path: https://github.com/westerveltco/pre-commit-template
django_version: 3.2
include_django: true
include_javascript: false
include_python: true
include_tailwind: false
python_version: 3.8
45 changes: 23 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.11
python: python3.8

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -11,39 +11,40 @@ repos:
- id: check-yaml

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.15.0
rev: "1.15.0"
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
args: [--target-version, "3.2"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: ruff-format

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
rev: v0.1.3
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: "1.16.0"
hooks:
- id: blacken-docs
alias: autoformat
additional_dependencies:
- black==22.12.0

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
- repo: https://github.com/rtts/djhtml
rev: "3.0.6"
hooks:
- id: djhtml
entry: djhtml --tabwidth 2
alias: autoformat

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
hooks:
- id: pretty-format-toml
args: [--autofix]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
hooks:
- id: prettier
# lint the following with prettier:
# - javascript
# - typescript
# - JSX/TSX
# - CSS
# - yaml
# ignore any minified code
files: '^(?!.*\.min\..*)(?P<name>[\w-]+(\.[\w-]+)*\.(js|jsx|ts|tsx|yml|yaml|css))$'
- id: validate-pyproject
16 changes: 16 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,19 @@ lint:

mypy:
python -m nox --reuse-existing-virtualenvs --session "mypy"

# ----------------------------------------------------------------------
# COPIER
# ----------------------------------------------------------------------

# create a copier answers file
copier-copy TEMPLATE_PATH DESTINATION_PATH=".":
pipx run copier copy {{ TEMPLATE_PATH }} {{ DESTINATION_PATH }}

# update the project using a copier answers file
copier-update ANSWERS_FILE *ARGS:
pipx run copier update --answers-file {{ ANSWERS_FILE }} {{ ARGS }}

# loop through all answers files and update the project using copier
@copier-update-all *ARGS:
for file in `ls .copier-answers/`; do just copier-update .copier-answers/$file "{{ ARGS }}"; done
107 changes: 48 additions & 59 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["hatchling"]

[project]
authors = [
{name = "Josh Thomas", email = "[email protected]"},
{name = "Josh Thomas", email = "[email protected]"}
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -24,13 +24,13 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: CPython"
]
dependencies = ["django>=3.2"]
description = "A simple, flexible, and extensible navigation menu for Django."
dynamic = ["version"]
keywords = []
license = "MIT"
license = {file = "LICENSE"}
name = "django-simple-nav"
readme = "README.md"
requires-python = ">=3.8"
Expand All @@ -49,7 +49,7 @@ dev = [
"pytest-django",
"pytest-randomly",
"pytest-reverse",
"pytest-xdist",
"pytest-xdist"
]
docs = [
"cogapp",
Expand All @@ -58,7 +58,7 @@ docs = [
"sphinx",
"sphinx-autobuild",
"sphinx-copybutton",
"sphinx-inline-tabs",
"sphinx-inline-tabs"
]
lint = ["pre-commit"]

Expand All @@ -67,37 +67,20 @@ Documentation = "https://django-simple-nav.westervelt.dev"
Issues = "https://github.com/westerveltco/django-simple-nav/issues"
Source = "https://github.com/westerveltco/django-simple-nav"

[tool.hatch.build]
exclude = [
".github/*",
".dockerfiles/*",
".dockerignore",
".editorconfig",
".pre-commit-config.yaml",
"Justfile",
"src/service/*",
]

[tool.hatch.build.targets.wheel]
packages = ["src/simple_nav"]

[tool.hatch.version]
path = "src/simple_nav/__init__.py"

[tool.bumpver]
commit = true
commit_message = ":bookmark: bump version {old_version} -> {new_version}"
current_version = "0.1.0dev0"
push = false # set to false for CI
push = false # set to false for CI
tag = false
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"

[tool.bumpver.file_patterns]
"src/simple_nav/__init__.py" = [
'__version__ = "{version}"',
'__version__ = "{version}"'
]
"tests/test_version.py" = [
'assert __version__ == "{version}"',
'assert __version__ == "{version}"'
]

[tool.coverage.paths]
Expand All @@ -109,22 +92,39 @@ fail_under = 85
[tool.coverage.run]
omit = [
"src/simple_nav/migrations/*",
"tests/*",
"tests/*"
]
source = ["simple_nav"]

[tool.django-stubs]
django_settings_module = "tests.settings"
strict_settings = false

[tool.hatch.build]
exclude = [
".github/*",
".dockerfiles/*",
".dockerignore",
".editorconfig",
".pre-commit-config.yaml",
"Justfile",
"src/service/*"
]

[tool.hatch.build.targets.wheel]
packages = ["src/simple_nav"]

[tool.hatch.version]
path = "src/simple_nav/__init__.py"

[tool.mypy]
check_untyped_defs = true
exclude = "docs/.*\\.py$"
mypy_path = "src/"
namespace_packages = false
check_untyped_defs = true
no_implicit_optional = true
plugins = [
"mypy_django_plugin.main",
"mypy_django_plugin.main"
]
warn_redundant_casts = true
warn_unused_configs = true
Expand All @@ -139,27 +139,16 @@ module = "tests.*"
ignore_missing_model_attributes = true

[tool.pytest.ini_options]
django_find_project = false
pythonpath = "src"
addopts = "--create-db -n auto --dist loadfile --doctest-modules"
django_find_project = false
norecursedirs = ".* bin build dist *.egg htmlcov logs node_modules templates venv"
python_files = "tests.py test_*.py *_tests.py"
pythonpath = "src"
testpaths = ["tests"]

[tool.ruff]
ignore = ["E501", "E741"] # temporary
select = [
"B", # flake8-bugbear
"E", # Pycodestyle
"F", # Pyflakes
"I", # isort
"UP", # pyupgrade
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "I"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
Expand All @@ -181,34 +170,34 @@ exclude = [
"migrations",
"node_modules",
"static",
"venv",
"venv"
]
extend-include = ["*.pyi?"]

per-file-ignores = {}

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "I"]
ignore = ["E501", "E741"] # temporary
indent-width = 4
# Same as Black.
line-length = 88
indent-width = 4

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

per-file-ignores = {}
select = [
"B", # flake8-bugbear
"E", # Pycodestyle
"F", # Pyflakes
"I", # isort
"UP" # pyupgrade
]
# Assume Python >3.8.
target-version = "py38"
unfixable = []

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
# magic-trailing-comma = "respect"

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Like Black, use double quotes for strings.
quote-style = "double"

[tool.ruff.isort]
force-single-line = true
Expand Down

0 comments on commit d0ed157

Please sign in to comment.