-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Lighter switch to ruff #2998
Lighter switch to ruff #2998
Conversation
We cannot use ruff's isort today, it defaults to black-compatible import formatting. |
@@ -213,7 +213,7 @@ def _assemble_vector_array(b: np.ndarray, L: Form, constants=None, coeffs=None): | |||
|
|||
|
|||
@functools.singledispatch | |||
def assemble_matrix(a: typing.Any, bcs: typing.Optional[typing.List[DirichletBC]] = None, | |||
def assemble_matrix(a: typing.Any, bcs: typing.Optional[list[DirichletBC]] = None, |
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.
This change, and all similar ones, will break python < 3.9
. I think that ruff
uses by default whatever version of python is available in the docker image (3.10
, if I remember correctly), but there is a configuration option to prevent it from doing that. However, I don't remember which of the rules is enforcing this change (pyupgrade
maybe?) to check the actual name of this option.
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.
We should discuss deprecating 3.8, only has ~6 months of support left.
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.
I checked this. The target version is inferred from pyproject.toml.
ruff --show-settings | grep target_version
gives
target_version: Py38,
target_version: Py38,
python/dolfinx/io/utils.py
Outdated
@@ -18,8 +18,8 @@ | |||
import basix.ufl | |||
import ufl | |||
from dolfinx import cpp as _cpp | |||
from dolfinx.cpp.io import perm_gmsh as cell_perm_gmsh # noqa F401 | |||
from dolfinx.cpp.io import perm_vtk as cell_perm_vtk # noqa F401 | |||
from dolfinx.cpp.io import perm_gmsh as cell_perm_gmsh # F401 |
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.
Removing the noqa
is odd: I guess it should have been either noqa: F401
, or no comment at all
@@ -17,7 +17,7 @@ | |||
from dolfinx import default_real_type | |||
from dolfinx.fem import Function, functionspace | |||
from dolfinx.io import VTKFile | |||
from dolfinx.io.utils import cell_perm_vtk # noqa F401 |
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.
noqa here too.
python/demo/demo_cahn-hilliard.py
Outdated
@@ -194,7 +194,8 @@ | |||
u.x.array[:] = 0.0 | |||
|
|||
# Interpolate initial condition | |||
u.sub(0).interpolate(lambda x: 0.63 + 0.02 * (0.5 - np.random.rand(x.shape[1]))) | |||
rng = np.random.default_rng() |
Check notice
Code scanning / SonarCloud
Results that depend on random number generation should be reproducible Low
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.
I guess there is value in this comment, but how come it did not notice it before? The call to np.random.rand
was already there.
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.
I think it is a new feature of Github, Lets add a seed?
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.
I think GitHub can pickup on new issues picked up by SonarCloud and now put them back in to the review, which seems very useful.
Ruff linting without consistent formatting (e.g. black).