-
Notifications
You must be signed in to change notification settings - Fork 247
misc: Ruff #2771
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
base: main
Are you sure you want to change the base?
misc: Ruff #2771
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2771 +/- ##
==========================================
- Coverage 83.01% 78.97% -4.04%
==========================================
Files 248 248
Lines 51074 50826 -248
Branches 4491 4393 -98
==========================================
- Hits 42401 40142 -2259
- Misses 7902 9881 +1979
- Partials 771 803 +32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| # But ignore these inconvenient rules | ||
| ignore = ["F403", "E226", "E731", "E275", "F405", "E722", "E741", "W605"] | ||
|
|
||
| [tool.isort] |
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.
you look back 10 years ago or so there's a commit with message "FREEEEEEEEEEEEEDOOOMM" in which we are essentially removing isort from devito 😂
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.
What was the motivation for removing?
| [tool.isort] | ||
| line_length = 90 | ||
| known_first_party = ["devito", "examples"] | ||
| multi_line_output = "VERTICAL_GRID_GROUPED" |
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.
if this is for
from X import (
A,
B,
C,
...
)
then I vote no
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 this is in direct response to your comment on my other PR. This is specifically to avoid using ruff for the import formatting (see this issue)
a4609a1 to
43a044d
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
70151d8 to
b19cb9d
Compare
9b5069c to
1ec3c7f
Compare
…anges_part2 misc: ruff manual changes part2
…anges misc: Ruff manual changes
This reverts commit 1318b52.
| 'Cpu64AdvOmpOperator', 'Cpu64FsgCOperator', 'Cpu64FsgOmpOperator', | ||
| 'Cpu64CustomOperator', 'Cpu64CustomCXXOperator', 'Cpu64AdvCXXOperator', | ||
| 'Cpu64AdvCXXOmpOperator', 'Cpu64FsgCXXOperator', 'Cpu64FsgCXXOmpOperator'] | ||
| __all__ = [ |
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.
Why are some one per line and some are not (like archinfo.py)
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.
Because I put a # noqa: RUF022 around the line in archinfo.py since the list is carefully arranged and documented.
Note that isort fixes the imports and ruff formats the __all__.
devito/data/allocators.py
Outdated
| import mmap | ||
| import os | ||
| import sys | ||
| from ctypes.util import find_library |
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.
Slightly weird that it import ctypes then others then ctypes.util
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 [ruff/isort] did not do that, we imported both in this way and then it just got formatted like so. We should just fix it 😅 (which I will takes as the action to this comment)
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.
Nevermind! There is a good reason for it being the way it was! (util is a module and is not automatically imported when you import ctypes)
795c02b to
ac035e1
Compare
ac035e1 to
b19bb09
Compare
b19bb09 to
8d1fa60
Compare
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.
Nitpick: this file is a .yaml whilst all the others are .yml
| """ | ||
| Initialize any necessary input and run the operator associated with the solver. | ||
| """ | ||
| # Get the operator if exist |
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.
Nitpick, but whilst we're fixing all the typos "Get the operator if it exists"
|
|
||
| if oo['mpi'] and oo['mpi'] not in cls.MPI_MODES: | ||
| raise InvalidOperator("Unsupported MPI mode `%s`" % oo['mpi']) | ||
| raise InvalidOperator("Unsupported MPI mode `{}`".format(oo['mpi'])) |
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.
| raise InvalidOperator("Unsupported MPI mode `{}`".format(oo['mpi'])) | |
| raise InvalidOperator(f"Unsupported MPI mode `{oo['mpi']}`") |
| psubs = {} | ||
| nx0 = x0.copy() | ||
| for d, d0 in x0.items(): | ||
| for d, _ in x0.items(): |
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.
| for d, _ in x0.items(): | |
| for d in x0: |
| func, mode = args | ||
| else: | ||
| assert False | ||
| raise AssertionError('Too many args') |
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.
| raise AssertionError('Too many args') | |
| raise ValueError(f"Either 1 or 2 arguments permitted, {len(args)} provided") |
|
|
||
| def __repr__(self): | ||
| return "<SyncSpot (%s)>" % ",".join(str(i) for i in self.sync_ops) | ||
| return "<SyncSpot ({})>".format(",".join(str(i) for i in self.sync_ops)) |
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.
| return "<SyncSpot ({})>".format(",".join(str(i) for i in self.sync_ops)) | |
| return f"<SyncSpot ({','.join(str(i) for i in self.sync_ops)})>" |
| def __repr__(self): | ||
| functions = "(%s)" % ",".join(i.name for i in self.functions) | ||
| return "<%s%s>" % (self.__class__.__name__, functions) | ||
| functions = "({})".format(",".join(i.name for i in self.functions)) |
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.
| functions = "({})".format(",".join(i.name for i in self.functions)) | |
| functions = f"({','.join(i.name for i in self.functions)})" |
| v = f._C_name | ||
| else: | ||
| assert False | ||
| raise AssertionError('rvalue is not a recognised type') |
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.
| raise AssertionError('rvalue is not a recognised type') | |
| raise TypeError('rvalue is not a recognised type') |
| v = f._C_field_dmap | ||
| else: | ||
| assert False | ||
| raise AssertionError('rvalue is not a recognised type') |
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.
| raise AssertionError('rvalue is not a recognised type') | |
| raise TypeError('rvalue is not a recognised type') |
| try: | ||
| assert not queue | ||
| except AssertionError: | ||
| except AssertionError as e: | ||
| if options['mpi']: | ||
| raise RuntimeError("Unsupported MPI for the given equations") | ||
| raise RuntimeError("Unsupported MPI for the given equations") from e |
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.
| try: | |
| assert not queue | |
| except AssertionError: | |
| except AssertionError as e: | |
| if options['mpi']: | |
| raise RuntimeError("Unsupported MPI for the given equations") | |
| raise RuntimeError("Unsupported MPI for the given equations") from e | |
| if not queue and options['mpi']: | |
| raise RuntimeError("Unsupported MPI for the given equations") |
EdCaunt
left a comment
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.
Looks mainly good to me - feel free to ignore any and all of my comments since they don't affect functionality and it's still an improvement over the existing code.
We should just get this merged to avoid hellish rebasing and then fix the quibbles later
I'm trying to automate detection a lot of the "nitpick" code review comments and providing a route to automatically fixing the issues apriori.
What I have added to CI is equivalent to locally running:
isort --check-only --sort-reexports --multi-line VERTICAL_GRID_GROUPED --line-length 90 --force-alphabetical-sort-within-sections --project devito,examples . ruff check --preview --select E,W,F,B,UP,SIM,I,RUF022 --ignore F403,E226,E731,E275,F405,E722,E741,W605 --line-length=90 --output-format conciseMost command line arguments are included in the
pyproject.tomland checking out this branch you can just runisort --check-only . ruff check --output-format conciseFixing most linting issues is as simple as
isort . ruff check --fixif you trust the auto-formatter!
This PR also extends linting to Dockerfiles and Github actions too.
An excerpt from
CONTRIBUTING.md: