Skip to content

Commit

Permalink
pyproject: add and fix more ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Jul 6, 2024
1 parent 6c6fdcb commit 242e9b1
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 50 deletions.
4 changes: 1 addition & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# MeshPy documentation build configuration file, created by
# sphinx-quickstart on Tue Jul 1 12:35:03 2008.
#
Expand Down Expand Up @@ -46,7 +44,7 @@

# General substitutions.
project = "MeshPy"
copyright = u"2008, Andreas Klöckner"
copyright = "2008, Andreas Klöckner"


# The default replacements for |version| and |release|, also used in various
Expand Down
16 changes: 7 additions & 9 deletions examples/box-in-box.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ def main():

# region attributes
mesh_info.regions.resize(1)
mesh_info.regions[0] = (
mesh_info.regions[0] = [
# point in region
[0, 0, 0]
+ [
# region number
1,
# max volume in region
0.001,
]
)
0, 0, 0,
# region number
1,
# max volume in region
0.001,
]

mesh = build(mesh_info, max_volume=0.06,
volume_constraints=True, attributes=True)
Expand Down
18 changes: 9 additions & 9 deletions examples/jw_meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def MakeSurfaceMesh(xstr, ystr, zstr, u0, u1, v0, v1, n1, n2):
max_len = max([np.max(np.diff(all_u)), np.max(np.diff(all_v))])

# make mesh
uv_points = np.array(uv_bound + [uv_bound[0]])
uv_points = np.array([*uv_bound, uv_bound[0]])
p1, v1 = PointSegments(uv_points)
p_uv, elements, bou, li_bou = DoTriMesh(p1, v1, edge_length=max_len, show=False)

Expand Down Expand Up @@ -302,9 +302,9 @@ def MakeSphere(P0, R, mesh_len, epsilon=1e-8, type="cart"):
if type == "cart":

