Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use launch_fluent to launch container while building gallery #336

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .ci/start_fluent.py

This file was deleted.

12 changes: 0 additions & 12 deletions .ci/stop_fluent.py

This file was deleted.

10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/nightly-doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 20 additions & 29 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +28,7 @@

# necessary when building the sphinx gallery
pyvista.BUILDING_GALLERY = True
pyfluent.BUILDING_GALLERY = True

# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -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):
mkundu1 marked this conversation as resolved.
Show resolved Hide resolved
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 ---------------------------------------------------
Expand All @@ -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),
}


Expand Down
1 change: 0 additions & 1 deletion src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ def disable_logging_to_file() -> None:
pass

BUILDING_GALLERY = False
RUNNING_PYTEST = False
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")