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

Switch to pyproject and ruff #418

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ on:
- cron: '17 3 * * 0'

jobs:
flake8:
name: Flake8
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
uses: actions/setup-python@v5
with:
# matches compat target in setup.py
python-version: '3.8'
submodules: true
- uses: actions/setup-python@v5
- name: "Main Script"
run: |
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
. ./prepare-and-run-flake8.sh "$(basename $GITHUB_REPOSITORY)" test examples
pip install ruff
ruff check

pylint:
name: Pylint
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ a.out
*.h5
*.xmf
*.hdf
*.pdf
*.stl

.cache
.pytest_cache
Expand Down
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ Documentation:
tags:
- python3

Flake8:
script:
- curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
- . ./prepare-and-run-flake8.sh "$CI_PROJECT_NAME" test examples
Ruff:
script: |
pipx install ruff
ruff check
tags:
- python3
- docker-runner
except:
- tags

Expand Down
21 changes: 9 additions & 12 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
include doc/*.rst
include doc/*.sh
include doc/Makefile
include doc/*.py
include doc/conf.py
include doc/images/*.tex
include doc/images/*.png
include doc/images/Makefile

include examples/*.py

include test/*.step
include test/blob2d*.msh
include test/*.sh
include test/annulus.msh
include test/hybrid-cube.msh
include test/blob2d*.msh
include test/cubed-cube.msh
include test/*.sh
include test/gh-394.msh
include test/hybrid-cube.msh
include test/ref-*.pvtu

include README.rst
include LICENSE
prune .ci
prune .github
exclude .gitignore
exclude .gitlab-ci.yml
13 changes: 4 additions & 9 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from importlib import metadata
from urllib.request import urlopen


Expand All @@ -13,15 +14,9 @@

tikz_tikzlibraries = "decorations.markings"

copyright = "2014-21, Meshmode contributors"

ver_dic = {}
with open("../meshmode/version.py") as _inf:
exec(compile(_inf.read(), "../meshmode/version.py", "exec"), ver_dic)

version = ".".join(str(x) for x in ver_dic["VERSION"])
# The full version, including alpha/beta/rc tags.
release = ver_dic["VERSION_TEXT"]
copyright = "2014-2024, Meshmode contributors"
release = metadata.version("meshmode")
version = ".".join(release.split(".")[:2])

intersphinx_mapping = {
"arraycontext": ("https://documen.tician.de/arraycontext", None),
Expand Down
2 changes: 0 additions & 2 deletions examples/.gitignore

This file was deleted.

7 changes: 6 additions & 1 deletion examples/from_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def main(visualize=True):
return 0

from firedrake import (
Function, FunctionSpace, SpatialCoordinate, UnitSquareMesh, cos)
Function,
FunctionSpace,
SpatialCoordinate,
UnitSquareMesh,
cos,
)

from meshmode.interop.firedrake import build_connection_from_firedrake

Expand Down
4 changes: 2 additions & 2 deletions examples/multiple-meshes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys

import numpy as np # noqa
import numpy as np


order = 4


def main():
from meshmode.mesh.generation import make_curve_mesh, starfish # noqa
from meshmode.mesh.generation import make_curve_mesh, starfish
mesh1 = make_curve_mesh(starfish, np.linspace(0, 1, 20), 4)

from meshmode.mesh.processing import affine_map, merge_disjoint_meshes
Expand Down
8 changes: 6 additions & 2 deletions examples/plot-connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ def main():
actx = PyOpenCLArrayContext(queue)

from meshmode.mesh.generation import ( # noqa: F401
generate_icosahedron, generate_sphere, generate_torus)
generate_icosahedron,
generate_sphere,
generate_torus,
)

#mesh = generate_sphere(1, order=order)
mesh = generate_icosahedron(1, order=order)
#mesh = generate_torus(3, 1, order=order)

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
PolynomialWarpAndBlend3DRestrictingGroupFactory)
PolynomialWarpAndBlend3DRestrictingGroupFactory,
)

discr = Discretization(
actx, mesh, PolynomialWarpAndBlend3DRestrictingGroupFactory(order))
Expand Down
23 changes: 15 additions & 8 deletions examples/simple-dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import pyopencl as cl
import pyopencl.array as cla # noqa
from arraycontext import (
ArrayContainer, dataclass_array_container, map_array_container,
with_container_arithmetic)
ArrayContainer,
dataclass_array_container,
map_array_container,
with_container_arithmetic,
)
from pytools import log_process, memoize_method
from pytools.obj_array import flat_obj_array, make_obj_array

Expand Down Expand Up @@ -71,7 +74,8 @@ def __init__(self, actx, mesh, order):

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
PolynomialWarpAndBlend2DRestrictingGroupFactory)
PolynomialWarpAndBlend2DRestrictingGroupFactory,
)
self.group_factory = PolynomialWarpAndBlend2DRestrictingGroupFactory(
order=order)
self.volume_discr = Discretization(actx, mesh, self.group_factory)
Expand Down Expand Up @@ -100,7 +104,9 @@ def boundary_connection(self, boundary_tag):
@memoize_method
def interior_faces_connection(self):
from meshmode.discretization.connection import (
FACE_RESTR_INTERIOR, make_face_restriction)
FACE_RESTR_INTERIOR,
make_face_restriction,
)
return make_face_restriction(
self.volume_discr._setup_actx,
self.volume_discr,
Expand All @@ -118,7 +124,9 @@ def opposite_face_connection(self):
@memoize_method
def all_faces_connection(self):
from meshmode.discretization.connection import (
FACE_RESTR_ALL, make_face_restriction)
FACE_RESTR_ALL,
make_face_restriction,
)
return make_face_restriction(
self.volume_discr._setup_actx,
self.volume_discr,
Expand All @@ -128,8 +136,7 @@ def all_faces_connection(self):

@memoize_method
def get_to_all_face_embedding(self, where):
from meshmode.discretization.connection import (
make_face_to_all_faces_embedding)
from meshmode.discretization.connection import make_face_to_all_faces_embedding

faces_conn = self.get_connection("vol", where)
return make_face_to_all_faces_embedding(
Expand Down Expand Up @@ -395,7 +402,7 @@ def wave_operator(actx, discr, c, q):
u=c*discr.div(q.v),
v=c*discr.grad(q.u)
)
- # noqa: W504
-
discr.inverse_mass(
discr.face_mass(
wave_flux(actx, discr, c=c,
Expand Down
17 changes: 14 additions & 3 deletions examples/to_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def main():

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
InterpolatoryQuadratureSimplexGroupFactory)
InterpolatoryQuadratureSimplexGroupFactory,
)
group_factory = InterpolatoryQuadratureSimplexGroupFactory(order=order)
discr = Discretization(actx, mesh, group_factory)

Expand All @@ -92,8 +93,18 @@ def main():

# set up dirichlet laplace problem in fd and solve
from firedrake import (
Constant, DirichletBC, Function, FunctionSpace, TestFunction, TrialFunction,
dx, grad, inner, project, solve)
Constant,
DirichletBC,
Function,
FunctionSpace,
TestFunction,
TrialFunction,
dx,
grad,
inner,
project,
solve,
)

# because it's easier to write down the variational problem,
# we're going to project from our "DG" space
Expand Down
40 changes: 18 additions & 22 deletions meshmode/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
THE SOFTWARE.
"""

import sys
from warnings import warn

from arraycontext import (
PyOpenCLArrayContext as PyOpenCLArrayContextBase,
PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase)
PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase,
)
from arraycontext.pytest import (
_PytestPyOpenCLArrayContextFactoryWithClass,
_PytestPytatoPyOpenCLArrayContextFactory, register_pytest_array_context_factory)
_PytestPytatoPyOpenCLArrayContextFactory,
register_pytest_array_context_factory,
)


def thaw(actx, ary):
Expand Down Expand Up @@ -157,7 +159,9 @@ def _transform_loopy_inner(t_unit):
# {{{ element/dof iname tag

from meshmode.transform_metadata import (
ConcurrentDOFInameTag, ConcurrentElementInameTag)
ConcurrentDOFInameTag,
ConcurrentElementInameTag,
)
el_inames = [iname.name
for iname in default_ep.inames.values()
if ConcurrentElementInameTag() in iname.tags]
Expand Down Expand Up @@ -321,27 +325,19 @@ def actx_class(self):
)


if sys.version_info >= (3, 7):
def __getattr__(name):
if name not in _actx_names:
raise AttributeError(name)
def __getattr__(name):
if name not in _actx_names:
raise AttributeError(name)

import arraycontext
result = getattr(arraycontext, name)
import arraycontext
result = getattr(arraycontext, name)

warn(f"meshmode.array_context.{name} is deprecated. "
f"Use arraycontext.{name} instead. "
f"meshmode.array_context.{name} will continue to work until 2022.",
DeprecationWarning, stacklevel=2)
warn(f"meshmode.array_context.{name} is deprecated. "
f"Use arraycontext.{name} instead. "
f"meshmode.array_context.{name} will continue to work until 2022.",
DeprecationWarning, stacklevel=2)

return result
else:
def _import_names():
import arraycontext
for name in _actx_names:
globals()[name] = getattr(arraycontext, name)

_import_names()
return result

# }}}

Expand Down
8 changes: 6 additions & 2 deletions meshmode/discretization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
from meshmode.dof_array import DOFArray as _DOFArray
from meshmode.mesh import Mesh as _Mesh, MeshElementGroup as _MeshElementGroup
from meshmode.transform_metadata import (
ConcurrentDOFInameTag, ConcurrentElementInameTag, DiscretizationDOFAxisTag,
DiscretizationElementAxisTag, FirstAxisIsElementsTag)
ConcurrentDOFInameTag,
ConcurrentElementInameTag,
DiscretizationDOFAxisTag,
DiscretizationElementAxisTag,
FirstAxisIsElementsTag,
)


__doc__ = """
Expand Down
Loading
Loading