Skip to content

Commit

Permalink
Disable PLR0133 in pre/post commit hooks
Browse files Browse the repository at this point in the history
We seem to compare 2 constants but seem strings are in fact interpolated in Jinja.

https://docs.astral.sh/ruff/rules/comparison-of-constant/
  • Loading branch information
browniebroke committed Jan 17, 2025
1 parent b02f9b4 commit b72e5b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
23 changes: 12 additions & 11 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: PLR0133
import json
import os
import random
Expand Down Expand Up @@ -73,7 +74,7 @@ def remove_docker_files():
]
for file_name in file_names:
os.remove(file_name) # noqa: PTH107
if "{{ cookiecutter.editor }}" == "PyCharm": # noqa: PLR0133
if "{{ cookiecutter.editor }}" == "PyCharm":
file_names = ["docker_compose_up_django.xml", "docker_compose_up_docs.xml"]
for file_name in file_names:
os.remove(os.path.join(".idea", "runConfigurations", file_name)) # noqa: PTH107, PTH118
Expand Down Expand Up @@ -430,15 +431,15 @@ def main(): # noqa: C901, PLR0912, PLR0915
)
set_flags_in_settings_files()

if "{{ cookiecutter.open_source_license }}" == "Not open source": # noqa: PLR0133
if "{{ cookiecutter.open_source_license }}" == "Not open source":
remove_open_source_files()
if "{{ cookiecutter.open_source_license}}" != "GPLv3": # noqa: PLR0133
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
remove_gplv3_files()

if "{{ cookiecutter.username_type }}" == "username": # noqa: PLR0133
if "{{ cookiecutter.username_type }}" == "username":
remove_custom_user_manager_files()

if "{{ cookiecutter.editor }}" != "PyCharm": # noqa: PLR0133
if "{{ cookiecutter.editor }}" != "PyCharm":
remove_pycharm_files()

if "{{ cookiecutter.use_docker }}".lower() == "y":
Expand All @@ -448,7 +449,7 @@ def main(): # noqa: C901, PLR0912, PLR0915
else:
remove_docker_files()

if "{{ cookiecutter.use_docker }}".lower() == "y" and "{{ cookiecutter.cloud_provider}}" != "AWS": # noqa: PLR0133
if "{{ cookiecutter.use_docker }}".lower() == "y" and "{{ cookiecutter.cloud_provider}}" != "AWS":
remove_aws_dockerfile()

if "{{ cookiecutter.use_heroku }}".lower() == "n":
Expand Down Expand Up @@ -483,7 +484,7 @@ def main(): # noqa: C901, PLR0912, PLR0915
use_async=("{{ cookiecutter.use_async }}".lower() == "y"),
)

if "{{ cookiecutter.cloud_provider }}" == "None" and "{{ cookiecutter.use_docker }}".lower() == "n": # noqa: PLR0133
if "{{ cookiecutter.cloud_provider }}" == "None" and "{{ cookiecutter.use_docker }}".lower() == "n":
print(
WARNING + "You chose to not use any cloud providers nor Docker, "
"media files won't be served in production." + TERMINATOR,
Expand All @@ -494,16 +495,16 @@ def main(): # noqa: C901, PLR0912, PLR0915
if "{{ cookiecutter.use_docker }}".lower() == "y":
remove_celery_compose_dirs()

if "{{ cookiecutter.ci_tool }}" != "Travis": # noqa: PLR0133
if "{{ cookiecutter.ci_tool }}" != "Travis":
remove_dottravisyml_file()

if "{{ cookiecutter.ci_tool }}" != "Gitlab": # noqa: PLR0133
if "{{ cookiecutter.ci_tool }}" != "Gitlab":
remove_dotgitlabciyml_file()

if "{{ cookiecutter.ci_tool }}" != "Github": # noqa: PLR0133
if "{{ cookiecutter.ci_tool }}" != "Github":
remove_dotgithub_folder()

if "{{ cookiecutter.ci_tool }}" != "Drone": # noqa: PLR0133
if "{{ cookiecutter.ci_tool }}" != "Drone":
remove_dotdrone_file()

if "{{ cookiecutter.use_drf }}".lower() == "n":
Expand Down
7 changes: 4 additions & 3 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: PLR0133
import sys

TERMINATOR = "\x1b[0m"
Expand All @@ -20,12 +21,12 @@

assert project_slug == project_slug.lower(), f"'{project_slug}' project slug should be all lowercase"

assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name." # noqa: PLR0133
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."

if "{{ cookiecutter.use_whitenoise }}".lower() == "n" and "{{ cookiecutter.cloud_provider }}" == "None": # noqa: PLR0133
if "{{ cookiecutter.use_whitenoise }}".lower() == "n" and "{{ cookiecutter.cloud_provider }}" == "None":
print("You should either use Whitenoise or select a Cloud Provider to serve static files")
sys.exit(1)

if "{{ cookiecutter.mail_service }}" == "Amazon SES" and "{{ cookiecutter.cloud_provider }}" != "AWS": # noqa: PLR0133
if "{{ cookiecutter.mail_service }}" == "Amazon SES" and "{{ cookiecutter.cloud_provider }}" != "AWS":
print("You should either use AWS or select a different Mail Service for sending emails.")
sys.exit(1)

0 comments on commit b72e5b2

Please sign in to comment.