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

Lighter switch to ruff #2998

Merged
merged 31 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4806473
Basic configuration from other branch.
jhale Jan 18, 2024
f55135e
Ignore X | Y, our supported Python to old
jhale Jan 18, 2024
81e8a7f
Cannot use isort package from ruff.
jhale Jan 18, 2024
cebb334
Use traditional isort + ruff --fix .
jhale Jan 18, 2024
c3427f5
Unsafe fixes.
jhale Jan 18, 2024
b5b7191
Add back in isort.
jhale Jan 18, 2024
0b67404
Add ruff.toml
jhale Jan 18, 2024
fb1f579
Fix.
jhale Jan 18, 2024
54834fe
Ignore RUF012
jhale Jan 18, 2024
a32efe5
Fix circleci
jhale Jan 18, 2024
231d144
Remove deprecated numpy random call.
jhale Jan 18, 2024
d80318d
Add back isort.
jhale Jan 18, 2024
30a033d
Move Python minimum to 3.9 (discuss).
jhale Jan 18, 2024
83996a2
Merge branch 'main' into jhale/ruff-light
jhale Jan 18, 2024
3b33340
More fixes.
jhale Jan 18, 2024
a6287e5
Merge branch 'jhale/ruff-light' of github.com:FEniCS/dolfinx into jha…
jhale Jan 18, 2024
f6f4501
Merge remote-tracking branch 'origin/main' into jhale/ruff-light
jhale Jan 21, 2024
081d670
ruff fix.
jhale Jan 21, 2024
f7f6896
Fix isort configuration and re-isort.
jhale Jan 21, 2024
70be3d7
Fixes.
jhale Jan 21, 2024
30e2f45
Python 3.10
jhale Jan 22, 2024
0cb91ab
Merge remote-tracking branch 'origin/main' into jhale/ruff-light
jhale Jan 22, 2024
57f0a62
Not necessary.
jhale Jan 22, 2024
235515f
Add back in some removals.
jhale Jan 22, 2024
cce1384
Merge remote-tracking branch 'origin/main' into jhale/ruff-light
jhale Jan 22, 2024
5d03160
isort.
jhale Jan 22, 2024
383d406
Rocky and Intel OneAPI on Python 3.9
jhale Jan 22, 2024
82eaf51
Seed random number generator.
jhale Jan 22, 2024
41d8ace
Remove | stuff.
jhale Jan 22, 2024
93b2da0
Fix circleci.
jhale Jan 22, 2024
237e1f5
Merge remote-tracking branch 'origin/main' into jhale/ruff-light
jhale Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ install-python-components: &install-python-components
pip3 install git+https://github.com/FEniCS/ufl.git
pip3 install git+https://github.com/FEniCS/ffcx.git

flake8-python-code: &flake8-python-code
name: Flake8 checks on Python code
ruff-isort-python-code: &ruff-isort-python-code
name: ruff and isort checks on Python code
command: |
cd python/
python3 -m flake8 dolfinx
python3 -m flake8 demo
python3 -m flake8 test
ruff check .
isort --check .

configure-cpp: &configure-cpp
name: Configure (C++)
Expand Down Expand Up @@ -101,7 +100,7 @@ jobs:
steps:
- checkout
- run: *install-python-components
- run: *flake8-python-code
- run: *ruff-isort-python-code
- run: *configure-cpp
- run: *build-install-cpp

Expand Down Expand Up @@ -131,7 +130,7 @@ jobs:
steps:
- checkout
- run: *install-python-components
- run: *flake8-python-code
- run: *ruff-isort-python-code
- run: *configure-cpp
- run: *build-install-cpp

Expand Down
19 changes: 5 additions & 14 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,15 @@ jobs:
python3 -m pip install git+https://github.com/FEniCS/basix.git@${{ github.event.inputs.basix_ref }}
python3 -m pip install git+https://github.com/FEniCS/ffcx.git@${{ github.event.inputs.ffcx_ref }}

- name: Flake8 checks
run: |
cd cpp/
python3 -m flake8 cmake
python3 -m flake8 demo
python3 -m flake8 test
cd ..
cd python/
python3 -m flake8 dolfinx
python3 -m flake8 demo
python3 -m flake8 test
- name: isort checks (non-blocking)
continue-on-error: true
- name: ruff and isort C++ .py file checks
run: |
cd cpp/
ruff check .
python3 -m isort --check .
cd ..
- name: ruff and isort Python interface checks
run: |
cd python/
ruff check .
python3 -m isort --check .
- name: mypy checks
run: |
Expand Down
1 change: 1 addition & 0 deletions cpp/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extend = "../python/pyproject.toml"
6 changes: 0 additions & 6 deletions python/.isort.cfg

