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

ci: add flake8 and fix warnings #326

Merged
merged 2 commits into from
Nov 3, 2020
Merged

ci: add flake8 and fix warnings #326

merged 2 commits into from
Nov 3, 2020

Conversation

jenhagg
Copy link
Collaborator

@jenhagg jenhagg commented Oct 30, 2020

Purpose

Add flake8 linting which can catch typos in variable names, unused imports, undefined variables, etc. In the process, I found 2 actual bugs where there is an undefined local variable (see create.py)

What the code is doing

This adds flake8 to the default tox envlist, and adds a new job to the github lint workflow. To make it pass, I fixed warnings, except for a few that made more sense to ignore. List of error codes is here.

Testing

CI

Where to look

tox.ini - how flake8 is run and configured, everything else is code fixes

Time estimate

10 min

@jenhagg jenhagg requested review from ahurli and rouille October 30, 2020 22:46
@@ -479,7 +479,7 @@ class TexasEastern(_Builder):

name = "Texas_Eastern"

def __init__(self):
def __init__(self, ssh_client):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This class is never instantiated. That is why it is not maintained

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could just use pass after the definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we never use it, and we never foresee using it, should we remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah we should remove if there aren't plans for it (I wasn't sure what the status was). I suppose you would be someone to ask about that, so I will go ahead, we can always put it back later since it's still in git.

Copy link
Contributor

@danielolsen danielolsen Nov 3, 2020

Choose a reason for hiding this comment

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

Well... we may want to keep it in (with the fixes) for other people to use. Coupling between Texas and Eastern isn't strong currently, but someone might want to study a scenario where the coupling improves between these two, while Western remains relatively isolated, in which case they would want to use this.

@@ -490,7 +490,7 @@ class EasternWestern(_Builder):

name = "Eastern_Western"

def __init__(self):
def __init__(self, ssh_client):
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@rouille
Copy link
Collaborator

rouille commented Oct 30, 2020

It seems that we could check docstring through flake8: https://stackoverflow.com/questions/60403545/flake8-not-giving-errors-warnings-on-missing-docstring-or-code-not-following-pep

Or we could use pydocstyle directly.

Any thoughts?

@@ -461,5 +461,5 @@ def test_grid_eq_failure_storage(base_texas):
def test_that_fields_are_not_modified_when_loading_another_grid():
western_grid = Grid(["Western"])
western_plant_original_shape = western_grid.plant.shape
eastern_grid = Grid(["Eastern"])
eastern_grid = Grid(["Eastern"]) # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this comment mean?

For context, this test was to demonstrate a bug that has since been fixed. Loading an Eastern grid modified existing Westerns. I believe the test would achieve the same thing even if the Eastern grid is not stored in a variable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It causes flake8 to ignore that line, not sure why I didn't just remove the variable name but will do that.

@@ -30,8 +30,8 @@ def get_table(self, filename, path_on_server):
try:
table = self._get_from_server(path_on_server)
table.to_csv(local_path, index=False)
except:
print(f"Failed to download {filename} list from server.")
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the idea that any general except must at least print the exception caught?

Copy link
Collaborator

@rouille rouille Oct 30, 2020

Choose a reason for hiding this comment

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

The error message will be cluttered

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The warning is about having an empty except: block, but figured we might as well print the error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I didn't see a lot of value in printing this one, so updated it to ignore the flake8 warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think some of the reason for the generality of the exception catching is that it's hard to catch paramiko exceptions, something about them being part of a separate thread, so it's hard to know what we'll get if _get_from_server doesn't complete successfully. But this is second-hand info from @rouille.

@jenhagg
Copy link
Collaborator Author

jenhagg commented Oct 30, 2020

Yeah we could add plugins for flake8 to check docstrings and other things, it's very extensible, just wanted to keep this simple to start.

@danielolsen
Copy link
Contributor

Removing all those unused imports is beautiful.

@jenhagg jenhagg self-assigned this Nov 2, 2020
@jenhagg jenhagg added this to the VOTE milestone Nov 2, 2020
Copy link
Contributor

@danielolsen danielolsen left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

I'm not familiar with the yaml files or the tox script, but I trust you.

@jenhagg jenhagg merged commit 1fedeb3 into develop Nov 3, 2020
@jenhagg jenhagg deleted the jon/flake8 branch November 3, 2020 20:18
@ahurli ahurli mentioned this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants