Skip to content

Commit

Permalink
Update extras require. (#273)
Browse files Browse the repository at this point in the history
* Update setup.py

* Create PyVistaImportError in vtk_helper.py

* Use PyVistaImportError in _PyVistaPlotter and restrain the import check to the __init__.

* Bump PyVista requirement in PyVistaImportError to 0.32.0

* Remove PyVista version checks for 0.30.0 (deprecation of stitle) or 0.32.0 (apparition of return_cpos argument) since the global requirement becomes >=0.32.0

* Fix vtk_helper import

Co-authored-by: paul.profizi <paul.profizi@ansys.com>
  • Loading branch information
akaszynski and PProfizi authored Jul 1, 2022
1 parent 06301fb commit be7450d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 66 deletions.
75 changes: 10 additions & 65 deletions ansys/dpf/core/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ansys.dpf.core.common import locations, DefinitionLabels
from ansys.dpf.core.common import shell_layers as eshell_layers
from ansys.dpf.core import errors as dpf_errors
from ansys.dpf.core.check_version import meets_version


def _sort_supported_kwargs(bound_method, **kwargs):
Expand Down Expand Up @@ -58,13 +57,12 @@ class _PyVistaPlotter:
"""The _InternalPlotter class is based on PyVista."""
def __init__(self, **kwargs):
# Import pyvista
from ansys.dpf.core.vtk_helper import PyVistaImportError
try:
import pyvista as pv
except ModuleNotFoundError:
raise ModuleNotFoundError(
"To use plotting capabilities, please install pyvista "
"with :\n pip install pyvista>=0.24.0"
)
raise PyVistaImportError

# Filter kwargs
kwargs_in = _sort_supported_kwargs(
bound_method=pv.Plotter.__init__,
Expand Down Expand Up @@ -230,56 +228,17 @@ def show_figure(self, **kwargs):
self._plotter.camera_position = cpos

# Show depending on return_cpos option
return_cpos = kwargs.pop("return_cpos", None)
kwargs_in = _sort_supported_kwargs(
bound_method=self._plotter.show, **kwargs)
if return_cpos is None:
return self._plotter.show(**kwargs_in)
else:
import pyvista as pv
pv_version = pv.__version__
version_to_reach = '0.32.0'
meet_ver = meets_version(pv_version, version_to_reach)
if meet_ver:
return self._plotter.show(return_cpos=return_cpos, **kwargs_in)
else:
txt = """To use the return_cpos option, please upgrade
your pyvista module with a version higher than """
txt += version_to_reach
raise core.errors.DpfVersionNotSupported(version_to_reach, txt)
return self._plotter.show(**kwargs_in)

def _set_scalar_bar_title(self, kwargs):
# Import pyvista
try:
import pyvista as pv
except ModuleNotFoundError:
raise ModuleNotFoundError(
"To use plotting capabilities, please install pyvista "
"with :\n pip install pyvista>=0.24.0"
)
stitle = kwargs.pop("stitle", None)
pv_version = pv.__version__
version_to_reach = '0.30.0' # when stitle started to be deprecated
meet_ver = meets_version(pv_version, version_to_reach)
if meet_ver:
# use scalar_bar_args
scalar_bar_args = kwargs.pop("scalar_bar_args", None)
if not scalar_bar_args:
scalar_bar_args = {'title': stitle}
kwargs.setdefault("scalar_bar_args", scalar_bar_args)
else:
# use stitle
has_attribute_scalar_bar = False
try:
has_attribute_scalar_bar = hasattr(self._plotter, 'scalar_bar')
except:
has_attribute_scalar_bar = False

if not has_attribute_scalar_bar:
kwargs.setdefault("stitle", stitle)
else:
if self._plotter.scalar_bar.GetTitle() is None:
kwargs.setdefault("stitle", stitle)
# use scalar_bar_args
scalar_bar_args = kwargs.pop("scalar_bar_args", None)
if not scalar_bar_args:
scalar_bar_args = {'title': stitle}
kwargs.setdefault("scalar_bar_args", scalar_bar_args)
return kwargs


Expand Down Expand Up @@ -736,24 +695,10 @@ def plot_contour(
self._internal_plotter._plotter.camera_position = cpos

# show result
return_cpos = kwargs.pop("return_cpos", None)
kwargs_in = _sort_supported_kwargs(
bound_method=self._internal_plotter._plotter.show,
**kwargs)
if return_cpos is None:
return self._internal_plotter._plotter.show(**kwargs_in)
else:
import pyvista as pv
pv_version = pv.__version__
version_to_reach = '0.32.0'
meet_ver = meets_version(pv_version, version_to_reach)
if meet_ver:
return self._internal_plotter._plotter.show(return_cpos=return_cpos, **kwargs_in)
else:
txt = """To use the return_cpos option, please upgrade
your pyvista module with a version higher than """
txt += version_to_reach
raise core.errors.DpfVersionNotSupported(version_to_reach, txt)
return self._internal_plotter._plotter.show(**kwargs_in)

def _plot_contour_using_vtk_file(self, fields_container, notebook=None):
"""Plot the contour result on its mesh support.
Expand Down
10 changes: 10 additions & 0 deletions ansys/dpf/core/vtk_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@
) # kAnsBeam4 = 31,


class PyVistaImportError(ModuleNotFoundError):
"""Error raised when PyVista could not be imported during plotting."""

def __init__(
self, msg="To use plotting capabilities, please install pyvista "
"with :\n pip install pyvista>=0.32.0"
):
ModuleNotFoundError.__init__(self, msg)


def dpf_mesh_to_vtk(nodes, etypes, connectivity, as_linear=True):
"""Return a pyvista unstructured grid given DPF node and element
definitions.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*",
install_requires=install_requires,
extras_require={
"plotting": ["pyvista>=0.24.0", "matplotlib==3.2"],
"plotting": ["pyvista>=0.32.0", "matplotlib>=3.2"],
"reporting": ["scooby"],
},
url="https://github.com/pyansys/pydpf-core",
Expand Down

0 comments on commit be7450d

Please sign in to comment.