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

Pylint part 1 #2314

Merged
merged 16 commits into from
Aug 29, 2022
Merged

Pylint part 1 #2314

merged 16 commits into from
Aug 29, 2022

Conversation

glennmatthews
Copy link
Contributor

@glennmatthews glennmatthews commented Aug 25, 2022

Progress towards: #2292

What's Changed

  • Add pylint and pylint-django as dev dependencies
  • Add invoke pylint task and nautobot-server pylint command provided by the example plugin. (The latter is needed because of our custom startup code, meaning that DJANGO_SETTINGS_MODULE=nautobot.core.settings pylint nautobot/ doesn't work on its own)
  • Add example plugin to PLUGINS in the development config (closes Enable Example Plugin by Default in Developer Environment #2198) so that the above will work
  • Fix and/or spot-disable a bunch of relatively low-hanging pylint warnings throughout our code base. It may be easier to review these commit-by-commit rather than looking at the entire diffset at once.
    • cabb177 bad-super-call,dangerous-default-value,expression-not-assigned,no-self-argument,trailing-comma-tuple
    • 70947aa unbalanced-tuple-unpacking, undefined-loop-variable, unused-variable, used-before-assignment
    • 64298f4 unnecessary-comprehension, unnecessary-pass, use-dict-literal, use-list-literal, useless-object-inheritance, useless-super-delegation, using-constant-test
    • 4a3a49f abstract-class-instantiated, assignment-from-no-return, assignment-from-none, duplicate-key, function-redefined, implicit-str-concat
    • c98694d arguments-differ, deprecated-decorator, deprecated-method, deprecated-module, inconsistent-return-statements, invalid-envvar-default, invalid-overridden-method, invalid-str-returned
    • d997a25 redefined-argument-from-local, redefined-builtin, redefined-outer-name, redundant-unittest-assert, reimported
  • Disable all remaining current active pylint warnings against our code base so that we have a passing baseline.
    • I've got a local branch that re-enables and addresses a bunch more of these, but the diffs get increasingly large and hard to follow, and probably more controversial as well. :-) . I'll open up follow-on PR(s) with those additional changes as time and interest permits, hence why this is a "part 1".
  • Make a first stab at adding pylint to CI - as it takes about 10 minutes to run, I've set it as a parallel step to the unit-tests, rather than parallel to the other, much faster linter steps.

TODO

  • Explanation of Change(s)
  • n/a Attached Screenshots, Payload Example
  • n/a Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • git pre-commit hook updates
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

…not-assigned,no-self-argument,trailing-comma-tuple
…ict-literal, use-list-literal, useless-object-inheritance, useless-super-delegation, using-constant-test
…turn, assignment-from-none, duplicate-key, function-redefined, implicit-str-concat

Also update pylint command to include additional sources
…-method, deprecated-module, inconsistent-return-statements, invalid-envvar-default, invalid-overridden-method, invalid-str-returned
…uter-name, redundant-unittest-assert, reimported
@@ -190,7 +190,7 @@ def register_homepage_panels(path, label, homepage_layout):
)
else:
raise TypeError(f"Third level objects need to be an instance of HomePageItem: {group_item}")
panel_perms |= set(group_item.permissions)
panel_perms |= set(group_item.permissions)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugfix here - we were only adding the last group_item.permissions (after the above for loop terminates) instead of adding the permissions of each group_item in the loop.

@@ -8,27 +8,18 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file are removing Python 2 backwards compatibility code that's no longer needed. There's probably more that could be done here but this is sufficient to address the immediate pylint warnings.

nautobot/core/runner/settings.py Show resolved Hide resolved
nautobot/core/runner/settings.py Outdated Show resolved Hide resolved
@@ -84,7 +84,7 @@ def get_permissions_for_model(self, model, actions):
for action in actions:
if action not in ("view", "add", "change", "delete"):
raise ValueError(f"Unsupported action: {action}")
permissions.append("{}.{}_{}".format(model._meta.app_label, action, model._meta.model_name))
permissions.append("{}.{}_{}".format(model._meta.app_label, action, model._meta.model_name))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another bug fix where we were doing something after the for loop terminates instead of per-iteration of the loop.

nautobot/dcim/models/sites.py Outdated Show resolved Hide resolved
nautobot/extras/jobs.py Show resolved Hide resolved
nautobot/extras/scripts.py Show resolved Hide resolved
nautobot/extras/views.py Outdated Show resolved Hide resolved
nautobot/tenancy/models.py Outdated Show resolved Hide resolved
Copy link
Contributor

@gsnider2195 gsnider2195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of good fixes!

@glennmatthews glennmatthews merged commit ab80c43 into develop Aug 29, 2022
@glennmatthews glennmatthews deleted the gfm-pylint-part-1 branch August 29, 2022 19:33
glennmatthews added a commit that referenced this pull request Aug 29, 2022
@bryanculver bryanculver mentioned this pull request Sep 9, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Enable Example Plugin by Default in Developer Environment
3 participants