This file was deleted.

3 changes: 1 addition & 2 deletions python/demo/demo_biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@
from dolfinx import fem, io, mesh, plot
from dolfinx.fem.petsc import LinearProblem
from dolfinx.mesh import CellType, GhostMode
from ufl import (CellDiameter, FacetNormal, avg, div, dS, dx, grad, inner,
jump, pi, sin)
from ufl import CellDiameter, FacetNormal, avg, div, dS, dx, grad, inner, jump, pi, sin

# -

Expand Down
3 changes: 2 additions & 1 deletion python/demo/demo_cahn-hilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,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(42)
u.sub(0).interpolate(lambda x: 0.63 + 0.02 * (0.5 - rng.random(x.shape[1])))
u.x.scatter_forward()
# -

Expand Down
9 changes: 3 additions & 6 deletions python/demo/demo_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@
import dolfinx
import ufl
from dolfinx import la
from dolfinx.fem import (Expression, Function, FunctionSpace, dirichletbc,
form, functionspace, locate_dofs_topological)
from dolfinx.fem.petsc import (apply_lifting, assemble_matrix, assemble_vector,
set_bc)
from dolfinx.fem import Expression, Function, FunctionSpace, dirichletbc, form, functionspace, locate_dofs_topological
from dolfinx.fem.petsc import apply_lifting, assemble_matrix, assemble_vector, set_bc
from dolfinx.io import XDMFFile
from dolfinx.mesh import (CellType, GhostMode, create_box,
locate_entities_boundary)
from dolfinx.mesh import CellType, GhostMode, create_box, locate_entities_boundary
from ufl import dx, grad, inner

dtype = PETSc.ScalarType # type: ignore
Expand Down
5 changes: 2 additions & 3 deletions python/demo/demo_lagrange_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#
# We begin this demo by importing the required modules.

import typing

from mpi4py import MPI

Expand Down Expand Up @@ -166,8 +165,8 @@ def saw_tooth(x):
uh = fem.Function(V)
uh.interpolate(lambda x: saw_tooth(x[0]))
if MPI.COMM_WORLD.size == 1: # Skip this plotting in parallel
pts: typing.List[typing.List[float]] = []
cells: typing.List[int] = []
pts: list[list[float]] = []
cells: list[int] = []
for cell in range(10):
for i in range(51):
pts.append([cell / 10 + i / 50 / 10, 0, 0])
Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_mixed-poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
from basix.ufl import element, mixed_element
from dolfinx import fem, io, mesh
from dolfinx.fem.petsc import LinearProblem
from ufl import (Measure, SpatialCoordinate, TestFunctions, TrialFunctions,
div, exp, inner)
from ufl import Measure, SpatialCoordinate, TestFunctions, TrialFunctions, div, exp, inner

msh = mesh.create_unit_square(MPI.COMM_WORLD, 32, 32, mesh.CellType.quadrilateral)

Expand Down
4 changes: 2 additions & 2 deletions python/demo/demo_navier-stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@

from dolfinx import default_real_type, fem, io, mesh
from dolfinx.fem.petsc import assemble_matrix_block, assemble_vector_block
from ufl import (CellDiameter, FacetNormal, TestFunction, TrialFunction, avg,
conditional, div, dot, dS, ds, dx, grad, gt, inner, outer)
from ufl import (CellDiameter, FacetNormal, TestFunction, TrialFunction, avg, conditional, div, dot, dS, ds, dx, grad,
gt, inner, outer)

if np.issubdtype(PETSc.ScalarType, np.complexfloating): # type: ignore
print("Demo should only be executed with DOLFINx real mode")
Expand Down
4 changes: 2 additions & 2 deletions python/demo/demo_pml/demo_pml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# +
import sys
from functools import partial
from typing import Tuple, Union
from typing import Union

from mpi4py import MPI

