From b72e5b2c2a081d1901aa69702b78612c23ee5609 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 17 Jan 2025 19:45:23 +0000 Subject: [PATCH] Disable PLR0133 in pre/post commit hooks We seem to compare 2 constants but seem strings are in fact interpolated in Jinja. https://docs.astral.sh/ruff/rules/comparison-of-constant/ --- hooks/post_gen_project.py | 23 ++++++++++++----------- hooks/pre_gen_project.py | 7 ++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 64fb7d7435..35b8b5f15d 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,3 +1,4 @@ +# ruff: noqa: PLR0133 import json import os import random @@ -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 @@ -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": @@ -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": @@ -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, @@ -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": diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 1c8b738995..de2f87e3e6 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -1,3 +1,4 @@ +# ruff: noqa: PLR0133 import sys TERMINATOR = "\x1b[0m" @@ -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)