ansys / pymapdl

Pythonic interface to MAPDL

Home Page:https://mapdl.docs.pyansys.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplify doc build

germa89 opened this issue · comments

There is a chunk of code which seems unnecesary:

if pymapdl.BUILDING_GALLERY: # pragma: no cover
LOG.debug("Building gallery.")
# launch an instance of pymapdl if it does not already exist and
# we're allowed to start instances
if GALLERY_INSTANCE[0] is None:
mapdl = launch_mapdl(
start_instance=True,
cleanup_on_exit=False,
loglevel=loglevel,
set_no_abort=set_no_abort,
**start_parm,
)
GALLERY_INSTANCE[0] = {"ip": mapdl._ip, "port": mapdl._port}
return mapdl
# otherwise, connect to the existing gallery instance if available
elif GALLERY_INSTANCE[0] is not None:
mapdl = MapdlGrpc(
ip=GALLERY_INSTANCE[0]["ip"],
port=GALLERY_INSTANCE[0]["port"],
cleanup_on_exit=False,
loglevel=loglevel,
set_no_abort=set_no_abort,
use_vtk=use_vtk,
**start_parm,
)
if clear_on_connect:
mapdl.clear()
return mapdl

This does not need to be in the library.

We can just use Sphinx events to spawn an MAPDL instance.

The pseudo code is as follow:

def spawn_mapdl_instance(app, docname, source):
     app._mapdl = launch_mapdl()  # it should account for local and remote.

def kill_mapdl_instance(app, exception):
    app._mapdl.exit()

def setup(app):
    app.connect('builder-inited', spawn_mapdl_instance)
    app.connect('build-finished', kill_mapdl_instance)

This way, we can remove the mentioned code from the library itself. It has been long irritating my eyes.

Reference: https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events

Related to this #2922