Skip to content
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
17 changes: 4 additions & 13 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,15 @@

- name: Build Python interface
run: |
pip install --check-build-dependencies --no-build-isolation --config-settings=cmake.build-type="Developer" 'python/[test]'
pip install --check-build-dependencies --no-build-isolation --config-settings=cmake.build-type="Developer" 'python/[test,mypy]'
python -c "from mpi4py import MPI; import dolfinx; assert not dolfinx.has_petsc; assert not dolfinx.has_petsc4py; assert dolfinx.has_superlu_dist"

- name: Run mypy
working-directory: python
run: |
pip install mypy types-cffi scipy-stubs
mypy -p dolfinx

- name: Run mypy # Use a venv to avoid NumPy upgrades that are incompatible with numba
working-directory: python
run: |
python -m venv mypy-env
. ./mypy-env/bin/activate
pip install mypy types-cffi scipy-stubs
mypy -p dolfinx
mypy --config-file python/pyproject.toml -p dolfinx # package mode, type checks installed dolfinx (working around name collision in python/ directory)
cd python/
mypy test
mypy demo
#mypy demo # TODO: Enable this in future

Check warning on line 140 in .github/workflows/ccpp.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=FEniCS_dolfinx&issues=AZ5l5z7jxiyXy5aZNbFn&open=AZ5l5z7jxiyXy5aZNbFn&pullRequest=4135

- name: Install gmsh and pyvista (and dependencies)
run: |
Expand Down
22 changes: 18 additions & 4 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@ Below is guidance for building the DOLFINx Python interface.

2. Ensure the Python interface build requirements are installed:

pip install scikit-build-core
python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install
pip install scikit-build-core
python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install

3. Build DOLFINx Python interface:

pip install --check-build-dependencies --no-build-isolation .
pip install --check-build-dependencies --no-build-isolation .

To build in Developer and editable mode for development:

pip -v install --check-build-dependencies --config-settings=build-dir="build" --config-settings=cmake.build-type="Developer" --config-settings=install.strip=false --no-build-isolation -e .

Note that our Developer mode is significantly stricter than CMake's default Debug mode.
Note that Developer mode is significantly stricter than CMake's default Debug mode.

# Type checking with mypy

1. Install DOLFINx Python with the `[mypy]` optional dependencies set, e.g.:

pip install .[mypy]

2. Check with mypy, e.g.:

mypy --config-file pyproject.toml -p dolfinx

The `--config-file pyproject.toml` is mandatory to run mypy with the correct options.
The `-p` flag checks the built/installed package `dolfinx`, containing the C++
bindings and Python interface.
4 changes: 2 additions & 2 deletions python/demo/demo_pyamg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None:
solver_type: pyamg solver type, either "ruge_stuben" or
"smoothed_aggregation"
"""
real_type = np.real(dtype(0)).dtype # type: ignore
real_type = np.real(np.zeros(0, dtype=dtype)).dtype
mesh = create_box(
comm=MPI.COMM_WORLD,
points=[(0.0, 0.0, 0.0), (3.0, 2.0, 1.0)],
Expand All @@ -84,7 +84,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None:

dofs = locate_dofs_topological(V=V, entity_dim=fdim, entities=facets)

bc = dirichletbc(value=dtype(0), dofs=dofs, V=V) # type: ignore
bc = dirichletbc(value=dtype(0.0), dofs=dofs, V=V) # type: ignore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this kind of show that the type hint for dirichletbc is wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem arises from the explicit dtype() invocation:

demo/demo_pyamg.py:87: error: "dtype[Any]" not callable  [operator]

I tried multiple fixes but I am not sure how to correctly create a scalar of a certain type in a typing compliant way. Arrays work fine, but constructor of a dtype seems to be a different case.


u, v = ufl.TrialFunction(V), ufl.TestFunction(V)
x = ufl.SpatialCoordinate(mesh)
Expand Down
5 changes: 2 additions & 3 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ docs = [
"fenics-dolfinx[demo]",
]
lint = ["ruff"]
mypy = ["mypy", "types-cffi", "types-setuptools", "scipy-stubs"]
optional = ["numba"]
petsc4py = ["petsc4py"]
test = [
Expand All @@ -61,12 +62,11 @@ test = [
"fenics-dolfinx[optional]",
]
ci = [
"mypy",
"pytest-xdist",
"types-setuptools",
"fenics-dolfinx[build]",
"fenics-dolfinx[docs]",
"fenics-dolfinx[lint]",
"fenics-dolfinx[mypy]",
"fenics-dolfinx[optional]",
"fenics-dolfinx[test]",
]
Expand Down Expand Up @@ -98,7 +98,6 @@ warn_unused_ignores = false
show_error_codes = true
ignore_missing_imports = true


[tool.ruff]
line-length = 100
indent-width = 4
Expand Down
Loading