Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
roushikk opened this issue Apr 4, 2024 · 1 comment · Fixed by #5068
Closed

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

roushikk opened this issue Apr 4, 2024 · 1 comment · Fixed by #5068
Labels

Comments

@roushikk
Copy link

roushikk commented Apr 4, 2024

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"
    }
@browniebroke
Copy link
Member

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.

You were pretty close, I think. This STATIC_URL is coming from the star import when these conditions are met, otherwise it's defined in the same file. Attempted a fix here: #5068

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants