nautobot / cookiecutter-nautobot-app

Cookiecutter template for creating new Nautobot Apps.
https://docs.nautobot.com/projects/cookiecutter-nautobot-app/en/latest/
Apache License 2.0
16 stars 5 forks source link

Enable the pylint-django migrations plugin #179

Closed gsnider2195 closed 1 month ago

gsnider2195 commented 1 month ago

https://github.com/pylint-dev/pylint-django?tab=readme-ov-file#additional-plugins

bryanculver commented 1 month ago

Justification: this would have caught the open issues we have in many of our Apps repos (such as: https://github.com/nautobot/nautobot-app-golden-config/issues/738) that call out missing reverse migrations.

The default value one is good too.

gsnider2195 commented 1 month ago

Today we're not actually running pylint against any of the migration files. If we enable pylint for these files we encounter some pylint rules that we probably don't want to deal with in migrations:

Using config file pyproject.toml
************* Module nautobot_dev_example.migrations.0001_initial
nautobot_dev_example/migrations/0001_initial.py:1:0: C0114: Missing module docstring (missing-module-docstring)
nautobot_dev_example/migrations/0001_initial.py:1:0: C0103: Module name "0001_initial" doesn't conform to snake_case naming style (invalid-name)
nautobot_dev_example/migrations/0001_initial.py:11:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nautobot_dev_example.migrations.0002_runpython
nautobot_dev_example/migrations/0002_runpython.py:1:0: C0114: Missing module docstring (missing-module-docstring)
nautobot_dev_example/migrations/0002_runpython.py:1:0: C0103: Module name "0002_runpython" doesn't conform to snake_case naming style (invalid-name)
nautobot_dev_example/migrations/0002_runpython.py:6:0: C0116: Missing function or method docstring (missing-function-docstring)
nautobot_dev_example/migrations/0002_runpython.py:10:0: C0115: Missing class docstring (missing-class-docstring)
nautobot_dev_example/migrations/0002_runpython.py:15:18: W5197: Always include backwards migration callable (missing-backwards-migration-callable)

As far as I can tell the global pylint config in the pyproject.toml allows you to either:

But it does not allow you to disable rules for specific files or directories. Our only option may be to run pylint twice, the second time only checking migrations and disabling some rules:

pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml nautobot_dev_example
pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml --module-rgx='^[0-9a-z_]{2,30}$' --disable=missing-module-docstring,missing-class-docstring,missing-function-docstring nautobot_dev_example.migrations
gsnider2195 commented 1 month ago

Instead of disabling rules, only enable the pylint django migrations checkers when checking migrations