Skip to content

Commit

Permalink
Merge branch 'main' into fix/improve-tox
Browse files Browse the repository at this point in the history
  • Loading branch information
Revathyvenugopal162 authored Oct 7, 2024
2 parents 801800f + 24b3a13 commit f167caf
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ env:
MAPDL_PACKAGE: ghcr.io/ansys/mapdl
ON_CI: True
PYTEST_ARGUMENTS: '-vvv -ra --durations=10 --maxfail=3 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html'
BUILD_CHEATSHEET: True

# Following env vars when changed will "reset" the mentioned cache,
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3460.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: having two global flags. One for visualizer and one for pyvista
1 change: 1 addition & 0 deletions doc/changelog.d/3468.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: add ``build cheatsheet`` as env variable within doc-build
10 changes: 7 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,17 @@
"json_url": f"https://{cname}/versions.json",
"version_match": switcher_version,
},
"cheatsheet": {
}

BUILD_CHEATSHEET = os.environ.get("BUILD_CHEATSHEET", "false").lower() == "true"

if BUILD_CHEATSHEET:
html_theme_options["cheatsheet"] = {
"file": "cheat_sheet/cheat_sheet.qmd",
"title": "PyMAPDL cheat sheet",
"version": f"v{version}",
"pages": ["getting_started/learning"],
},
}
}

