From fcffee3d540a14f93d3a7d22b09cf341a61a9c3b Mon Sep 17 00:00:00 2001 From: Eugene Oliveros Date: Sun, 7 Apr 2024 00:43:37 +0800 Subject: [PATCH] fix: remove reorder-python-imports I'm glad that I discovered this issue sooner. I really liked reorder-python-imports but it was impossible to make it work with ruff and/or black. The one small issue I had was ruff was adding a new line below a docstring. While reorder-python-imports removes the new line. For context: - https://github.com/asottile/reorder-python-imports/pull/370 - https://github.com/asottile/reorder-python-imports/issues/366 - https://github.com/psf/black/issues/4175 --- .pre-commit-config.yaml | 5 ----- manage.py-tpl | 5 +++-- pyproject.toml | 24 ++++++++++++++---------- src/project_name/asgi.py-tpl | 2 +- src/project_name/conf/settings.py-tpl | 22 ++++++++++++++++------ src/project_name/conf/urls.py-tpl | 1 + src/project_name/wsgi.py-tpl | 1 + 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb3c3f6..ec85c40 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,8 +21,3 @@ repos: args: - --fix - id: ruff-format - -- repo: https://github.com/asottile/reorder_python_imports - rev: v3.12.0 - hooks: - - id: reorder-python-imports diff --git a/manage.py-tpl b/manage.py-tpl index 6697788..da02043 100755 --- a/manage.py-tpl +++ b/manage.py-tpl @@ -2,6 +2,7 @@ import os import sys + def main(): """ Run administrative tasks. @@ -12,8 +13,8 @@ def main(): except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" + 'available on your PYTHONPATH environment variable? Did you ' + 'forget to activate a virtual environment?' ) from exc execute_from_command_line(sys.argv) diff --git a/pyproject.toml b/pyproject.toml index 870c94f..d792968 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,16 +58,20 @@ quote-style = 'single' [tool.ruff.lint] select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "UP", # pyupgrade + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "UP", # pyupgrade ] ignore = [ - "E501", # line too long, handled by black - "B008", # do not perform function calls in argument defaults - "C901", # too complex - "W191", # indentation contains tabs + "E501", # line too long, handled by black + "B008", # do not perform function calls in argument defaults + "C901", # too complex + "W191", # indentation contains tabs ] + +[tool.ruff.lint.isort] +force-single-line = true diff --git a/src/project_name/asgi.py-tpl b/src/project_name/asgi.py-tpl index 36f147f..9fbf067 100644 --- a/src/project_name/asgi.py-tpl +++ b/src/project_name/asgi.py-tpl @@ -6,6 +6,7 @@ It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/asgi/ """ + import os from django.core.asgi import get_asgi_application @@ -13,4 +14,3 @@ from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.conf.settings') application = get_asgi_application() - diff --git a/src/project_name/conf/settings.py-tpl b/src/project_name/conf/settings.py-tpl index 7e6afbe..db0c593 100644 --- a/src/project_name/conf/settings.py-tpl +++ b/src/project_name/conf/settings.py-tpl @@ -9,10 +9,11 @@ https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ """ + from pathlib import Path -from decouple import config from decouple import Csv +from decouple import config # Build paths inside the project like this: str(BASE_DIR / "subdir") BASE_DIR = Path(__file__).resolve().parent.parent @@ -23,7 +24,10 @@ PROJECT_DIR = BASE_DIR.parent.parent # See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('DJANGO_SECRET_KEY', default='{{ secret_key }}') +SECRET_KEY = config( + 'DJANGO_SECRET_KEY', + default='{{ secret_key }}', +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config('DJANGO_DEBUG', cast=bool, default=True) @@ -34,7 +38,11 @@ INTERNAL_IPS = ['localhost', '127.0.0.1', '[::1]'] # List of strings representing the host/domain names that this site can serve # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#allowed-hosts -ALLOWED_HOSTS = config('DJANGO_ALLOWED_HOSTS', cast=Csv(), default='127.0.0.1,localhost') +ALLOWED_HOSTS = config( + 'DJANGO_ALLOWED_HOSTS', + cast=Csv(), + default='127.0.0.1,localhost', +) # Application definition @@ -100,7 +108,9 @@ DATABASES = { # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ - {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator' + }, {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'}, {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'}, {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}, @@ -126,9 +136,9 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/ -STATIC_URL = config('DJANGO_STATIC_URL', default="/static/") +STATIC_URL = config('DJANGO_STATIC_URL', default='/static/') -STATIC_ROOT = config('DJANGO_STATIC_ROOT', default=str(PROJECT_DIR / "staticfiles")) +STATIC_ROOT = config('DJANGO_STATIC_ROOT', default=str(PROJECT_DIR / 'staticfiles')) STATICFILES_DIRS = (str(BASE_DIR / 'static'),) diff --git a/src/project_name/conf/urls.py-tpl b/src/project_name/conf/urls.py-tpl index 1791aab..4e5028c 100644 --- a/src/project_name/conf/urls.py-tpl +++ b/src/project_name/conf/urls.py-tpl @@ -16,6 +16,7 @@ Examples: 2. Add a URL to urlpatterns: path('blog/', include('{{ project_name }}.apps.blog.urls')) """ + from django.conf import settings from django.contrib import admin from django.urls import include diff --git a/src/project_name/wsgi.py-tpl b/src/project_name/wsgi.py-tpl index 4fff403..70053c6 100644 --- a/src/project_name/wsgi.py-tpl +++ b/src/project_name/wsgi.py-tpl @@ -6,6 +6,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/wsgi/ """ + import os from django.core.wsgi import get_wsgi_application