diff --git a/.ci/start_fluent.py b/.ci/start_fluent.py deleted file mode 100644 index 284ad250fd9..00000000000 --- a/.ci/start_fluent.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import subprocess -import sys -import tempfile -import time -from typing import List - -from ansys.fluent.core import EXAMPLES_PATH - - -def start_fluent_container(args: List[str]) -> None: - fd, sifile = tempfile.mkstemp( - suffix=".txt", prefix="serverinfo-", dir=EXAMPLES_PATH - ) - os.close(fd) - timeout = 100 - license_server = os.environ["ANSYSLMD_LICENSE_FILE"] - port = os.environ["PYFLUENT_FLUENT_PORT"] - - try: - subprocess.run( - [ - "docker", - "run", - "--name", - "fluent_server", - "-d", - "--rm", - "-p", - f"{port}:{port}", - "-v", - f"{EXAMPLES_PATH}:{EXAMPLES_PATH}", - "-e", - f"ANSYSLMD_LICENSE_FILE={license_server}", - "-e", - f"REMOTING_PORTS={port}/portspan=2", - "-e", - "FLUENT_LAUNCHED_FROM_PYFLUENT=1", - "ghcr.io/pyansys/pyfluent", - "-g", - f"-sifile={sifile}", - ] - + args - ) - - sifile_last_mtime = os.stat(sifile).st_mtime - while True: - if os.stat(sifile).st_mtime > sifile_last_mtime: - time.sleep(1) - break - if timeout == 0: - break - time.sleep(1) - timeout -= 1 - except OSError: - pass - finally: - if os.path.exists(sifile): - os.remove(sifile) - - -if __name__ == "__main__": - start_fluent_container(sys.argv[1:]) diff --git a/.ci/stop_fluent.py b/.ci/stop_fluent.py deleted file mode 100644 index 4ec80ff754c..00000000000 --- a/.ci/stop_fluent.py +++ /dev/null @@ -1,12 +0,0 @@ -import subprocess - - -def stop_fluent_container() -> None: - try: - subprocess.run(["docker", "stop", "fluent_server"]) - except OSError: - pass - - -if __name__ == "__main__": - stop_fluent_container() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f7c4f17e93..ea0f1fc60ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ env: # You should go up in number, if you go down (or repeat a previous value) # you might end up reusing a previous cache if it haven't been deleted already. # It applies 7 days retention policy by default. - RESET_EXAMPLES_CACHE: 0 + RESET_EXAMPLES_CACHE: 1 jobs: stylecheck: @@ -152,15 +152,9 @@ jobs: Examples-v${{ env.RESET_EXAMPLES_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ hashFiles('examples/**') }} - name: Build Documentation - run: | - sudo rm -rf /home/ansys/.local/share/ansys_fluent_core/examples/* - pip install -r requirements_docs.txt - xvfb-run make -C doc html - touch doc/_build/html/.nojekyll - echo "fluentdocs.pyansys.com" >> doc/_build/html/CNAME + run: make build-doc env: ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }} - PYFLUENT_FLUENT_PORT: 63084 PYFLUENT_START_INSTANCE: 0 - name: Upload HTML Documentation diff --git a/.github/workflows/nightly-doc-build.yml b/.github/workflows/nightly-doc-build.yml index 089039b357c..92850bade16 100644 --- a/.github/workflows/nightly-doc-build.yml +++ b/.github/workflows/nightly-doc-build.yml @@ -44,14 +44,9 @@ jobs: run: make docker-pull - name: Build Documentation - run: | - pip install -r requirements_docs.txt - xvfb-run make -C doc html - touch doc/_build/html/.nojekyll - echo "dev.fluentdocs.pyansys.com" >> doc/_build/html/CNAME + run: make build-doc env: ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }} - PYFLUENT_FLUENT_PORT: 63084 PYFLUENT_START_INSTANCE: 0 - name: Deploy diff --git a/Makefile b/Makefile index a3ed3f2073b..877f78b505e 100644 --- a/Makefile +++ b/Makefile @@ -41,3 +41,10 @@ api-codegen: @python codegen/tuigen.py @python codegen/settingsgen.py @python codegen/datamodelgen.py + +build-doc: + @sudo rm -rf /home/ansys/.local/share/ansys_fluent_core/examples/* + @pip install -r requirements_docs.txt + @xvfb-run make -C doc html + @touch doc/_build/html/.nojekyll + @echo "fluentdocs.pyansys.com" >> doc/_build/html/CNAME diff --git a/doc/source/conf.py b/doc/source/conf.py index 145ed7c486d..bf695a2c378 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,14 +1,15 @@ """Sphinx documentation configuration file.""" from datetime import datetime import os +import platform import subprocess -import sys import numpy as np from pyansys_sphinx_theme import pyansys_logo_black import pyvista from sphinx_gallery.sorting import FileNameSortKey +import ansys.fluent.core as pyfluent from ansys.fluent.core import __version__ # Manage errors @@ -27,6 +28,7 @@ # necessary when building the sphinx gallery pyvista.BUILDING_GALLERY = True +pyfluent.BUILDING_GALLERY = True # -- Project information ----------------------------------------------------- @@ -118,32 +120,21 @@ copybutton_prompt_is_regexp = True -_THIS_DIR = os.path.dirname(__file__) -_START_FLUENT_FILE = os.path.normpath( - os.path.join(_THIS_DIR, "..", "..", ".ci", "start_fluent.py") -) -_STOP_FLUENT_FILE = os.path.normpath( - os.path.join(_THIS_DIR, "..", "..", ".ci", "stop_fluent.py") -) - - -def _start_or_stop_fluent_container(gallery_conf, fname, when): - start_instance = bool(int(os.getenv("PYFLUENT_START_INSTANCE", "1"))) - if not start_instance: - if when == "before": - if fname in ["mixing_elbow.py", "exhaust_system.py"]: - args = ["3ddp", "-t2", "-meshing"] - elif fname in [ - "parametric_static_mixer_1.py", - "parametric_static_mixer_2.py", - "parametric_static_mixer_3.py", - ]: - args = ["3ddp", "-t2"] - elif fname in ["post_processing_exhaust_manifold.py"]: - args = ["3ddp", "-t4"] - subprocess.run([sys.executable, _START_FLUENT_FILE] + args) - elif when == "after": - subprocess.run([sys.executable, _STOP_FLUENT_FILE]) +def _stop_fluent_container(gallery_conf, fname): + try: + is_linux = platform.system() == "Linux" + container_names = ( + subprocess.check_output( + "docker container ls --format {{.Names}}", shell=is_linux + ) + .decode("utf-8") + .strip() + .split() + ) + for container_name in container_names: + subprocess.run(f"docker stop {container_name}", shell=is_linux) + except Exception: + pass # -- Sphinx Gallery Options --------------------------------------------------- @@ -167,8 +158,8 @@ def _start_or_stop_fluent_container(gallery_conf, fname, when): "image_scrapers": ("pyvista", "matplotlib"), "ignore_pattern": "flycheck*", "thumbnail_size": (350, 350), - "reset_modules_order": "both", - "reset_modules": (_start_or_stop_fluent_container), + "reset_modules_order": "after", + "reset_modules": (_stop_fluent_container), } diff --git a/src/ansys/fluent/core/__init__.py b/src/ansys/fluent/core/__init__.py index cabd58b42a1..642f494d6b3 100644 --- a/src/ansys/fluent/core/__init__.py +++ b/src/ansys/fluent/core/__init__.py @@ -88,4 +88,3 @@ def disable_logging_to_file() -> None: pass BUILDING_GALLERY = False -RUNNING_PYTEST = False diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 9028b0f2606..52908463171 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -232,7 +232,7 @@ def launch_fluent( else: import ansys.fluent.core as pyfluent - if pyfluent.BUILDING_GALLERY or pyfluent.RUNNING_PYTEST: + if pyfluent.BUILDING_GALLERY or os.getenv("PYFLUENT_LAUNCH_CONTAINER") == "1": args = _build_fluent_launch_args_string(**argvals).split() # Assumes the container OS will be able to create the # EXAMPLES_PATH of host OS. With the Fluent docker diff --git a/tests/conftest.py b/tests/conftest.py index 15acd7c263d..17233f1f2c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,6 @@ import pytest -import ansys.fluent.core as pyfluent - @pytest.fixture def with_running_pytest(monkeypatch: pytest.MonkeyPatch) -> None: - monkeypatch.setattr(pyfluent, "RUNNING_PYTEST", True) + monkeypatch.setenv("PYFLUENT_LAUNCH_CONTAINER", "1")