Skip to content

Commit

Permalink
fix: remove reorder-python-imports
Browse files Browse the repository at this point in the history
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:

- asottile/reorder-python-imports#370
- asottile/reorder-python-imports#366
- psf/black#4175
  • Loading branch information
yujinyuz committed Apr 6, 2024
1 parent 2611979 commit fcffee3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -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
5 changes: 3 additions & 2 deletions manage.py-tpl
Expand Up @@ -2,6 +2,7 @@
import os
import sys


def main():
"""
Run administrative tasks.
Expand All @@ -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)

Expand Down
24 changes: 14 additions & 10 deletions pyproject.toml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/project_name/asgi.py-tpl
Expand Up @@ -6,11 +6,11 @@ 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

os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.conf.settings')

application = get_asgi_application()

22 changes: 16 additions & 6 deletions src/project_name/conf/settings.py-tpl
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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'},
Expand All @@ -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'),)

Expand Down
1 change: 1 addition & 0 deletions src/project_name/conf/urls.py-tpl
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/project_name/wsgi.py-tpl
Expand Up @@ -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
Expand Down

0 comments on commit fcffee3

Please sign in to comment.