Skip to content

Commit

Permalink
make meshio an optional dependency (#1939)
Browse files Browse the repository at this point in the history
* make meshio an optional dependency

* add import guards

* make flake8 happy

Co-authored-by: Alex Kaszynski <akascap@gmail.com>
  • Loading branch information
nschloe and akaszynski committed Dec 20, 2021
1 parent 9849318 commit ff64a0e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
3 changes: 1 addition & 2 deletions pyvista/core/filters/unstructured_grid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Filters module with a class to manage filters/algorithms for unstructured grid datasets."""
from functools import wraps

import pyvista
from pyvista import abstract_class
from pyvista.core.filters.poly_data import PolyDataFilters
from pyvista.core.filters.data_set import DataSetFilters
from pyvista.core.filters.poly_data import PolyDataFilters


@abstract_class
Expand Down
10 changes: 6 additions & 4 deletions pyvista/utilities/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@ def __init__(self, additional=None, ncol=3, text_width=80, sort=False,
"""
# Mandatory packages.
core = ['pyvista', 'vtk', 'numpy', 'imageio', 'appdirs', 'scooby',
'meshio']
core = ['pyvista', 'vtk', 'numpy', 'imageio', 'appdirs', 'scooby']

# Optional packages.
optional = ['matplotlib', 'pyvistaqt', 'PyQt5', 'IPython', 'colorcet',
'cmocean', 'ipyvtklink', 'scipy', 'itkwidgets', 'tqdm']
optional = [
'matplotlib', 'pyvistaqt', 'PyQt5', 'IPython', 'colorcet',
'cmocean', 'ipyvtklink', 'scipy', 'itkwidgets', 'tqdm',
'meshio',
]

# Information about the GPU - bare except in case there is a rendering
# bug that the user is trying to report.
Expand Down
21 changes: 18 additions & 3 deletions pyvista/utilities/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def read(filename, attrs=None, force_ext=None, file_format=None):
* ``'.foam'``
.. note::
See https://github.com/nschloe/meshio for formats supported by ``meshio``.
See https://github.com/nschloe/meshio for formats supported by
``meshio``. Be sure to install ``meshio`` with ``pip install
meshio`` if you wish to use it.
Parameters
----------
Expand Down Expand Up @@ -635,7 +637,13 @@ def from_meshio(mesh):

def read_meshio(filename, file_format=None):
"""Read any mesh file using meshio."""
import meshio
try:
import meshio
except ImportError: # pragma: no cover
raise ImportError(
"To use this feature install meshio with:\n\n"
"pip install meshio"
)

# Make sure relative paths will work
filename = os.path.abspath(os.path.expanduser(str(filename)))
Expand Down Expand Up @@ -673,7 +681,14 @@ def save_meshio(filename, mesh, file_format=None, **kwargs):
>>> pyvista.save_meshio('mymesh.inp', sphere) # doctest:+SKIP
"""
import meshio
try:
import meshio
except ImportError: # pragma: no cover
raise ImportError(
"To use this feature install meshio with:\n\n"
"pip install meshio"
)

from meshio.vtk._vtk import vtk_to_meshio_type

# Make sure relative paths will work
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ param==1.10.1
ipygany
pytest-xdist
pythreejs
meshio>=4.0.3, <5.0
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'pillow',
'appdirs',
'scooby>=0.5.1',
'meshio>=4.0.3, <5.0',
'vtk',
'dataclasses;python_version=="3.6"',
'typing_extensions;python_version<="3.7"',
Expand Down Expand Up @@ -70,6 +69,8 @@
python_requires='>=3.6.*',
install_requires=install_requires,
extras_require={
'colormaps': ['matplotlib', 'colorcet', 'cmocean']
'all': ['matplotlib', 'colorcet', 'cmocean', 'meshio'],
'colormaps': ['matplotlib', 'colorcet', 'cmocean'],
'io': ['meshio>=4.0.3, <5.0'],
},
)

0 comments on commit ff64a0e

Please sign in to comment.