From 0baa147ebac44b82a106506797038b7c14468a39 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Sat, 15 Mar 2025 10:17:40 +0000 Subject: [PATCH] Fix Ruff errors --- {{cookiecutter.project_slug}}/config/asgi.py | 6 +--- {{cookiecutter.project_slug}}/config/urls.py | 6 ++-- {{cookiecutter.project_slug}}/config/wsgi.py | 8 ----- {{cookiecutter.project_slug}}/docs/conf.py | 7 +++-- {{cookiecutter.project_slug}}/manage.py | 30 +++++++++---------- .../merge_production_dotenvs_in_dotenv.py | 1 - 6 files changed, 23 insertions(+), 35 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/asgi.py b/{{cookiecutter.project_slug}}/config/asgi.py index edfffbbc5..302db2613 100644 --- a/{{cookiecutter.project_slug}}/config/asgi.py +++ b/{{cookiecutter.project_slug}}/config/asgi.py @@ -1,4 +1,3 @@ -# ruff: noqa """ ASGI config for {{ cookiecutter.project_name }} project. @@ -25,12 +24,9 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") # This application object is used by any ASGI server configured to use this file. django_application = get_asgi_application() -# Apply ASGI middleware here. -# from helloworld.asgi import HelloWorldApplication -# application = HelloWorldApplication(application) # Import websocket application here, so apps from django_application are loaded first -from config.websocket import websocket_application +from config.websocket import websocket_application # noqa: E402 async def application(scope, receive, send): diff --git a/{{cookiecutter.project_slug}}/config/urls.py b/{{cookiecutter.project_slug}}/config/urls.py index aca4352e6..8f9b5e426 100644 --- a/{{cookiecutter.project_slug}}/config/urls.py +++ b/{{cookiecutter.project_slug}}/config/urls.py @@ -1,4 +1,3 @@ -# ruff: noqa from django.conf import settings from django.conf.urls.static import static from django.contrib import admin @@ -77,4 +76,7 @@ if settings.DEBUG: if "debug_toolbar" in settings.INSTALLED_APPS: import debug_toolbar - urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns + urlpatterns = [ + path("__debug__/", include(debug_toolbar.urls)), + *urlpatterns, + ] diff --git a/{{cookiecutter.project_slug}}/config/wsgi.py b/{{cookiecutter.project_slug}}/config/wsgi.py index 73a6cddcb..cc82dd7f3 100644 --- a/{{cookiecutter.project_slug}}/config/wsgi.py +++ b/{{cookiecutter.project_slug}}/config/wsgi.py @@ -1,4 +1,3 @@ -# ruff: noqa """ WSGI config for {{ cookiecutter.project_name }} project. @@ -25,16 +24,9 @@ from django.core.wsgi import get_wsgi_application # {{ cookiecutter.project_slug }} directory. BASE_DIR = Path(__file__).resolve(strict=True).parent.parent sys.path.append(str(BASE_DIR / "{{ cookiecutter.project_slug }}")) -# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks -# if running multiple sites in the same mod_wsgi process. To fix this, use -# mod_wsgi daemon mode with each site in its own daemon process, or use -# os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. application = get_wsgi_application() -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application) diff --git a/{{cookiecutter.project_slug}}/docs/conf.py b/{{cookiecutter.project_slug}}/docs/conf.py index 31a828fe5..02bd02a0c 100644 --- a/{{cookiecutter.project_slug}}/docs/conf.py +++ b/{{cookiecutter.project_slug}}/docs/conf.py @@ -1,4 +1,4 @@ -# ruff: noqa +# ruff: noqa: ERA001, PTH100 # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full @@ -13,9 +13,10 @@ import os import sys + import django -if os.getenv("READTHEDOCS", default=False) == "True": +if os.getenv("READTHEDOCS", default="False") == "True": sys.path.insert(0, os.path.abspath("..")) os.environ["DJANGO_READ_DOT_ENV_FILE"] = "True" os.environ["USE_DOCKER"] = "no" @@ -32,7 +33,7 @@ django.setup() # -- Project information ----------------------------------------------------- project = "{{ cookiecutter.project_name }}" -copyright = """{% now 'utc', '%Y' %}, {{ cookiecutter.author_name }}""" +copyright = """{% now 'utc', '%Y' %}, {{ cookiecutter.author_name }}""" # noqa: A001 author = "{{ cookiecutter.author_name }}" diff --git a/{{cookiecutter.project_slug}}/manage.py b/{{cookiecutter.project_slug}}/manage.py index a39871814..d6c4f110f 100755 --- a/{{cookiecutter.project_slug}}/manage.py +++ b/{{cookiecutter.project_slug}}/manage.py @@ -1,28 +1,22 @@ #!/usr/bin/env python -# ruff: noqa +"""Django's command-line utility for administrative tasks.""" import os import sys from pathlib import Path -if __name__ == "__main__": + +def main(): + """Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") try: from django.core.management import execute_from_command_line - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django - except ImportError: - 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?" - ) - - raise + except ImportError as exc: + raise ImportError( # noqa: TRY003 + "Couldn't import Django. Are you sure it's installed and " # noqa: EM101 + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?", + ) from exc # This allows easy placement of apps within the interior # {{ cookiecutter.project_slug }} directory. @@ -30,3 +24,7 @@ if __name__ == "__main__": sys.path.append(str(current_path / "{{ cookiecutter.project_slug }}")) execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py b/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py index c83ed7166..35139fb2e 100644 --- a/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py +++ b/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py @@ -1,4 +1,3 @@ -# ruff: noqa import os from collections.abc import Sequence from pathlib import Path