# make part of the sphere
xstr = "%g*np.cos(u)*np.sin(v)" % (R)
ystr = "%g*np.sin(u)*np.sin(v)" % (R)
zstr = "%g*np.cos(v)" % (R)
xstr = f"{R:g}*np.cos(u)*np.sin(v)"
ystr = f"{R:g}*np.sin(u)*np.sin(v)"
zstr = f"{R:g}*np.cos(v)"
Nu = int(2 * np.pi * R / mesh_len)
pp, tt = MakeSurfaceMesh(
xstr, ystr, zstr, 0, 2 * np.pi, np.pi / 4.0, np.pi / 2.0, Nu, int(Nu / 3.0)
Expand Down Expand Up @@ -350,9 +350,9 @@ def MakeSphere(P0, R, mesh_len, epsilon=1e-8, type="cart"):

else:
# make part of the sphere
xstr = "%g*np.cos(u)*np.sin(v)" % (R)
ystr = "%g*np.sin(u)*np.sin(v)" % (R)
zstr = "%g*np.cos(v)" % (R)
xstr = f"{R:g}*np.cos(u)*np.sin(v)"
ystr = f"{R:g}*np.sin(u)*np.sin(v)"
zstr = f"{R:g}*np.cos(v)"
Nu = int(2.0 * np.pi * R / mesh_len)
pn, tn = MakeSurfaceMesh(
xstr, ystr, zstr, 0, 2.0 * np.pi, 0, np.pi, Nu, int(Nu / 3.0)
Expand Down Expand Up @@ -867,7 +867,7 @@ def FindBoundaryElement(t, Seg, BoundE):
# print("Boundary Segment ",Seg," Boundary Element ",t[BoundE[i]])
# sort in a way that the first two indices are boundary indices
# main indices first
ThirdIndex = list(set(t[BoundE[i], 0:3]) - set(Seg[0:2]))[0]
ThirdIndex = next(set(t[BoundE[i], 0:3]) - set(Seg[0:2]))
dbllist = list(t[BoundE[i], 0:3]) * 2
kk = 1 + dbllist.index(ThirdIndex)
MainIndices = dbllist[kk : kk + 3]
Expand Down Expand Up @@ -1400,7 +1400,7 @@ def ConnectBoundary(boundary_segments, Pall, pstart=None):
# indj gives the position of the segment in allseg
indj = nodes.index(indices[j])
# find the number of boundary the node belongs to
this_boundary = (np.where((np.array(boundaries) <= indj))[0])[-1]
this_boundary = (np.where(np.array(boundaries) <= indj)[0])[-1]

if not flag_sorted[this_boundary]:
# define the indices for slicing
Expand Down
12 changes: 6 additions & 6 deletions examples/tet-size-control.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def add_to_all_vertex_indices(facets, increment):
return [[pt + increment for pt in facet] for facet in facets]


mesh_info.set_facets(
[[0, 1, 2, 3]] # base
+ box_without_minus_z # first box
+ add_to_all_vertex_indices(box_without_minus_z, 4) # second box
)
mesh_info.set_facets([
[0, 1, 2, 3], # base
*box_without_minus_z, # first box
*add_to_all_vertex_indices(box_without_minus_z, 4) # second box
])

# set the volume properties -- this is where the tet size constraints are
mesh_info.regions.resize(2)
Expand All @@ -50,7 +50,7 @@ def add_to_all_vertex_indices(facets, increment):
1e-2, # max tet volume in region
]

mesh = build(mesh_info, area_constraints=True)
mesh = build(mesh_info, volume_constraints=True)

# this is a no-op, but it shows how to access the output data
for point in mesh.points:
Expand Down
2 changes: 1 addition & 1 deletion examples/tri-refinement-spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
#
info.regions.resize(1)
# points [x,y] in region, + region number, + regional area constraints
info.regions[0] = [0, 0] + [1, 0.05]
info.regions[0] = [0, 0, 1, 0.05]

mesh = triangle.build(info, volume_constraints=True, max_volume=0.1)

Expand Down
8 changes: 4 additions & 4 deletions meshpy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def write_neu(self, outfile, bc=None, periodicity=None,
# header --------------------------------------------------------------
outfile.write("CONTROL INFO 2.1.2\n")
outfile.write("** GAMBIT NEUTRAL FILE\n")
outfile.write("%s\n" % description)
outfile.write("PROGRAM: MeshPy VERSION: %s\n" % version)
outfile.write("%s\n" % datetime.now().ctime())
outfile.write(f"{description}\n")
outfile.write(f"PROGRAM: MeshPy VERSION: {version}\n")
outfile.write(f"{datetime.now().ctime()}\n")

bc_markers = list(bc.keys())
if periodicity:
Expand Down Expand Up @@ -144,7 +144,7 @@ def write_neu(self, outfile, bc=None, periodicity=None,
flags = 0
outfile.write("GROUP:%11d ELEMENTS:%11d MATERIAL:%11s NFLAGS: %11d\n"
% (1, len(grp_elements), repr(material), flags))
outfile.write(("epsilon: %s\n" % material).rjust(32)) # FIXME
outfile.write((f"epsilon: {material}\n").rjust(32)) # FIXME
outfile.write("0\n")
outfile.write(_linebreak_list([str(i+1) for i in grp_elements],
pad=8)
Expand Down
2 changes: 1 addition & 1 deletion meshpy/gmsh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from warnings import warn

from gmsh_interop.runner import * # noqa: F403, F401
from gmsh_interop.runner import * # noqa: F403


warn("meshpy.gmsh is deprecated. Use gmsh_interop.runner instead.",
Expand Down
2 changes: 1 addition & 1 deletion meshpy/gmsh_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from warnings import warn

from gmsh_interop.reader import * # noqa: F403, F401
from gmsh_interop.reader import * # noqa: F403


warn("meshpy.gmsh_reader is deprecated. Use gmsh_interop.reader instead.",
Expand Down
4 changes: 2 additions & 2 deletions meshpy/naca.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def explain(*s):
def explain(*s):
pass

explain("Airfoil: NACA-%s" % naca_digits)
explain(f"Airfoil: NACA-{naca_digits}")

if sharp_trailing_edge:
explain("Sharp trailing edge")
Expand Down Expand Up @@ -259,7 +259,7 @@ def main():
verbose=options.verbose)

if options.output is None:
options.output = "naca-%s.dat" % digits
options.output = f"naca-{digits}.dat"

print("Output file:", options.output)
write_points(points, options.output)
Expand Down
2 changes: 1 addition & 1 deletion meshpy/ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def make_parser(it):
.split()):
return parse_int
else:
raise ValueError("unknown type '%s'" % tp)
raise ValueError(f"unknown type '{tp}'")


def parse_ply(name):
Expand Down
8 changes: 4 additions & 4 deletions meshpy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_refined_face(a, b):
try:
face_points = face_point_dict[a, b]
except KeyError:
a_pt, b_pt = [points[idx] for idx in [a, b]]
a_pt, b_pt = (points[idx] for idx in (a, b))
dx = (b_pt - a_pt)/factor

# build subdivided facet
Expand All @@ -41,13 +41,13 @@ def get_refined_face(a, b):
return face_points

for a, b, c in elements:
a_pt, b_pt, c_pt = [points[idx] for idx in [a, b, c]]
a_pt, b_pt, c_pt = (points[idx] for idx in (a, b, c))
dr = (b_pt - a_pt)/factor
ds = (c_pt - a_pt)/factor

ab_refined, bc_refined, ac_refined = [
ab_refined, bc_refined, ac_refined = (
get_refined_face(*pt_indices)
for pt_indices in [(a, b), (b, c), (a, c)]]
for pt_indices in [(a, b), (b, c), (a, c)])

el_point_dict = {}

Expand Down
17 changes: 11 additions & 6 deletions meshpy/triangle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import ClassVar, List

import meshpy._internals as internals
from meshpy.common import MeshInfoBase, dump_array


class MeshInfo(internals.TriMeshInfo, MeshInfoBase):
_constituents = [
_constituents: ClassVar[List[str]] = [
"points", "point_attributes", "point_markers",
"elements", "element_attributes", "element_volumes",
"neighbors",
Expand Down Expand Up @@ -127,7 +129,7 @@ def build(mesh_info, verbose=False, refinement_func=None, attributes=False,
opts = "pzj"
if quality_meshing:
if min_angle is not None:
opts += "q%f" % min_angle
opts += f"q{min_angle:f}"
else:
opts += "q"

Expand All @@ -145,7 +147,7 @@ def build(mesh_info, verbose=False, refinement_func=None, attributes=False,
if volume_constraints:
opts += "a"
if max_volume:
opts += "a%.20f" % max_volume
opts += f"a{max_volume:.20f}"

if refinement_func is not None:
opts += "u"
Expand Down Expand Up @@ -199,7 +201,7 @@ def refine(input_p, verbose=False, refinement_func=None, quality_meshing=True,

if quality_meshing:
if min_angle is not None:
opts += "q%f" % min_angle
opts += f"q{min_angle:f}"
else:
opts += "q"

Expand Down Expand Up @@ -229,5 +231,8 @@ def write_gnuplot_mesh(filename, out_p, facets=False):

for points in segments:
for pt in points:
gp_file.write("%f %f\n" % tuple(out_p.points[pt]))
gp_file.write("%f %f\n\n" % tuple(out_p.points[points[0]]))
x, y = out_p.points[pt]
gp_file.write(f"{x:f} {y:f}\n")

x, y = out_p.points[points[0]]
gp_file.write(f"{x:f} {y:f}\n\n")
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,24 @@ preview = true
extend-select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"G", # flake8-logging-format
"I", # flake8-isort
"N", # pep8-naming
"NPY", # numpy
"Q", # flake8-quotes
"RUF", # ruff
"UP", # pyupgrade
"W", # pycodestyle
]
extend-ignore = [
"C90", # McCabe complexity
"E226", # missing whitespace around arithmetic operator
"E241", # multiple spaces after comma
"E242", # tab after comma
"E265", # block comment should start with #
"E402", # module level import not at the top of file
"D", # pydocstyle
"C90", # McCabe complexity
]

[tool.ruff.lint.per-file-ignores]
Expand Down

0 comments on commit 242e9b1

Please sign in to comment.