Expand Down Expand Up @@ -358,7 +358,7 @@ def pml_coordinates(x: ufl.indexed.Indexed, alpha: float, k0: complex, l_dom: fl

def create_eps_mu(pml: ufl.tensors.ListTensor,
eps_bkg: Union[float, ufl.tensors.ListTensor],
mu_bkg: Union[float, ufl.tensors.ListTensor]) -> Tuple[ufl.tensors.ComponentTensor,
mu_bkg: Union[float, ufl.tensors.ListTensor]) -> tuple[ufl.tensors.ComponentTensor,
ufl.tensors.ComponentTensor]:
J = ufl.grad(pml)

Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_pml/efficiencies_pml_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
# & q_{\mathrm{abs}} = q_{\mathrm{ext}} - q_{\mathrm{sca}}
# $$

from typing import Tuple

import numpy as np
from scipy.special import h2vp, hankel2, jv, jvp
Expand Down Expand Up @@ -107,7 +106,7 @@ def compute_a(nu: int, m: complex, alpha: float) -> float:

def calculate_analytical_efficiencies(eps: complex, n_bkg: float,
wl0: float, radius_wire: float,
num_n: int = 50) -> Tuple[float, float, float]:
num_n: int = 50) -> tuple[float, float, float]:
m = np.sqrt(np.conj(eps)) / n_bkg
alpha = 2 * np.pi * radius_wire / wl0 * n_bkg
c = 2 / alpha
Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_pml/mesh_wire_pml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import sys
from functools import reduce
from typing import List

import numpy.typing

Expand Down Expand Up @@ -117,7 +116,7 @@ def generate_mesh_wire(radius_wire: float, radius_scatt: float, l_dom: float, l_
gmsh.model.addPhysicalGroup(dim, y_group, tag=pml_tag + 2)

# Marker interior surface in bkg group
boundaries: List[numpy.typing.NDArray[numpy.int32]] = []
boundaries: list[numpy.typing.NDArray[numpy.int32]] = []
for tag in bkg_group:
boundary_pairs = gmsh.model.get_boundary([(dim, tag)], oriented=False)
boundaries.append(numpy.asarray([pair[1] for pair in boundary_pairs], dtype=numpy.int32))
Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

import dolfinx.plot as plot
from dolfinx.fem import Function, functionspace
from dolfinx.mesh import (CellType, compute_midpoints, create_unit_cube,
create_unit_square, meshtags)
from dolfinx.mesh import CellType, compute_midpoints, create_unit_cube, create_unit_square, meshtags

try:
import pyvista
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
# & q_{\mathrm{abs}} = q_{\mathrm{ext}} - q_{\mathrm{sca}}
# $$

from typing import Tuple

import numpy as np
from scipy.special import h2vp, hankel2, jv, jvp
Expand Down Expand Up @@ -106,7 +105,7 @@ def compute_a(nu: int, m: complex, alpha: float) -> float:


def calculate_analytical_efficiencies(eps: complex, n_bkg: float, wl0: float, radius_wire: float,
num_n: int = 50) -> Tuple[float, float, float]:
num_n: int = 50) -> tuple[float, float, float]:
m = np.sqrt(np.conj(eps)) / n_bkg
alpha = 2 * np.pi * radius_wire / wl0 * n_bkg
c = 2 / alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

# +
import sys
from typing import Tuple

from mpi4py import MPI

Expand Down Expand Up @@ -115,7 +114,7 @@ def __init__(self, theta: float, n_bkg: float, k0: complex):
self.k0 = k0 # vacuum wavevector
self.n_bkg = n_bkg # background refractive index

