Introducing pylint-nautobot

We are happy to announce the release of a new tool in the Nautobot ecosystem. pylint-nautobot (check it out on GitHub) will help you adopt best practices for your Nautobot app and job code, as well as ensure your code is compatible with newer versions of Nautobot.

This pylint plugin already includes some rules to aid you in readying your code for the upcoming Nautbot 2.0 release, such as:

  • Ensuring you are importing functions and classes for App consumption from the correct places
  • Ensuring you have updated all of your usage of models that have been replaced by others

Installing the Plugin

The application is available as a Python package in PyPI and can be installed atop an existing Nautobot App using pip:

$ pip3 install pylint-nautobot

Once installed, the plugin needs to be enabled and configured in the pyproject.toml file:

# pyproject.toml
[tool.pylint.master]
load-plugins="pylint_nautobot"

[tool.pylint-nautobot]
supported_nautobot_version = [
  "1",  # Supporting 1.x.y
  "2",  # Supporting 2.x.y
]

Now, when running pylint, you should see those new rules in play. As an example, check out the following code:

$ cat faulty_file.py
from nautobot.dcim.models import Device, Platform, Region, Site, DeviceRole, DeviceType, Manufacturer, Rack, RackGroup
from nautobot.utilities.forms import SlugField

$ pylint faulty_file.py
************* Module faulty_module.faulty_file
faulty_module/faulty_file.py:1:0: E4214: Imports a model that has been replaced (dcim.Region -> dcim.Location). (nb-replaced-region)
faulty_module/faulty_file.py:1:0: E4215: Imports a model that has been replaced (dcim.Site -> dcim.Location). (nb-replaced-site)
faulty_module/faulty_file.py:1:0: E4211: Imports a model that has been replaced (dcim.DeviceRole -> extras.Role). (nb-replaced-device-role)
faulty_module/faulty_file.py:2:0: E4251: Import location has changed (nautobot.utilities.forms -> nautobot.core.forms). (nb-code-location-changed)

------------------------------------------------------------------
Your code has been rated at 7.90/10 (previous run: 7.90/10, +0.00)

Next Steps

New rules will continue to be added, some not tied to any specific release. These include ensuring you’re inheriting from the proper base classes, helping you discover simplifications you can make, and helping your apps behave just like core does. Just like other pylint rules though, you will be able to ignore rules that may not apply to your use case. Our intent is to capture in these rules any patterns you should apply during your app development so that deviations from best practices can be automatically detected.

We at Network to Code will also be using this pylint plugin in order to ensure our own Apps adhere to best practices.


Conclusion

As usual, we would like to hear your feedback. Feel free to reach out to us in the #nautobot channel on the Network to Code Slack Workspace!

-Leo & Cristian



ntc img
ntc img

Contact Us to Learn More

Share details about yourself & someone from our team will reach out to you ASAP!

Author