-
Notifications
You must be signed in to change notification settings - Fork 19
Python linting with Ruff #909
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
e77bbae
Add ruff.toml
jwallwork23 a0b238b
Add Python linting to CI
jwallwork23 a1927c0
Apply ruff check --fix
jwallwork23 438d258
Docstrings
jwallwork23 b431842
Remove blank line
jwallwork23 24cf358
Avoid redefinition of loop variable
jwallwork23 de2a19c
Don't use f-strings in exceptions
jwallwork23 547797c
Docstring for magic method
jwallwork23 a17409a
Docstring for SingleColumnThermo
jwallwork23 a1d8a1a
Module imports at top
jwallwork23 c22fd82
Avoid trailing whitespace
jwallwork23 3fa2197
Avoid unnecessary multi-line docstrings
jwallwork23 9b4075a
Avoid assert False
jwallwork23 190df08
Add trailing period
jwallwork23 f6cf882
Avoid raw strings in exceptions
jwallwork23 6bfc1d7
Use imperative mood
jwallwork23 2d72ea8
Format docstrings
jwallwork23 8832a1b
Avoid shadowing builtins
jwallwork23 87fce99
Move imports to top level
jwallwork23 6c01365
Use context manager for files
jwallwork23 2c5ced2
Fix ThermoIntegration test
jwallwork23 6a27399
Avoid bare except
jwallwork23 e65907f
Avoid unused loop variable
jwallwork23 bfaab82
Avoid unused function arguments
jwallwork23 f4fbce8
Ignore magic value comparison
jwallwork23 4ef809c
Fix and ignore S101 (no assert)
jwallwork23 5264653
Ignore too-many-X rules for now
jwallwork23 8aef2a6
Ignore subprocess rules for now
jwallwork23 dfe3917
Ignore built-in variable shadowing in docs/conf
jwallwork23 71a425c
Ignore missing docstrings for now
jwallwork23 759c819
Drop ruff format in CI
jwallwork23 a64d714
Run linting tests when not merging into main or develop
jwallwork23 64e31ec
Add exclusions for data files
jwallwork23 93b3b3e
Avoid multiple comparisons
jwallwork23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Generate the old_names.nc file used by core/test/ParaGrid_test.cpp.""" | ||
import time | ||
|
||
import netCDF4 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
"""Script for generating a changelog file.""" | ||
import os | ||
import re | ||
import string | ||
|
||
# Prerequisites: | ||
# | ||
# | ||
# github_changelog_generator repo -t token --date-format '%Y-%m-%d %H:%M' -o 'CHANGELOG.md' | ||
# git tag -l -n9 > a.txt | ||
# All tags should be of type 'v\d[\.\w]*' | ||
|
||
if __name__ == '__main__': | ||
with open('a.txt', 'r') as foo: | ||
if __name__ == "__main__": | ||
with open("a.txt", "r") as foo: | ||
data = foo.readlines() | ||
foo.close() | ||
tags_title_annotation = {} | ||
matched = None | ||
for line in data: | ||
if re.search('v\d[\.\w]*', line): | ||
matched = re.findall('v\d[\.\w]*', line)[0] | ||
if re.search(r"v\d[\.\w]*", line): | ||
matched = re.findall(r"v\d[\.\w]*", line)[0] | ||
tags_title_annotation[matched] = { | ||
'title': '', | ||
'annotation': [] | ||
"title": "", | ||
"annotation": [] | ||
} | ||
title = line.replace(matched, '').strip() | ||
title = line.replace(matched, "").strip() | ||
title = title[0].upper() + title[1:] | ||
tags_title_annotation[matched]['title'] = title | ||
tags_title_annotation[matched]["title"] = title | ||
elif matched is not None: | ||
line = line.strip() | ||
annotation = line.replace(matched, '') | ||
tags_title_annotation[matched]['annotation'].append(annotation) | ||
annotation = line.strip().replace(matched, "") | ||
tags_title_annotation[matched]["annotation"].append(annotation) | ||
|
||
with open('CHANGELOG.md', 'r') as fil: | ||
with open("CHANGELOG.md", "r") as fil: | ||
data = fil.readlines() | ||
fil.close() | ||
matched = None | ||
data_w = data | ||
for index, line in enumerate(data): | ||
if re.search('## \[v\d[\.\w]*\]', line): | ||
matched = re.findall('v\d[\.\w]*', line)[0] | ||
if re.search(r"## \[v\d[\.\w]*\]", line): | ||
matched = re.findall(r"v\d[\.\w]*", line)[0] | ||
|
||
insert_data = [ | ||
"**Description:**", | ||
tags_title_annotation[matched]['title'] | ||
tags_title_annotation[matched]["title"] | ||
] | ||
values = "\n" + \ | ||
"\n".join(insert_data) + \ | ||
"\n" + \ | ||
"\n".join(tags_title_annotation[matched]['annotation']) + \ | ||
"\n".join(tags_title_annotation[matched]["annotation"]) + \ | ||
"\n" | ||
data_w.insert(index + 1, values) | ||
with open('CHANGELOG.md', 'w') as fin: | ||
|
||
with open("CHANGELOG.md", "w") as fin: | ||
fin.writelines(data_w) | ||
fin.close() | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason the prescriptive second person form (generate), rather than the descriptive third person form (generates)? Admittedly I got this from writing javadoc comments many years ago, rather than any Python standard, but I feel it makes more sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It comes from
D401 First line of docstring should be in imperative mood
. We could ignore this rule if preferred?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'll try to follow that rule in future.