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

DAS-1892 - Add pycodestyle check to automated test suite. #4

Merged
merged 2 commits into from
Aug 3, 2023

Conversation

owenlittlejohns
Copy link
Member

Description

This PR stems from conversations with @eni-awowale during her work on DAS-1891. There wasn't an automated check for code styling in the regular bunch of unit tests. This PR adds that. (The test mimics others from repositories like HOSS).

Jira Issue ID

DAS-1892 (not strictly, but sort-of related)

Local Test Steps

N/A

PR Acceptance Checklist

  • Jira ticket acceptance criteria met.
  • CHANGELOG.md updated to include high level summary of PR changes.
  • VERSION updated if publishing a release.
  • Tests added/updated and passing.
  • Documentation updated (if needed).

short_name is None or
re.match(short_name, self.short_name) is not None
short_name is None
or re.match(short_name, self.short_name) is not None
Copy link
Member Author

@owenlittlejohns owenlittlejohns Aug 2, 2023

Choose a reason for hiding this comment

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

The two changes in this file and varinfo/var_info.py are styling things relating to the binary operator breaking stuff (W503 vs W504).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh nice! So to test if our code adheres to style requirements we would do something pycodestyle cmr_search.py or can we just run pycodestyle in the root directory and it will check everything?

Copy link
Member Author

Choose a reason for hiding this comment

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

The style check is now folded into the main test suite, so if you run make test it will run pycodestyle over the whole varinfo directory as part of that command. That's how I found these stragglers. Having that test in place now means that we can't merge the PR until the code is all compliant according to pycodestyle because that will be a test failure.

If you wanted to run it separately, though, you could use pycodestyle in the command line, too. pycodestyle varinfo/*py or pycodestyle varinfo/cmr_search.py as you say.

Copy link
Collaborator

@eni-awowale eni-awowale left a comment

Choose a reason for hiding this comment

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

I just had some questions but everything looks good to me!

short_name is None or
re.match(short_name, self.short_name) is not None
short_name is None
or re.match(short_name, self.short_name) is not None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh nice! So to test if our code adheres to style requirements we would do something pycodestyle cmr_search.py or can we just run pycodestyle in the root directory and it will check everything?


* E501: Line length, which defaults to 80 characters. This is a
preferred feature of the code, but not always easily achieved.
* W503: Break before binary operator. Have to ignore one of W503 or
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a nit or suggestion but what's this binary operator business about haha?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's the biblical reference.

An example if this is whether you should have:

if (
    my_value == 1.2345
    or my_other_value == 2.3456
):
    ...

Or:

if (
    my_value == 1.2345 or
    my_other_value == 2.3456
):
    ...

Ultimately the answer is that either are okay, so long as the code is consistently one or the other, with PEP008 stating a mild preference for the first option. pycodestyle is automatically configured to warn against both options, which is unhelpful, so the test ignores the checking of the one that is considered slightly preferred.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So either is okay (slight preference for the first) but you should keep it consistent and you turned off the check in pycodestyle for this?

Copy link
Member Author

@owenlittlejohns owenlittlejohns Aug 3, 2023

Choose a reason for hiding this comment

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

Yeah - either is okay, but we should choose one and use it throughout the project. Then I turned off the warning for the one we went with. So that second example will still trigger a warning, but the first one won't.

@owenlittlejohns owenlittlejohns merged commit 143c24c into main Aug 3, 2023
4 checks passed
@owenlittlejohns owenlittlejohns deleted the add-pycodestyle-automatic-test branch August 3, 2023 20:17
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.

2 participants