Skip to content

Commit

Permalink
fix: broken pre-commit upon project initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Jan 11, 2024
1 parent 2d8fe25 commit 40ab2a0
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 221 deletions.
162 changes: 81 additions & 81 deletions docs/images/project-tree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/falco/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present Tobi DEGNON <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "0.2.2"
__version__ = "0.2.3"
86 changes: 45 additions & 41 deletions src/falco_blueprints/project_name/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.11
python: python3.11 # TODO: change this to your system's Python version

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -17,52 +17,56 @@ repos:
- id: check-symlinks
- id: check-json

- repo: local
- repo: https://github.com/myint/autoflake
rev: v2.2.1
hooks:
- id: pyright
name: Run pyright
entry: hatch run lint:run-pyright
language: system
files: \.py$
- id: autoflake
exclude: .*/__init__.py
args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables

- id: ruff
name: Run ruff lint
entry: hatch run lint:run-ruff
language: system
files: \.py$
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black

- id: ruff-format
name: Run run format
entry: hatch run lint:run-format
language: system
files: \.py$
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args:
- "--application-directories={{ project_name }}"

- id: ruff-format
name: Run run reorder-python-imports
entry: hatch run lint:run-reorder-python-imports
language: system
files: \.py$
- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.34.1
hooks:
- id: djlint-reformat-django
- id: djlint-django

- id: curlylint
name: Run curlylint
entry: hatch run lint:run-curlylint
language: system
files: \.html$
- repo: https://github.com/asottile/pyupgrade
rev: 'v3.15.0'
hooks:
- id: pyupgrade

- id: djhtml
name: Run djhtml
entry: hatch run lint:djhtml
language: system
files: \.html$
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.15.0"
hooks:
- id: django-upgrade
args: [--target-version, "5.0"]

- id: pyupgrade
name: Run pyupgrade
entry: hatch run lint:run-all-pyupgrade
language: system
files: \.py$
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.6.0"
hooks:
- id: pyproject-fmt

