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

Added pylint django migrations checker to the invoke pylint command. #183

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/183.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added pylint django migrations checker to the `invoke pylint` command.
23 changes: 21 additions & 2 deletions nautobot-app/{{ cookiecutter.project_slug }}/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",))
Expand Down
Loading