html_context = {
"display_github": True, # Integrate GitHub
Expand Down
16 changes: 12 additions & 4 deletions src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,23 @@
_LOCAL_PORTS = []


# Per contract with Sphinx-Gallery, this method must be available at top level
try:
import pyvista
from ansys.tools.visualization_interface import Plotter

_HAS_VISUALIZER = True
except ModuleNotFoundError: # pragma: no cover
LOG.debug("The module 'ansys-tools-visualization_interface' is not installed.")
_HAS_VISUALIZER = False

try:
import pyvista as pv

_HAS_PYVISTA = True
except ModuleNotFoundError: # pragma: no cover
LOG.debug("The module 'PyVista' is not installed.")
LOG.debug("The module 'pyvista' is not installed.")
_HAS_PYVISTA = False


try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError: # pragma: no cover
Expand Down Expand Up @@ -124,7 +132,7 @@

_HAS_ANSYS = _check_has_ansys()

if _HAS_PYVISTA:
if _HAS_VISUALIZER:
from ansys.mapdl.core.plotting.theme import _apply_default_theme

_apply_default_theme()
Expand Down
7 changes: 3 additions & 4 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core import LOG as logger
from ansys.mapdl.core import _HAS_PYVISTA
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.commands import (
CMD_BC_LISTING,
CMD_LISTING,
Expand Down Expand Up @@ -255,15 +255,15 @@ def __init__(
self._mute = False
self._save_selection_obj = None

if _HAS_PYVISTA:
if _HAS_VISUALIZER:
if use_vtk is not None: # pragma: no cover
self._use_vtk = use_vtk
else:
self._use_vtk = True
else: # pragma: no cover
if use_vtk:
raise ModuleNotFoundError(
"Using the keyword argument 'use_vtk' requires having Pyvista installed."
"Using the keyword argument 'use_vtk' requires having 'ansys-tools-visualization_interface' installed."
)
else:
self._use_vtk = False
Expand Down Expand Up @@ -1142,7 +1142,6 @@ def _lockfile(self):
def _mesh(self) -> "Archive":
"""Write entire archive to ASCII and read it in as an
``ansys.mapdl.core.Archive``"""
# lazy import here to avoid loading pyvista and vtk
from ansys.mapdl.reader import Archive

if self._archive_cache is None:
Expand Down
40 changes: 20 additions & 20 deletions src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from numpy.typing import DTypeLike, NDArray

from ansys.mapdl.core import LOG as logger
from ansys.mapdl.core import _HAS_PYVISTA
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.commands import CommandListingOutput
from ansys.mapdl.core.errors import (
CommandDeprecated,
Expand Down Expand Up @@ -425,7 +425,7 @@ def kplot(
HPT - Plots only those keypoints that are hard points.
vtk : bool, optional
Plot the currently selected lines using ``pyvista``.
Plot the currently selected lines using ``ansys-tools-visualization_interface``.
show_keypoint_numbering : bool, optional
Display keypoint numbers when ``vtk=True``.
Expand All @@ -439,9 +439,9 @@ def kplot(
if vtk is None:
vtk = self._use_vtk
elif vtk is True:
if not _HAS_PYVISTA: # pragma: no cover
if not _HAS_VISUALIZER: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)
if vtk:
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter
Expand Down Expand Up @@ -500,7 +500,7 @@ def lplot(
NINC are ignored and display all selected lines [LSEL].
vtk : bool, optional
Plot the currently selected lines using ``pyvista``.
Plot the currently selected lines using ``ansys-tools-visualization_interface``.
show_line_numbering : bool, optional
Display line and keypoint numbers when ``vtk=True``.
Expand Down Expand Up @@ -531,9 +531,9 @@ def lplot(
if vtk is None:
vtk = self._use_vtk
elif vtk is True:
if not _HAS_PYVISTA: # pragma: no cover
if not _HAS_VISUALIZER: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)

if vtk:
Expand Down Expand Up @@ -658,8 +658,8 @@ def aplot(
when ``vtk=True``.
vtk : bool, optional
Plot the currently selected areas using ``pyvista``. As
this creates a temporary surface mesh, this may have a
Plot the currently selected areas using ``ansys-tools-visualization_interface``.
As this creates a temporary surface mesh, this may have a
long execution time for large meshes.
quality : int, optional
Expand Down Expand Up @@ -715,9 +715,9 @@ def aplot(
if vtk is None:
vtk = self._use_vtk
elif vtk is True:
if not _HAS_PYVISTA: # pragma: no cover
if not _HAS_VISUALIZER: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)

if vtk:
Expand Down Expand Up @@ -891,8 +891,8 @@ def vplot(
to .075). Ignored when ``vtk=True``.
vtk : bool, optional
Plot the currently selected volumes using ``pyvista``. As
this creates a temporary surface mesh, this may have a
Plot the currently selected volumes using ``ansys-tools-visualization_interface``.
As this creates a temporary surface mesh, this may have a
long execution time for large meshes.
quality : int, optional
Expand All @@ -917,9 +917,9 @@ def vplot(
if vtk is None:
vtk = self._use_vtk
elif vtk is True:
if not _HAS_PYVISTA: # pragma: no cover
if not _HAS_VISUALIZER: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)

if vtk:
Expand Down Expand Up @@ -1096,12 +1096,12 @@ def nplot(self, nnum="", vtk=None, **kwargs):
vtk = self._use_vtk

if vtk is True:
if _HAS_PYVISTA:
if _HAS_VISUALIZER:
# lazy import here to avoid top level import
import pyvista as pv
else: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)

if "knum" in kwargs:
Expand Down Expand Up @@ -1152,7 +1152,7 @@ def eplot(self, show_node_numbering=False, vtk=None, **kwargs):
Parameters
----------
vtk : bool, optional
Plot the currently selected elements using ``pyvista``.
Plot the currently selected elements using ``ansys-tools-visualization_interface``.
Defaults to current ``use_vtk`` setting.
show_node_numbering : bool, optional
Expand Down Expand Up @@ -1238,9 +1238,9 @@ def eplot(self, show_node_numbering=False, vtk=None, **kwargs):
if vtk is None:
vtk = self._use_vtk
elif vtk is True:
if not _HAS_PYVISTA: # pragma: no cover
if not _HAS_VISUALIZER: # pragma: no cover
raise ModuleNotFoundError(
"Using the keyword argument 'vtk' requires having Pyvista installed."
"Using the keyword argument 'vtk' requires having 'ansys-tools-visualization_interface' installed."
)

if vtk:
Expand Down
10 changes: 9 additions & 1 deletion src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,18 @@ def __init__(
"ansys.api.mapdl.v0", # ansys-api-mapdl-v0
"ansys.mapdl.reader", # ansys-mapdl-reader
"google.protobuf", # protobuf library
"ansys-math-core",
]

# Optional packages
optional = ["matplotlib", "pyvista", "pyiges", "tqdm"]
optional = [
"matplotlib",
"pyvista",
"pyiges",
"tqdm",
"ansys-tools-visualization_interface",
"pandas",
]

if _HAS_PYANSYS_REPORT:
# Combine all packages into one
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from ansys.mapdl.core import _HAS_PYVISTA
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.plotting.consts import ( # noqa: F401
ALLOWED_TARGETS,
BC_D,
Expand All @@ -30,6 +30,6 @@
POINT_SIZE,
)

if _HAS_PYVISTA:
if _HAS_VISUALIZER:
from ansys.mapdl.core.plotting.theme import MapdlTheme # noqa: F401
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter # noqa: F401
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/plotting/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import numpy as np
from numpy.typing import NDArray

from ansys.mapdl.core import _HAS_PYVISTA
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.misc import get_bounding_box
from ansys.mapdl.core.plotting.consts import (
ALLOWED_TARGETS,
Expand All @@ -42,7 +42,7 @@
)
from ansys.mapdl.core.plotting.theme import MapdlTheme

if _HAS_PYVISTA:
if _HAS_VISUALIZER:
import pyvista as pv

from ansys.mapdl.core.plotting.plotting_defaults import DefaultSymbol
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

import numpy as np

from ansys.mapdl.core import _HAS_PYVISTA
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.errors import MapdlRuntimeError
from ansys.mapdl.core.misc import requires_package, supress_logging

if _HAS_PYVISTA:
if _HAS_VISUALIZER:
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

COMPONENT_STRESS_TYPE = ["X", "Y", "Z", "XY", "YZ", "XZ"]
Expand Down

0 comments on commit f167caf

Please sign in to comment.