From 40ab2a04efdb48514a33c710ab230731bfc8eb99 Mon Sep 17 00:00:00 2001 From: Tobi DEGNON Date: Fri, 12 Jan 2024 00:49:02 +0100 Subject: [PATCH] fix: broken pre-commit upon project initialization --- docs/images/project-tree.svg | 162 +++++++++--------- src/falco/__about__.py | 2 +- .../project_name/.pre-commit-config.yaml | 86 +++++----- src/falco_blueprints/project_name/README.md | 3 + .../users/migrations/0001_initial.py | 42 +---- .../project_name/project_name/users/models.py | 2 +- .../project_name/pyproject.toml | 118 ++++++------- 7 files changed, 194 insertions(+), 221 deletions(-) diff --git a/docs/images/project-tree.svg b/docs/images/project-tree.svg index 498aae3d..bb6130dc 100644 --- a/docs/images/project-tree.svg +++ b/docs/images/project-tree.svg @@ -19,135 +19,135 @@ font-weight: 700; } - .terminal-2577673104-matrix { + .terminal-4175178640-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-2577673104-title { + .terminal-4175178640-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-2577673104-r1 { fill: #d9d9d9 } + .terminal-4175178640-r1 { fill: #d9d9d9 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -159,47 +159,47 @@ - + - - $ tree -L 3 src/falco_blueprints/project_name -src/falco_blueprints/project_name -├── README.md -├── config -│   ├── __init__.py -│   ├── asgi.py -│   ├── settings.py -│   ├── urls.py -│   └── wsgi.py -├── deploy -│   ├── Dockerfile -│   ├── entrypoint.sh -│   └── gunicorn.conf.py -├── manage.py -├── playground.ipynb -├── project_name -│   ├── __init__.py -│   ├── core -│   │   ├── __init__.py -│   │   └── apps.py -│   ├── static -│   │   └── vendors -│   ├── templates -│   │   ├── base.html -│   │   └── home.html -│   └── users -│       ├── __init__.py -│       ├── admin.py -│       ├── apps.py -│       ├── forms.py -│       ├── migrations -│       └── models.py -├── pyproject.toml -└── tests -    ├── __init__.py -    └── test_assert_true.py - -11 directories, 24 files + + $ tree -L 3 src/falco_blueprints/project_name +src/falco_blueprints/project_name +├── config +│   ├── asgi.py +│   ├── __init__.py +│   ├── settings.py +│   ├── urls.py +│   └── wsgi.py +├── deploy +│   ├── Dockerfile +│   ├── entrypoint.sh +│   └── gunicorn.conf.py +├── manage.py +├── playground.ipynb +├── project_name +│   ├── core +│   │   ├── apps.py +│   │   └── __init__.py +│   ├── __init__.py +│   ├── static +│   │   └── vendors +│   ├── templates +│   │   ├── base.html +│   │   └── home.html +│   └── users +│       ├── admin.py +│       ├── apps.py +│       ├── forms.py +│       ├── __init__.py +│       ├── migrations +│       └── models.py +├── pyproject.toml +├── README.md +└── tests +    ├── __init__.py +    └── test_assert_true.py + +11 directories, 24 files diff --git a/src/falco/__about__.py b/src/falco/__about__.py index 91d3df2c..c17935e1 100644 --- a/src/falco/__about__.py +++ b/src/falco/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Tobi DEGNON # # SPDX-License-Identifier: MIT -__version__ = "0.2.2" +__version__ = "0.2.3" diff --git a/src/falco_blueprints/project_name/.pre-commit-config.yaml b/src/falco_blueprints/project_name/.pre-commit-config.yaml index 84d59341..8eb56e0d 100644 --- a/src/falco_blueprints/project_name/.pre-commit-config.yaml +++ b/src/falco_blueprints/project_name/.pre-commit-config.yaml @@ -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 @@ -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$ diff --git a/src/falco_blueprints/project_name/README.md b/src/falco_blueprints/project_name/README.md index 23846ba5..b43ba959 100644 --- a/src/falco_blueprints/project_name/README.md +++ b/src/falco_blueprints/project_name/README.md @@ -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 @@ -54,3 +56,4 @@ hr runserver # if you've added falco-cli as a dependency to your project falco work ``` + diff --git a/src/falco_blueprints/project_name/project_name/users/migrations/0001_initial.py b/src/falco_blueprints/project_name/project_name/users/migrations/0001_initial.py index 5698abe9..5eb38c9c 100644 --- a/src/falco_blueprints/project_name/project_name/users/migrations/0001_initial.py +++ b/src/falco_blueprints/project_name/project_name/users/migrations/0001_initial.py @@ -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 = [ @@ -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( @@ -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", ), ), @@ -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( diff --git a/src/falco_blueprints/project_name/project_name/users/models.py b/src/falco_blueprints/project_name/project_name/users/models.py index 1ab685c6..821a628a 100644 --- a/src/falco_blueprints/project_name/project_name/users/models.py +++ b/src/falco_blueprints/project_name/project_name/users/models.py @@ -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 diff --git a/src/falco_blueprints/project_name/pyproject.toml b/src/falco_blueprints/project_name/pyproject.toml index f5d7d08a..e3f04fde 100644 --- a/src/falco_blueprints/project_name/pyproject.toml +++ b/src/falco_blueprints/project_name/pyproject.toml @@ -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] @@ -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}"] @@ -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" @@ -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