def eval(self, x: np.typing.NDArray[np.float64]) -> Tuple[np.typing.NDArray[np.complex128],
def eval(self, x: np.typing.NDArray[np.float64]) -> tuple[np.typing.NDArray[np.complex128],
np.typing.NDArray[np.complex128]]:
kx = self.n_bkg * self.k0 * np.cos(self.theta)
ky = self.n_bkg * self.k0 * np.sin(self.theta)
Expand Down
9 changes: 3 additions & 6 deletions python/demo/demo_static-condensation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@
import ufl
from basix.ufl import element
from dolfinx import geometry
from dolfinx.fem import (Form, Function, IntegralType, dirichletbc, form,
form_cpp_class, functionspace,
from dolfinx.fem import (Form, Function, IntegralType, dirichletbc, form, form_cpp_class, functionspace,
locate_dofs_topological)
from dolfinx.fem.petsc import (apply_lifting, assemble_matrix, assemble_vector,
set_bc)
from dolfinx.fem.petsc import apply_lifting, assemble_matrix, assemble_vector, set_bc
from dolfinx.io import XDMFFile
from dolfinx.jit import ffcx_jit
from dolfinx.mesh import locate_entities_boundary, meshtags
from ffcx.codegeneration.utils import \
numba_ufcx_kernel_signature as ufcx_signature
from ffcx.codegeneration.utils import numba_ufcx_kernel_signature as ufcx_signature

if PETSc.RealType == np.float32: # type: ignore
print("float32 not yet supported for this demo.")
Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@
import ufl
from basix.ufl import element, mixed_element
from dolfinx import fem, la
from dolfinx.fem import (Constant, Function, dirichletbc,
extract_function_spaces, form, functionspace,
from dolfinx.fem import (Constant, Function, dirichletbc, extract_function_spaces, form, functionspace,
locate_dofs_topological)
from dolfinx.fem.petsc import assemble_matrix_block, assemble_vector_block
from dolfinx.io import XDMFFile
Expand Down
7 changes: 3 additions & 4 deletions python/demo/demo_tnt-elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
from mpi4py import MPI

# +
import matplotlib
import matplotlib as mpl
import matplotlib.pylab as plt
import numpy as np

import basix
import basix.ufl
from dolfinx import fem, mesh
from dolfinx.fem.petsc import LinearProblem
from ufl import (SpatialCoordinate, TestFunction, TrialFunction, cos, div, dx,
grad, inner, sin)
from ufl import SpatialCoordinate, TestFunction, TrialFunction, cos, div, dx, grad, inner, sin

matplotlib.use('agg')
mpl.use('agg')
# -

# ## Defining a degree 1 TNT element
Expand Down
3 changes: 1 addition & 2 deletions python/demo/demo_waveguide/demo_half_loaded_waveguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
from basix.ufl import element, mixed_element
from dolfinx import default_scalar_type, fem, io, plot
from dolfinx.fem.petsc import assemble_matrix
from dolfinx.mesh import (CellType, create_rectangle, exterior_facet_indices,
locate_entities)
from dolfinx.mesh import CellType, create_rectangle, exterior_facet_indices, locate_entities

try:
import pyvista
Expand Down
6 changes: 2 additions & 4 deletions python/dolfinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

from dolfinx import common
from dolfinx import cpp as _cpp
from dolfinx import (fem, geometry, graph, io, jit, la, log, mesh, nls, plot,
utils)
from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot, utils
# Initialise logging
from dolfinx.common import (TimingType, git_commit_hash, has_debug, has_kahip,
has_parmetis, list_timings, timing)
from dolfinx.common import TimingType, git_commit_hash, has_debug, has_kahip, has_parmetis, list_timings, timing
from dolfinx.cpp import __version__

_cpp.common.init_logging(sys.argv)
Expand Down
3 changes: 1 addition & 2 deletions python/dolfinx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import typing

from dolfinx import cpp as _cpp
from dolfinx.cpp.common import (IndexMap, git_commit_hash, has_adios2, # noqa
has_debug, has_kahip, has_parmetis)
from dolfinx.cpp.common import IndexMap, git_commit_hash, has_adios2, has_debug, has_kahip, has_parmetis # noqa

__all__ = ["IndexMap", "Timer", "timed"]

Expand Down
17 changes: 6 additions & 11 deletions python/dolfinx/fem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Tools for assembling and manipulating finite element forms."""

from dolfinx.cpp.fem import (IntegralType,
create_nonmatching_meshes_interpolation_data)
from dolfinx.cpp.fem import IntegralType, create_nonmatching_meshes_interpolation_data
from dolfinx.cpp.fem import create_sparsity_pattern as _create_sparsity_pattern
from dolfinx.cpp.fem import transpose_dofmap
from dolfinx.fem.assemble import (apply_lifting, assemble_matrix,
assemble_scalar, assemble_vector,
create_matrix, create_vector, set_bc)
from dolfinx.fem.bcs import (DirichletBC, bcs_by_block, dirichletbc,
locate_dofs_geometrical, locate_dofs_topological)
from dolfinx.fem.assemble import (apply_lifting, assemble_matrix, assemble_scalar, assemble_vector, create_matrix,
create_vector, set_bc)
from dolfinx.fem.bcs import DirichletBC, bcs_by_block, dirichletbc, locate_dofs_geometrical, locate_dofs_topological
from dolfinx.fem.dofmap import DofMap
from dolfinx.fem.element import CoordinateElement, coordinate_element
from dolfinx.fem.forms import (Form, extract_function_spaces, form,
form_cpp_class)
from dolfinx.fem.function import (Constant, ElementMetaData, Expression,
Function, FunctionSpace, functionspace)
from dolfinx.fem.forms import Form, extract_function_spaces, form, form_cpp_class
from dolfinx.fem.function import Constant, ElementMetaData, Expression, Function, FunctionSpace, functionspace


def create_sparsity_pattern(a: Form):
Expand Down
Loading
Loading