From f4befaea64ae698bda9b8b10abc357c10bd0615d Mon Sep 17 00:00:00 2001 From: Gary Snider <75227981+gsnider2195@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:41:19 -0700 Subject: [PATCH] Added pylint django migrations checker to the `invoke pylint` command. (#183) --- changes/183.added | 1 + .../{{ cookiecutter.project_slug }}/tasks.py | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 changes/183.added diff --git a/changes/183.added b/changes/183.added new file mode 100644 index 00000000..c411d614 --- /dev/null +++ b/changes/183.added @@ -0,0 +1 @@ +Added pylint django migrations checker to the `invoke pylint` command. diff --git a/nautobot-app/{{ cookiecutter.project_slug }}/tasks.py b/nautobot-app/{{ cookiecutter.project_slug }}/tasks.py index 83a15236..a9fb3eec 100644 --- a/nautobot-app/{{ cookiecutter.project_slug }}/tasks.py +++ b/nautobot-app/{{ cookiecutter.project_slug }}/tasks.py @@ -709,8 +709,27 @@ def hadolint(context): @task def pylint(context): """Run pylint code analysis.""" - command = 'pylint --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml {{ cookiecutter.app_name }}' - run_command(context, command) + exit_code = 0 + + base_pylint_command = 'pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml' + command = f"{base_pylint_command} {{ cookiecutter.app_name }}" + if not run_command(context, command, warn=True): + exit_code = 1 + + # run the pylint_django migrations checkers on the migrations directory, if one exists + migrations_dir = Path(__file__).absolute().parent / Path("{{ cookiecutter.app_name }}") / Path("migrations") + if migrations_dir.is_dir(): + migrations_pylint_command = ( + f"{base_pylint_command} --load-plugins=pylint_django.checkers.migrations" + " --disable=all --enable=fatal,new-db-field-with-default,missing-backwards-migration-callable" + " {{ cookiecutter.app_name }}.migrations" + ) + if not run_command(context, migrations_pylint_command, warn=True): + exit_code = 1 + else: + print("No migrations directory found, skipping migrations checks.") + + raise Exit(code=exit_code) @task(aliases=("a",))