cookiecutter-django icon indicating copy to clipboard operation
cookiecutter-django copied to clipboard

ruff hook fails with F405 issue in config/settings/production.py

Open roushikk opened this issue 1 year ago • 0 comments

What happened?

When running pre-commit run --all-files on a newly created project, the ruff hook fails with the following error:

ruff.....................................................................Failed
- hook id: ruff
- exit code: 1

config/settings/production.py:108:16: F405 `STATIC_URL` may be undefined, or defined from star imports
Found 1 error.

EDIT: Line 108 of config/settings/production.py

COMPRESS_URL = STATIC_URL

What should've happened instead?

The ruff hook should pass

ruff.....................................................................Passed

Additional details

The issue is caused because STATIC_URL is not explicitly imported. The issue is easily fixed if we add the following line in config/settings/production.py:

from .base import STATIC_URL

EDIT: The issue only occurs if "cloud_provider" is set as "None". There's also an interesting line in config/settings/production.py:

COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %}{% endif %}

There's an if block in the template but nothing is enclosed in it. It might be a mistake but I do not know what is the purpose of this. Here's a link to the line: https://github.com/cookiecutter/cookiecutter-django/blob/831ce14ca320125b4176ed99b82956570789abf5/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/production.py#L288C26-L288C121

  • Host system configuration:

    • Version of cookiecutter CLI: 2.6.0

    • OS name and version:

      LSB Version:    n/a
      Distributor ID: NobaraLinux
      Description:    Nobara Linux 39 (KDE Plasma)
      Release:        39
      Codename:       n/a
      (Based on Fedora 39)
      
    • Python version: Python 3.12.2

    • Docker version (if using Docker): 26.0.0, build 2ae903e

    • docker compose version (if using Docker): v2.25.0

  • Options selected and/or replay file:

"cookiecutter": {
      "project_name": "narcissus",
      "project_slug": "narcissus",
      "description": "A place for me to be a narcissist",
      "author_name": "roushikk",
      "domain_name": "...",
      "email": "...",
      "version": "0.1.0",
      "open_source_license": "Not open source",
      "username_type": "email",
      "timezone": "UTC",
      "windows": "n",
      "editor": "VS Code",
      "use_docker": "y",
      "postgresql_version": "16",
      "cloud_provider": "None",
      "mail_service": "Other SMTP",
      "use_async": "y",
      "use_drf": "n",
      "frontend_pipeline": "Django Compressor",
      "use_celery": "y",
      "use_mailpit": "y",
      "use_sentry": "n",
      "use_whitenoise": "y",
      "use_heroku": "n",
      "ci_tool": "Github",
      "keep_local_envs_in_vcs": "y",
      "debug": "n",
      "_template": "https://github.com/cookiecutter/cookiecutter-django"
    }

roushikk avatar Apr 04 '24 19:04 roushikk