- id: django-upgrade
name: Run django-upgrade
entry: hatch run lint:run-all-django-upgrade
- repo: local
hooks:
- id: mypy
name: Run mypt
entry: hatch run mypy
language: system
files: \.py$
3 changes: 3 additions & 0 deletions src/falco_blueprints/project_name/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ hatch shell
git init && pre-commit install
```

Ensure that the Python version specified in your `.pre-commit-config.yaml` file aligns with the Python version installed on your system.

### Create a `.env` file

```shell
Expand Down Expand Up @@ -54,3 +56,4 @@ hr runserver
# if you've added falco-cli as a dependency to your project
falco work
```

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Generated by Django 4.1.3 on 2022-11-20 16:46
# Generated by Django 5.0.1 on 2024-01-11 23:44
import django.utils.timezone
from django.db import migrations
from django.db import models

import {{ project_name }}.users.models
import {{project_name}}.users.models
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand All @@ -18,22 +15,9 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name="User",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
("last_login", models.DateTimeField(blank=True, null=True, verbose_name="last login")),
(
"is_superuser",
models.BooleanField(
Expand All @@ -46,7 +30,7 @@ class Migration(migrations.Migration):
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into the admin site.",
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
Expand All @@ -58,18 +42,8 @@ class Migration(migrations.Migration):
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="email address"
),
),
("date_joined", models.DateTimeField(default=django.utils.timezone.now, verbose_name="date joined")),
("email", models.EmailField(max_length=254, unique=True, verbose_name="email address")),
(
"groups",
models.ManyToManyField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _create_user(self, email: str, password: str | None, **extra_fields):
raise ValueError("The given email must be set")
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.password = make_password(password)
user.password = make_password(password) # type: ignore
user.save(using=self._db)
return user

Expand Down
118 changes: 55 additions & 63 deletions src/falco_blueprints/project_name/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
requires = [
"hatchling",
]

[project]
name = "{{ project_name }}"
version = "0.1.0"
description = ''
description = ""
readme = "README.md"
requires-python = ">=3.11"
authors = [{ name = "{{ author_name }}", email = "{{ author_email }}" }]
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"Pillow",
"hiredis",
"redis",
"boto3",
"gunicorn",
"sentry-sdk",
"whitenoise",
"psycopg[binary]",
"crispy-tailwind",
"django[argon2]",
"django-environ",
"django-model-utils",
"django-allauth",
"django-template-partials",
"django-tailwind-cli",
"django-extensions",
"django-htmx",
"django-anymail",
"django-browser-reload",
"django-debug-toolbar",
"django-environ",
"django-extensions",
"django-fastdev",
"django-htmx",
"django-model-utils",
"django-tailwind-cli",
"django-template-partials",
"gunicorn",
"hiredis",
"Pillow",
"psycopg[binary]",
"redis",
"sentry-sdk",
"whitenoise",
]

[tool.hatch.env]
Expand All @@ -43,7 +50,7 @@ type = "pip-compile"
pip-compile-constraint = "default"
pip-compile-installer = "pip-sync"
lock-filename = "requirements.txt"
dependencies = ["dj-notebook>=0.6.1", "Werkzeug[watchdog]>=3.0.1", "pre-commit"]
dependencies = ["dj-notebook>=0.6.1", "Werkzeug[watchdog]>=3.0.1", "pre-commit", "django-stubs[compatible-mypy]"]

[tool.hatch.envs.default.scripts]
runserver = ["migrate", "python manage.py tailwind runserver {args}"]
Expand Down Expand Up @@ -71,42 +78,21 @@ test-cov = "coverage run -m pytest {args:tests}"
cov-report = ["- coverage combine", "coverage report"]
cov = ["test-cov", "cov-report"]

[tool.hatch.envs.lint]
dependencies = [
"mypy",
"django-stubs",
"curlylint",
"reorder-python-imports",
"djhtml",
"ruff",
"pyupgrade",
"django-upgrade",
"autoflake",
]
[tool.black]
line-length = 120
target-version = ['py311']

[tool.hatch.envs.lint.scripts]
run-mypy = "mypy {args:.}"
run-format = "hatch fmt --formatter"
run-autoflake = "autoflake --in-place --remove-all-unused-imports --remove-unused-variables --expand-star-imports --exclude=.*/__init__.py {args:.}"
run-reorder-python-imports = "reorder-python-imports config/*.py {args:./*/*/*.py}"
run-ruff = "ruff check --quiet --fix --exit-non-zero-on-fix {args:.}"
run-curlylint = "curlylint {args:.}"
run-djhtml = "djhtml --tabwidth 4 {args:.}"
run-pyupgrade = "pyupgrade --py311-plus {args}"
run-all-pyupgrade = "git ls-files -- '*.py' | xargs pyupgrade --py311-plus"
run-django-upgrade = "django-upgrade --target-version 4.2 {args}"
run-all-django-upgrade = "git ls-files -- '*.py' | xargs django-upgrade --target-version 4.2"
python = [
"run-pyright",
"run-format",
"run-reorder-python-imports",
"run-autoflake",
"run-ruff",
"run-all-pyupgrade",
"run-all-django-upgrade",
]
templates = ["run-curlylint", "run-djhtml"]
all = ["python", "templates"]
[tool.coverage.run]
source_pkgs = ["{{ project_name }}", "tests"]
branch = true
parallel = true

[tool.coverage.paths]
{{ project_name }} = ["*/{{ project_name }}/{{ project_name }}"]
tests = ["tests", "*/{{ project_name }}/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[tool.mypy]
python_version = "3.11"
Expand Down Expand Up @@ -148,14 +134,20 @@ meta_viewport = true
no_autofocus = true
tabindex_no_positive = true

[tool.coverage.run]
source_pkgs = ["{{ project_name }}", "tests"]
branch = true
parallel = true

[tool.coverage.paths]
{{ project_name }} = ["*/{{ project_name }}/{{ project_name }}"]
tests = ["tests", "*/{{ project_name }}/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
[tool.djlint]
blank_line_after_tag = "load,extends"
close_void_tags = true
format_css = true
format_js = true
# TODO: remove T002 when fixed https://github.com/Riverside-Healthcare/djLint/issues/687
ignore = "H006,H030,H031,T002"
include = "H017,H035"
indent = 2
max_line_length = 120
profile = "django"

[tool.djlint.css]
indent_size = 2

[tool.djlint.js]
indent_size = 2

0 comments on commit 40ab2a0

Please sign in to comment.