diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b67850cbc58..985f8f21166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,16 +145,16 @@ jobs: id: cache-api-code with: path: | - src/ansys/fluent/core/datamodel_231 - src/ansys/fluent/core/fluent_version_231.py - src/ansys/fluent/core/meshing/tui_231.py - src/ansys/fluent/core/solver/settings_231 - src/ansys/fluent/core/solver/tui_231.py + src/ansys/fluent/core/generated/datamodel_231 + src/ansys/fluent/core/generated/fluent_version_231.py + src/ansys/fluent/core/generated/meshing/tui_231.py + src/ansys/fluent/core/generated/solver/settings_231 + src/ansys/fluent/core/generated/solver/tui_231.py doc/source/api/meshing/tui doc/source/api/meshing/datamodel doc/source/api/solver/tui doc/source/api/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ env.DOC_DEPLOYMENT_IMAGE_TAG }}-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ env.DOC_DEPLOYMENT_IMAGE_TAG }}-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ env.DOC_DEPLOYMENT_IMAGE_TAG }} - name: Login to GitHub Container Registry @@ -251,17 +251,17 @@ jobs: id: cache-222-api-code with: path: - src/ansys/fluent/core/datamodel_222 - src/ansys/fluent/core/fluent_version_222.py - src/ansys/fluent/core/meshing/tui_222.py - src/ansys/fluent/core/solver/settings_222 - src/ansys/fluent/core/solver/tui_222.py - src/ansys/fluent/core/data/api_tree_222.pickle + src/ansys/fluent/core/generated/datamodel_222 + src/ansys/fluent/core/generated/fluent_version_222.py + src/ansys/fluent/core/generated/meshing/tui_222.py + src/ansys/fluent/core/generated/solver/settings_222 + src/ansys/fluent/core/generated/solver/tui_222.py + src/ansys/fluent/core/generated/data/api_tree_222.pickle doc/source/api/core/meshing/tui doc/source/api/core/meshing/datamodel doc/source/api/core/solver/tui doc/source/api/core/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v22.2.0-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v22.2.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v22.2.0 - name: Login to GitHub Container Registry @@ -285,25 +285,25 @@ jobs: - name: Print 22.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_222.py - python -c "from ansys.fluent.core.solver.settings_222 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_222.py + python -c "from ansys.fluent.core.generated.solver.settings_222 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Cache 23.1 API Code uses: actions/cache@v4 id: cache-231-api-code with: path: - src/ansys/fluent/core/datamodel_231 - src/ansys/fluent/core/fluent_version_231.py - src/ansys/fluent/core/meshing/tui_231.py - src/ansys/fluent/core/solver/settings_231 - src/ansys/fluent/core/solver/tui_231.py - src/ansys/fluent/core/data/api_tree_231.pickle + src/ansys/fluent/core/generated/datamodel_231 + src/ansys/fluent/core/generated/fluent_version_231.py + src/ansys/fluent/core/generated/meshing/tui_231.py + src/ansys/fluent/core/generated/solver/settings_231 + src/ansys/fluent/core/generated/solver/tui_231.py + src/ansys/fluent/core/generated/data/api_tree_231.pickle doc/source/api/core/meshing/tui doc/source/api/core/meshing/datamodel doc/source/api/core/solver/tui doc/source/api/core/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.1.0-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.1.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.1.0 - name: Pull 23.1 Fluent docker image @@ -320,25 +320,25 @@ jobs: - name: Print 23.1 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_231.py - python -c "from ansys.fluent.core.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_231.py + python -c "from ansys.fluent.core.generated.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Cache 23.2 API Code uses: actions/cache@v4 id: cache-232-api-code with: path: - src/ansys/fluent/core/datamodel_232 - src/ansys/fluent/core/fluent_version_232.py - src/ansys/fluent/core/meshing/tui_232.py - src/ansys/fluent/core/solver/settings_232 - src/ansys/fluent/core/solver/tui_232.py - src/ansys/fluent/core/data/api_tree_232.pickle + src/ansys/fluent/core/generated/datamodel_232 + src/ansys/fluent/core/generated/fluent_version_232.py + src/ansys/fluent/core/generated/meshing/tui_232.py + src/ansys/fluent/core/generated/solver/settings_232 + src/ansys/fluent/core/generated/solver/tui_232.py + src/ansys/fluent/core/generated/data/api_tree_232.pickle doc/source/api/core/meshing/tui doc/source/api/core/meshing/datamodel doc/source/api/core/solver/tui doc/source/api/core/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.2.0-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.2.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v23.2.0 - name: Pull 23.2 Fluent docker image @@ -355,25 +355,25 @@ jobs: - name: Print 23.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_232.py - python -c "from ansys.fluent.core.solver.settings_232 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_232.py + python -c "from ansys.fluent.core.generated.solver.settings_232 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Cache 24.1 API Code uses: actions/cache@v4 id: cache-241-api-code with: path: - src/ansys/fluent/core/datamodel_241 - src/ansys/fluent/core/fluent_version_241.py - src/ansys/fluent/core/meshing/tui_241.py - src/ansys/fluent/core/solver/settings_241 - src/ansys/fluent/core/solver/tui_241.py - src/ansys/fluent/core/data/api_tree_241.pickle + src/ansys/fluent/core/generated/datamodel_241 + src/ansys/fluent/core/generated/fluent_version_241.py + src/ansys/fluent/core/generated/meshing/tui_241.py + src/ansys/fluent/core/generated/solver/settings_241 + src/ansys/fluent/core/generated/solver/tui_241.py + src/ansys/fluent/core/generated/data/api_tree_241.pickle doc/source/api/core/meshing/tui doc/source/api/core/meshing/datamodel doc/source/api/core/solver/tui doc/source/api/core/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.1.0-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.1.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.1.0 - name: Pull 24.1 Fluent docker image @@ -390,25 +390,25 @@ jobs: - name: Print 24.1 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_241.py - python -c "from ansys.fluent.core.solver.settings_241 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_241.py + python -c "from ansys.fluent.core.generated.solver.settings_241 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Cache 24.2 API Code uses: actions/cache@v4 id: cache-242-api-code with: path: - src/ansys/fluent/core/datamodel_242 - src/ansys/fluent/core/fluent_version_242.py - src/ansys/fluent/core/meshing/tui_242.py - src/ansys/fluent/core/solver/settings_242 - src/ansys/fluent/core/solver/tui_242.py - src/ansys/fluent/core/data/api_tree_242.pickle + src/ansys/fluent/core/generated/datamodel_242 + src/ansys/fluent/core/generated/fluent_version_242.py + src/ansys/fluent/core/generated/meshing/tui_242.py + src/ansys/fluent/core/generated/solver/settings_242 + src/ansys/fluent/core/generated/solver/tui_242.py + src/ansys/fluent/core/generated/data/api_tree_242.pickle doc/source/api/core/meshing/tui doc/source/api/core/meshing/datamodel doc/source/api/core/solver/tui doc/source/api/core/solver/datamodel - key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.2.0-${{ hashFiles('codegen/**') }} + key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.2.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }} restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v24.2.0 - name: Pull 24.2 Fluent docker image @@ -425,8 +425,8 @@ jobs: - name: Print 24.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_242.py - python -c "from ansys.fluent.core.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_242.py + python -c "from ansys.fluent.core.generated.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Install again after codegen run: | diff --git a/.github/workflows/test-run-custom.yml b/.github/workflows/test-run-custom.yml index caeada3c829..1a99d880f71 100644 --- a/.github/workflows/test-run-custom.yml +++ b/.github/workflows/test-run-custom.yml @@ -84,7 +84,7 @@ jobs: - name: Print Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_${{ matrix.version }}.py + cat src/ansys/fluent/core/generated/fluent_version_${{ matrix.version }}.py - name: Install again after codegen run: | diff --git a/.github/workflows/test-run-dev-version-nightly.yml b/.github/workflows/test-run-dev-version-nightly.yml index 90c0ca679d4..e68e38b6b3d 100644 --- a/.github/workflows/test-run-dev-version-nightly.yml +++ b/.github/workflows/test-run-dev-version-nightly.yml @@ -66,8 +66,8 @@ jobs: - name: Print 24.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_242.py - python -c "from ansys.fluent.core.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_242.py + python -c "from ansys.fluent.core.generated.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Install again after codegen run: | diff --git a/.github/workflows/test-run-nightly.yml b/.github/workflows/test-run-nightly.yml index e42b6139c8f..a96f42c1ff1 100644 --- a/.github/workflows/test-run-nightly.yml +++ b/.github/workflows/test-run-nightly.yml @@ -66,8 +66,8 @@ jobs: - name: Print 24.1 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_241.py - python -c "from ansys.fluent.core.solver.settings_241 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_241.py + python -c "from ansys.fluent.core.generated.solver.settings_241 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Install again after codegen run: | diff --git a/.github/workflows/test-run-old-versions-weekly.yml b/.github/workflows/test-run-old-versions-weekly.yml index f2466b46de6..851f67204fa 100644 --- a/.github/workflows/test-run-old-versions-weekly.yml +++ b/.github/workflows/test-run-old-versions-weekly.yml @@ -66,8 +66,8 @@ jobs: - name: Print 22.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_222.py - python -c "from ansys.fluent.core.solver.settings_222 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_222.py + python -c "from ansys.fluent.core.generated.solver.settings_222 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Pull 23.1 Fluent docker image run: make docker-pull @@ -81,8 +81,8 @@ jobs: - name: Print 23.1 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_231.py - python -c "from ansys.fluent.core.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_231.py + python -c "from ansys.fluent.core.generated.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Pull 23.2 Fluent docker image run: make docker-pull @@ -96,8 +96,8 @@ jobs: - name: Print 23.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_232.py - python -c "from ansys.fluent.core.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_232.py + python -c "from ansys.fluent.core.generated.solver.settings_231 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Install again after codegen run: | diff --git a/.github/workflows/test-run-solvermode-weekly.yml b/.github/workflows/test-run-solvermode-weekly.yml index cafac5e3792..333d3b60c89 100644 --- a/.github/workflows/test-run-solvermode-weekly.yml +++ b/.github/workflows/test-run-solvermode-weekly.yml @@ -63,8 +63,8 @@ jobs: - name: Print 24.2 Fluent version info run: | - cat src/ansys/fluent/core/fluent_version_242.py - python -c "from ansys.fluent.core.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" + cat src/ansys/fluent/core/generated/fluent_version_242.py + python -c "from ansys.fluent.core.generated.solver.settings_242 import SHASH; print(f'SETTINGS_HASH = {SHASH}')" - name: Install again after codegen run: | diff --git a/.gitignore b/.gitignore index 4d27dd64bc4..53b9b4e9691 100644 --- a/.gitignore +++ b/.gitignore @@ -140,11 +140,7 @@ dmypy.json .vscode # generated API files -src/ansys/fluent/core/fluent_version_*.py -src/ansys/fluent/core/meshing/tui_*.py -src/ansys/fluent/core/solver/tui_*.py -src/ansys/fluent/core/datamodel_*/ -src/ansys/fluent/core/solver/settings_*/ +src/ansys/fluent/core/generated/ # Fluent generated files *.trn diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10e2221e8fb..685c482b5d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: 'flake8-annotations==3.0.1' ] args: [ - --exclude, src/ansys/fluent/core/meshing/tui* src/ansys/fluent/core/solver/tui* src/ansys/fluent/core/datamodel_222/* src/ansys/fluent/core/datamodel_231/* src/ansys/fluent/core/datamodel_232/* src/ansys/fluent/core/datamodel_241/* src/ansys/fluent/core/solver/settings_222/* src/ansys/fluent/core/solver/settings_231/* src/ansys/fluent/core/solver/settings_232/* src/ansys/fluent/core/solver/settings_241/*, + --exclude, src/ansys/fluent/core/generated, --select, W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806, #--select, W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806 ANN001 ANN201 ANN205 ANN206, --count, @@ -37,7 +37,7 @@ repos: --max-complexity, "10", --max-line-length, "88", --extend-ignore, E203 E501, - ansys, codegen, doc, examples, tests + ansys, doc, examples, tests ] - repo: https://github.com/codespell-project/codespell diff --git a/MANIFEST.in b/MANIFEST.in index 7fa0e0b6139..00d76d54177 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,5 +3,5 @@ include src/ansys/fluent/core/docs/README.rst include src/ansys/fluent/core/logging_config.yaml include src/ansys/fluent/core/quantity/cfg.yaml include src/ansys/fluent/core/launcher/watchdog_exec -recursive-include src/ansys/fluent/core *pyi -recursive-include src/ansys/fluent/core/data api_tree_*.pickle \ No newline at end of file +recursive-include src/ansys/fluent/core *.pyi +recursive-include src/ansys/fluent/core *.pickle \ No newline at end of file diff --git a/README.rst b/README.rst index f946eb1591b..12ec78fbc88 100644 --- a/README.rst +++ b/README.rst @@ -55,12 +55,12 @@ development version or previously released versions. You can also `view `_ or `download `_ the PyFluent cheat sheet. This one-page reference provides syntax rules and commands -for using PyFluent. +for using PyFluent. On the `PyFluent Issues `_ page, you can create issues to report bugs and request new features. On the `PyFluent Discussions `_ page or the `Discussions `_ -page on the Ansys Developer portal, you can post questions, share ideas, and get community feedback. +page on the Ansys Developer portal, you can post questions, share ideas, and get community feedback. To reach the project support team, email `pyansys.core@ansys.com `_. diff --git a/codegen/allapigen.py b/codegen/allapigen.py index 2f595cc9f37..17ec18965a2 100644 --- a/codegen/allapigen.py +++ b/codegen/allapigen.py @@ -1,68 +1,6 @@ -import argparse -import os -from pathlib import Path -import pickle - -import datamodelgen -import print_fluent_version -import settingsgen -import tuigen - -from ansys.fluent.core import FluentMode, launch_fluent -from ansys.fluent.core.utils.fluent_version import ( - FluentVersion, - get_version_for_file_name, -) -from ansys.fluent.core.utils.search import get_api_tree_file_name - - -def _update_first_level(d, u): - for k in d: - d[k].update(u.get(k, {})) +"""Helper module to generate Fluent API classes.""" +from ansys.fluent.core.codegen.allapigen import generate if __name__ == "__main__": - api_tree = {"": {}, "": {}} - parser = argparse.ArgumentParser( - description="Generate python code from Fluent APIs" - ) - parser.add_argument( - "--pyfluent-path", - dest="pyfluent_path", - help="Specify the pyfluent installation folder to patch, with full path. Such as /my-venv/Lib/site-packages", - ) - if not os.getenv("PYFLUENT_LAUNCH_CONTAINER"): - parser.add_argument( - "--ansys-version", - dest="ansys_version", - help=f"Specify the ansys package version to use, default is {FluentVersion.get_latest_installed().value}", - ) - parser.add_argument( - "--fluent-path", - dest="fluent_path", - help="Specify the fluent folder to use, with full path. Such as /apps/ansys_inc/v232/fluent", - ) - - args = parser.parse_args() - if not os.getenv("PYFLUENT_LAUNCH_CONTAINER"): - if args.ansys_version: - awp_root = os.environ[FluentVersion(args.ansys_version).awp_var] - os.environ["PYFLUENT_FLUENT_ROOT"] = str(Path(awp_root) / "fluent") - if args.fluent_path: - os.environ["PYFLUENT_FLUENT_ROOT"] = args.fluent_path - sessions = {FluentMode.SOLVER: launch_fluent()} - version = get_version_for_file_name(session=sessions[FluentMode.SOLVER]) - print_fluent_version.generate(args.pyfluent_path, sessions) - _update_first_level( - api_tree, tuigen.generate(version, args.pyfluent_path, sessions) - ) - _update_first_level( - api_tree, datamodelgen.generate(version, args.pyfluent_path, sessions) - ) - _update_first_level( - api_tree, settingsgen.generate(version, args.pyfluent_path, sessions) - ) - api_tree_file = get_api_tree_file_name(version, args.pyfluent_path) - Path(api_tree_file).parent.mkdir(parents=True, exist_ok=True) - with open(api_tree_file, "wb") as f: - pickle.dump(api_tree, f) + generate() diff --git a/codegen/data/tui_menu_descriptions.py b/codegen/data/tui_menu_descriptions.py deleted file mode 100644 index 7bad3f3cfc4..00000000000 --- a/codegen/data/tui_menu_descriptions.py +++ /dev/null @@ -1 +0,0 @@ -MENU_DESCRIPTIONS = {} diff --git a/doc/rstgen.py b/doc/rstgen.py index 96525cc96b3..7efaec04285 100644 --- a/doc/rstgen.py +++ b/doc/rstgen.py @@ -214,6 +214,7 @@ def _get_path(mode: str, is_datamodel: Optional[bool] = None): "ansys", "fluent", "core", + "generated", ) ) else: @@ -225,6 +226,7 @@ def _get_path(mode: str, is_datamodel: Optional[bool] = None): "ansys", "fluent", "core", + "generated", f"{mode}", ) ) diff --git a/doc/settings_rstgen.py b/doc/settings_rstgen.py index 8c8375910a7..f8b5a52c54a 100644 --- a/doc/settings_rstgen.py +++ b/doc/settings_rstgen.py @@ -126,7 +126,7 @@ def _populate_rst_from_settings(rst_dir, cls, version): r.write(f"{cls_name}\n") r.write(f'{"="*(len(cls_name))}\n\n') r.write( - f".. autoclass:: ansys.fluent.core.solver.settings_{version}.{file_name}.{cls_name}\n" + f".. autoclass:: ansys.fluent.core.generated.solver.settings_{version}.{file_name}.{cls_name}\n" ) r.write(f"{istr1}:show-inheritance:\n\n") @@ -218,6 +218,8 @@ def _populate_rst_from_settings(rst_dir, cls, version): image_tag = os.getenv("FLUENT_IMAGE_TAG", "v24.1.0") version = get_version_for_file_name(image_tag.lstrip("v")) - settings = importlib.import_module(f"ansys.fluent.core.solver.settings_{version}") + settings = importlib.import_module( + f"ansys.fluent.core.generated.solver.settings_{version}" + ) _populate_parents_list(settings.root) _populate_rst_from_settings(rst_dir, settings.root, version) diff --git a/doc/source/api/meshing/index.rst b/doc/source/api/meshing/index.rst index 3675cea4a7c..aeb8a4dfc12 100644 --- a/doc/source/api/meshing/index.rst +++ b/doc/source/api/meshing/index.rst @@ -14,7 +14,6 @@ Workflow example import ansys.fluent.core as pyfluent meshing = pyfluent.launch_fluent(mode="meshing") - meshing.transcript.start() meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") meshing.workflow.TaskObject["Import Geometry"].Arguments = {"FileName": "cylinder.agdb"} meshing.workflow.TaskObject["Import Geometry"].Execute() diff --git a/doc/source/api/solver/settings.rst b/doc/source/api/solver/settings.rst index cb7d3665f1c..abd9fbee9d1 100644 --- a/doc/source/api/solver/settings.rst +++ b/doc/source/api/solver/settings.rst @@ -18,10 +18,10 @@ the following code snippets) whose interface directly exposes the >>> solver = pyfluent.launch_fluent(mode="solver") -The ``solver`` object contains attributes such as :obj:`~ansys.fluent.core.solver.settings_232.file.file`, -:obj:`~ansys.fluent.core.solver.settings_232.setup.setup`, -:obj:`~ansys.fluent.core.solver.settings_232.solution.solution`, and -:obj:`~ansys.fluent.core.solver.settings_232.results.results`, +The ``solver`` object contains attributes such as :obj:`~ansys.fluent.core.generated.solver.settings_232.file.file`, +:obj:`~ansys.fluent.core.generated.solver.settings_232.setup.setup`, +:obj:`~ansys.fluent.core.generated.solver.settings_232.solution.solution`, and +:obj:`~ansys.fluent.core.generated.solver.settings_232.results.results`, which are also instances of settings objects. Note that the last three are top-level nodes in the outline tree view in Fluent's graphical user interface (GUI) --- much of this settings hierarchy has been designed in close alignment with this GUI hierarchy. @@ -41,9 +41,9 @@ of container objects: :obj:`~ansys.fluent.core.solver.flobject.Group`, - The :obj:`~ansys.fluent.core.solver.flobject.Group` type is a static container with predefined child objects that can be accessed as attributes. For example, using the expression ``solver.setup.models.energy``, - which resolves to :obj:`~ansys.fluent.core.solver.settings_232.energy.energy`, - which is a child of :obj:`~ansys.fluent.core.solver.settings_232.models_1.models`, - which itself is a child of :obj:`~ansys.fluent.core.solver.settings_232.setup.setup`, and each of those + which resolves to :obj:`~ansys.fluent.core.generated.solver.settings_232.energy.energy`, + which is a child of :obj:`~ansys.fluent.core.generated.solver.settings_232.models_1.models`, + which itself is a child of :obj:`~ansys.fluent.core.generated.solver.settings_232.setup.setup`, and each of those three objects is a ``Group``. The names of the child objects of a group can be accessed via ``.child_names``. diff --git a/doc/source/conf.py b/doc/source/conf.py index 35c17146654..940864b95b5 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -76,9 +76,10 @@ # type, unless multiple values are being returned" } numpydoc_validation_exclude = { - "ansys.fluent.core.solver.settings_231.", - "ansys.fluent.core.solver.settings_232.", - "ansys.fluent.core.solver.settings_241.", + "ansys.fluent.core.generated.solver.settings_231.", + "ansys.fluent.core.generated.solver.settings_232.", + "ansys.fluent.core.generated.solver.settings_241.", + "ansys.fluent.core.generated.solver.settings_242.", "ansys.fluent.core.services.batch_ops.BatchOps.__init__", } diff --git a/doc/source/user_guide/tui_commands.rst b/doc/source/user_guide/tui_commands.rst index a7fcc6f4f65..6cca7150b07 100644 --- a/doc/source/user_guide/tui_commands.rst +++ b/doc/source/user_guide/tui_commands.rst @@ -40,7 +40,7 @@ To see the documentation for the viscous model menu options, you can run: .. code-block:: python >>> help(solver.tui.define.models.viscous) - Help on viscous in module ansys.fluent.core.solver.tui_241 object: + Help on viscous in module ansys.fluent.core.generated.solver.tui_241 object: class viscous(ansys.fluent.core.services.datamodel_tui.TUIMenu) | viscous(service, version, mode, path) diff --git a/pylintrc b/pylintrc index ce6e27a656c..901a976e412 100644 --- a/pylintrc +++ b/pylintrc @@ -2,7 +2,7 @@ load-plugins = pylint.extensions.docparams disable = all enable = missing-raises-doc, missing-module-docstring, missing-class-docstring, missing-function-docstring, missing-param-doc -ignore-paths = codegen, tests +ignore-paths = tests [BASIC] accept-no-raise-doc = no diff --git a/pyproject.toml b/pyproject.toml index 6b1da5bc5dd..044b7e398fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,12 +20,13 @@ classifiers = [ ] include = [ - { path = "src/ansys/fluent/core/fluent_version_*.py", format = ["sdist", "wheel"] }, - { path = "src/ansys/fluent/core/meshing/tui_*.py", format = ["sdist", "wheel"] }, - { path = "src/ansys/fluent/core/solver/tui_*.py", format = ["sdist", "wheel"] }, - { path = "src/ansys/fluent/core/datamodel_*/*.py", format = ["sdist", "wheel"] }, - { path = "src/ansys/fluent/core/solver/settings_*/*.py", format = ["sdist", "wheel"] }, - { path = "src/ansys/fluent/core/solver/settings_*/*.pyi", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/fluent_version_*.py", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/meshing/tui_*.py", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/solver/tui_*.py", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/datamodel_*/*.py", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/solver/settings_*/*.py", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/solver/settings_*/*.pyi", format = ["sdist", "wheel"] }, + { path = "src/ansys/fluent/core/generated/*.pickle", format = ["sdist", "wheel"] }, ] packages = [ @@ -119,23 +120,18 @@ force_sort_within_sections = true line_length = 88 default_section = "THIRDPARTY" skip_glob = [ - "src/ansys/fluent/core/meshing/tui", - "src/ansys/fluent/core/solver/tui", - "src/ansys/fluent/core/datamodel_222", - "src/ansys/fluent/core/datamodel_231", - "src/ansys/fluent/core/datamodel_232", - "src/ansys/fluent/core/datamodel_241", - "src/ansys/fluent/core/solver/settings_222", - "src/ansys/fluent/core/solver/settings_231", - "src/ansys/fluent/core/solver/settings_232", - "src/ansys/fluent/core/solver/settings_241" + "src/ansys/fluent/core/generated" ] filter_files = "true" known_first_party = ["ansys"] [tool.codespell] -skip = "*.xml,./src/ansys/fluent/core/meshing/tui*,./src/ansys/fluent/core/solver/tui*,./src/ansys/fluent/core/datamodel_222/*,./src/ansys/fluent/core/datamodel_231/*,./src/ansys/fluent/core/datamodel_232/*,./src/ansys/fluent/core/datamodel_241/*,./codegen/data/fluent_gui_help.xml,./src/ansys/fluent/core/solver/settings_222/*,./src/ansys/fluent/core/solver/settings_231/*,./src/ansys/fluent/core/solver/settings_232/*,./src/ansys/fluent/core/solver/settings_241/*" +skip = """ + *.xml, + ./src/ansys/fluent/core/generated/*, + ./src/ansys/fluent/core/codegen/data/fluent_gui_help.xml, + """ ignore-words = ".github/styles/config/vocabularies/ANSYS/accept.txt" @@ -143,22 +139,7 @@ ignore-words = ".github/styles/config/vocabularies/ANSYS/accept.txt" in-place = "true" exclude = [ "tests/", - "src/ansys/fluent/core/meshing/tui_222.py", - "src/ansys/fluent/core/solver/tui_222.py", - "src/ansys/fluent/core/solver/settings_222/", - "src/ansys/fluent/core/datamodel_222/", - "src/ansys/fluent/core/meshing/tui_231.py", - "src/ansys/fluent/core/solver/tui_231.py", - "src/ansys/fluent/core/solver/settings_231/", - "src/ansys/fluent/core/datamodel_231/", - "src/ansys/fluent/core/meshing/tui_232.py", - "src/ansys/fluent/core/solver/tui_232.py", - "src/ansys/fluent/core/solver/settings_232/", - "src/ansys/fluent/core/datamodel_232/", - "src/ansys/fluent/core/meshing/tui_241.py", - "src/ansys/fluent/core/solver/tui_241.py", - "src/ansys/fluent/core/solver/settings_241/", - "src/ansys/fluent/core/datamodel_241/" + "src/ansys/fluent/core/generated/", ] black = "true" non-cap = [ @@ -181,11 +162,7 @@ non-cap = [ [tool.coverage.run] source = ["ansys/fluent"] omit = [ - "*/ansys/fluent/core/fluent_version_*", - "*/ansys/fluent/core/meshing/tui_*", - "*/ansys/fluent/core/solver/tui_*", - "*/ansys/fluent/core/solver/settings_*/*", - "*/ansys/fluent/core/datamodel_*/*" + "*/ansys/fluent/core/generated/*", ] [tool.coverage.report] diff --git a/src/ansys/fluent/core/__init__.py b/src/ansys/fluent/core/__init__.py index 85b07198a8f..3b1694e5448 100644 --- a/src/ansys/fluent/core/__init__.py +++ b/src/ansys/fluent/core/__init__.py @@ -1,6 +1,7 @@ """A package providing Fluent's Solver and Meshing capabilities in Python.""" import os +from pathlib import Path import pydoc import platformdirs @@ -83,7 +84,11 @@ def version_info() -> str: # Whether stream and cache commands state DATAMODEL_USE_NOCOMMANDS_DIFF_STATE = True +# Parent directory where codegen writes out API files +GENERATED_API_DIR = (Path(__file__) / ".." / "generated").resolve() + +# TODO: clean up the following and related code def wrap_api_call(f, *args, **kwargs): """Wrap API call.""" # overwritten in PyConsole diff --git a/codegen/__init__.py b/src/ansys/fluent/core/codegen/__init__.py similarity index 100% rename from codegen/__init__.py rename to src/ansys/fluent/core/codegen/__init__.py diff --git a/src/ansys/fluent/core/codegen/allapigen.py b/src/ansys/fluent/core/codegen/allapigen.py new file mode 100644 index 00000000000..eee65c8ac46 --- /dev/null +++ b/src/ansys/fluent/core/codegen/allapigen.py @@ -0,0 +1,65 @@ +"""Module to generate Fluent API classes.""" + +import argparse +import os +from pathlib import Path +import pickle + +from ansys.fluent.core import FluentMode, launch_fluent +from ansys.fluent.core.codegen import ( + datamodelgen, + print_fluent_version, + settingsgen, + tuigen, +) +from ansys.fluent.core.utils.fluent_version import ( + FluentVersion, + get_version_for_file_name, +) +from ansys.fluent.core.utils.search import get_api_tree_file_name + + +def _update_first_level(d, u): + for k in d: + d[k].update(u.get(k, {})) + + +def generate(): + """Generate Fluent API classes.""" + api_tree = {"": {}, "": {}} + parser = argparse.ArgumentParser( + description="Generate python code from Fluent APIs" + ) + if not os.getenv("PYFLUENT_LAUNCH_CONTAINER"): + parser.add_argument( + "--ansys-version", + dest="ansys_version", + help=f"Specify the ansys package version to use, default is {FluentVersion.get_latest_installed().value}", + ) + parser.add_argument( + "--fluent-path", + dest="fluent_path", + help="Specify the fluent folder to use, with full path. Such as /apps/ansys_inc/v232/fluent", + ) + + args = parser.parse_args() + if not os.getenv("PYFLUENT_LAUNCH_CONTAINER"): + if args.ansys_version: + awp_root = os.environ[FluentVersion(args.ansys_version).awp_var] + os.environ["PYFLUENT_FLUENT_ROOT"] = str(Path(awp_root) / "fluent") + if args.fluent_path: + os.environ["PYFLUENT_FLUENT_ROOT"] = args.fluent_path + sessions = {FluentMode.SOLVER: launch_fluent()} + version = get_version_for_file_name(session=sessions[FluentMode.SOLVER]) + print_fluent_version.generate(sessions) + _update_first_level(api_tree, tuigen.generate(version, sessions)) + _update_first_level(api_tree, datamodelgen.generate(version, sessions)) + _update_first_level(api_tree, settingsgen.generate(version, sessions)) + api_tree_file = get_api_tree_file_name(version) + Path(api_tree_file).parent.mkdir(parents=True, exist_ok=True) + with open(api_tree_file, "wb") as f: + pickle.dump(api_tree, f) + + +if __name__ == "__main__": + generate() diff --git a/codegen/data/__init__.py b/src/ansys/fluent/core/codegen/data/__init__.py similarity index 100% rename from codegen/data/__init__.py rename to src/ansys/fluent/core/codegen/data/__init__.py diff --git a/codegen/data/fluent_gui_help_patch.py b/src/ansys/fluent/core/codegen/data/fluent_gui_help_patch.py similarity index 86% rename from codegen/data/fluent_gui_help_patch.py rename to src/ansys/fluent/core/codegen/data/fluent_gui_help_patch.py index d312fd8fde9..ba0c51a3bb4 100644 --- a/codegen/data/fluent_gui_help_patch.py +++ b/src/ansys/fluent/core/codegen/data/fluent_gui_help_patch.py @@ -1,3 +1,5 @@ +"""Module containing the corrected Fluent GUI help strings.""" + XML_HELP_PATCH = { "flu_meshing_file_start_transcript": "Starts recording input and output in a file. A transcript file contains a complete record of all standard input to and output from Fluent (usually all keyboard and user interface input and all screen output).Start the transcription process with the file/start-transcript command, and end it with the file/stop-transcript command (or by exiting the program)." } diff --git a/codegen/data/static_info_222_meshing.pickle b/src/ansys/fluent/core/codegen/data/static_info_222_meshing.pickle similarity index 100% rename from codegen/data/static_info_222_meshing.pickle rename to src/ansys/fluent/core/codegen/data/static_info_222_meshing.pickle diff --git a/codegen/data/static_info_222_solver.pickle b/src/ansys/fluent/core/codegen/data/static_info_222_solver.pickle similarity index 100% rename from codegen/data/static_info_222_solver.pickle rename to src/ansys/fluent/core/codegen/data/static_info_222_solver.pickle diff --git a/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py similarity index 91% rename from codegen/datamodelgen.py rename to src/ansys/fluent/core/codegen/datamodelgen.py index 007f91ed265..6ef086cfdd0 100644 --- a/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -1,17 +1,19 @@ +"""Module to generate Fluent datamodel API classes.""" + from io import FileIO import os from pathlib import Path import shutil from typing import Any, Dict -from ansys.fluent.core import FluentMode, launch_fluent +from ansys.fluent.core import GENERATED_API_DIR, FluentMode, launch_fluent from ansys.fluent.core.session import BaseSession as Session from ansys.fluent.core.utils.fluent_version import ( FluentVersion, get_version_for_file_name, ) -_THIS_DIR = Path(__file__).parent +_ROOT_DIR = Path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." _PY_TYPE_BY_DM_TYPE = { **dict.fromkeys(["Logical", "Bool"], "bool"), @@ -36,10 +38,11 @@ "None": "None", } +# TODO: Move doc specific variables to docgen + _MESHING_DM_DOC_DIR = os.path.normpath( os.path.join( - _THIS_DIR, - "..", + _ROOT_DIR, "doc", "source", "api", @@ -49,8 +52,7 @@ ) _SOLVER_DM_DOC_DIR = os.path.normpath( os.path.join( - _THIS_DIR, - "..", + _ROOT_DIR, "doc", "source", "api", @@ -82,11 +84,12 @@ def _build_command_query_docstring(name: str, info: Any, indent: str, is_command class DataModelStaticInfo: + """Stores datamodel static information.""" + _noindices = [] def __init__( self, - pyfluent_path: str, rules: str, modes: tuple, version: str, @@ -97,13 +100,7 @@ def __init__( self.static_info = None if rules_save_name == "": rules_save_name = rules - datamodel_dir = ( - (Path(pyfluent_path) if pyfluent_path else (Path(_THIS_DIR) / ".." / "src")) - / "ansys" - / "fluent" - / "core" - / f"datamodel_{version}" - ).resolve() + datamodel_dir = (GENERATED_API_DIR / f"datamodel_{version}").resolve() datamodel_dir.mkdir(exist_ok=True) self.file_name = (datamodel_dir / f"{rules_save_name}.py").resolve() if len(modes) > 1: @@ -112,12 +109,13 @@ def __init__( class DataModelGenerator: - def __init__(self, version, pyfluent_path, sessions: dict): + """Provides the datamodel API class generator.""" + + def __init__(self, version, sessions: dict): self.version = version self.sessions = sessions self._static_info: Dict[str, DataModelStaticInfo] = { "workflow": DataModelStaticInfo( - pyfluent_path, "workflow", ( "meshing", @@ -125,35 +123,30 @@ def __init__(self, version, pyfluent_path, sessions: dict): ), self.version, ), - "meshing": DataModelStaticInfo( - pyfluent_path, "meshing", ("meshing",), self.version - ), + "meshing": DataModelStaticInfo("meshing", ("meshing",), self.version), "PartManagement": DataModelStaticInfo( - pyfluent_path, "PartManagement", ("meshing",), self.version + "PartManagement", ("meshing",), self.version ), "PMFileManagement": DataModelStaticInfo( - pyfluent_path, "PMFileManagement", ("meshing",), self.version + "PMFileManagement", ("meshing",), self.version ), "flicing": DataModelStaticInfo( - pyfluent_path, "flserver", ("flicing",), self.version, "flicing" + "flserver", ("flicing",), self.version, "flicing" ), "preferences": DataModelStaticInfo( - pyfluent_path, "preferences", ("meshing", "solver", "flicing,"), self.version, ), "solverworkflow": ( - DataModelStaticInfo( - pyfluent_path, "solverworkflow", ("solver",), self.version - ) + DataModelStaticInfo("solverworkflow", ("solver",), self.version) if FluentVersion(self.version) >= FluentVersion.v231 else None ), } if FluentVersion(self.version) >= FluentVersion.v242: self._static_info["meshing_utilities"] = DataModelStaticInfo( - pyfluent_path, "MeshingUtilities", ("meshing",), self.version + "MeshingUtilities", ("meshing",), self.version ) if not self._static_info["solverworkflow"]: del self._static_info["solverworkflow"] @@ -330,6 +323,7 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): return api_tree def write_static_info(self) -> None: + """Write API classes to files.""" api_tree = {"": {}, "": {}} for name, info in self._static_info.items(): if info.static_info == None: @@ -368,11 +362,12 @@ def _delete_generated_files(self): shutil.rmtree(Path(_SOLVER_DM_DOC_DIR)) -def generate(version, pyfluent_path, sessions: dict): - return DataModelGenerator(version, pyfluent_path, sessions).write_static_info() +def generate(version, sessions: dict): + """Generate datamodel API classes.""" + return DataModelGenerator(version, sessions).write_static_info() if __name__ == "__main__": sessions = {FluentMode.SOLVER: launch_fluent()} version = get_version_for_file_name(session=sessions[FluentMode.SOLVER]) - generate(version, None, sessions) + generate(version, sessions) diff --git a/codegen/print_fluent_version.py b/src/ansys/fluent/core/codegen/print_fluent_version.py similarity index 65% rename from codegen/print_fluent_version.py rename to src/ansys/fluent/core/codegen/print_fluent_version.py index 56edb396256..94409ed4c62 100644 --- a/codegen/print_fluent_version.py +++ b/src/ansys/fluent/core/codegen/print_fluent_version.py @@ -1,13 +1,11 @@ -import os -from pathlib import Path +"""Module to write Fluent version information.""" -from ansys.fluent.core import FluentMode, launch_fluent +from ansys.fluent.core import GENERATED_API_DIR, FluentMode, launch_fluent from ansys.fluent.core.utils.fluent_version import get_version_for_file_name -_THIS_DIR = os.path.dirname(__file__) - -def print_fluent_version(pyfluent_path, sessions: dict): +def print_fluent_version(sessions: dict): + """Write Fluent version information to file.""" if FluentMode.SOLVER not in sessions: sessions[FluentMode.SOLVER] = launch_fluent() session = sessions[FluentMode.SOLVER] @@ -15,11 +13,7 @@ def print_fluent_version(pyfluent_path, sessions: dict): version_for_filename = get_version_for_file_name(_fluent_version) eval = session.scheme_eval.scheme_eval version_file = ( - (Path(pyfluent_path) if pyfluent_path else (Path(_THIS_DIR) / ".." / "src")) - / "ansys" - / "fluent" - / "core" - / f"fluent_version_{version_for_filename}.py" + GENERATED_API_DIR / f"fluent_version_{version_for_filename}.py" ).resolve() with open(version_file, "w", encoding="utf8") as f: f.write(f'FLUENT_VERSION = "{_fluent_version}"\n') @@ -29,8 +23,9 @@ def print_fluent_version(pyfluent_path, sessions: dict): f.write(f'FLUENT_BRANCH = "{eval("(inquire-src-vcs-branch)")}"\n') -def generate(pyfluent_path, sessions: dict): - print_fluent_version(pyfluent_path, sessions) +def generate(sessions: dict): + """Write Fluent version information.""" + print_fluent_version(sessions) if __name__ == "__main__": diff --git a/codegen/settingsgen.py b/src/ansys/fluent/core/codegen/settingsgen.py similarity index 97% rename from codegen/settingsgen.py rename to src/ansys/fluent/core/codegen/settingsgen.py index 72a042d70d9..4d8ae237514 100644 --- a/codegen/settingsgen.py +++ b/src/ansys/fluent/core/codegen/settingsgen.py @@ -32,7 +32,7 @@ import pprint import shutil -from ansys.fluent.core import FluentMode, launch_fluent +from ansys.fluent.core import GENERATED_API_DIR, FluentMode, launch_fluent from ansys.fluent.core.solver import flobject from ansys.fluent.core.utils.fix_doc import fix_settings_doc from ansys.fluent.core.utils.fluent_version import get_version_for_file_name @@ -470,16 +470,9 @@ def _populate_init(parent_dir, sinfo): f.write(f"from .{root_class_path} import root") -def generate(version, pyfluent_path, sessions: dict): - dirname = os.path.dirname(__file__) - parent_dir = ( - (Path(pyfluent_path) if pyfluent_path else (Path(dirname) / ".." / "src")) - / "ansys" - / "fluent" - / "core" - / "solver" - / f"settings_{version}" - ).resolve() +def generate(version, sessions: dict): + """Generate settings API classes.""" + parent_dir = (GENERATED_API_DIR / "solver" / f"settings_{version}").resolve() # Clear previously generated data if os.path.exists(parent_dir): @@ -504,4 +497,4 @@ def generate(version, pyfluent_path, sessions: dict): if __name__ == "__main__": sessions = {FluentMode.SOLVER: launch_fluent()} version = get_version_for_file_name(session=sessions[FluentMode.SOLVER]) - generate(version, None, sessions) + generate(version, sessions) diff --git a/codegen/tuigen.py b/src/ansys/fluent/core/codegen/tuigen.py similarity index 84% rename from codegen/tuigen.py rename to src/ansys/fluent/core/codegen/tuigen.py index d92d5891bb0..8e0797a634f 100644 --- a/codegen/tuigen.py +++ b/src/ansys/fluent/core/codegen/tuigen.py @@ -24,9 +24,8 @@ import uuid import xml.etree.ElementTree as ET -from data.fluent_gui_help_patch import XML_HELP_PATCH - -from ansys.fluent.core import FluentMode, launch_fluent +from ansys.fluent.core import GENERATED_API_DIR, FluentMode, launch_fluent +from ansys.fluent.core.codegen.data.fluent_gui_help_patch import XML_HELP_PATCH from ansys.fluent.core.services.datamodel_tui import ( PyMenu, convert_path_to_grpc_path, @@ -40,28 +39,23 @@ logger = logging.getLogger("pyfluent.tui") -_THIS_DIRNAME = os.path.dirname(__file__) +_ROOT_DIR = Path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." -def _get_tui_filepath(mode: str, version: str, pyfluent_path: str): - return ( - (Path(pyfluent_path) if pyfluent_path else (Path(_THIS_DIRNAME) / ".." / "src")) - / "ansys" - / "fluent" - / "core" - / mode - / f"tui_{version}.py" - ).resolve() +def _get_tui_filepath(mode: str, version: str): + return (GENERATED_API_DIR / mode / f"tui_{version}.py").resolve() _INDENT_STEP = 4 +# TODO: Move doc-specific variables to docgen + + def _get_tui_docdir(mode: str): return os.path.normpath( os.path.join( - _THIS_DIRNAME, - "..", + _ROOT_DIR, "doc", "source", "api", @@ -71,9 +65,7 @@ def _get_tui_docdir(mode: str): ) -_XML_HELP_FILE = os.path.normpath( - os.path.join(_THIS_DIRNAME, "data", "fluent_gui_help.xml") -) +_XML_HELP_FILE = (Path(__file__) / ".." / "data" / "fluent_gui_help.xml").resolve() _XML_HELPSTRINGS = {} @@ -89,7 +81,8 @@ def _copy_tui_help_xml_file(version: str): ) xml_source = f"/ansys_inc/v{version}/commonfiles/help/en-us/fluent_gui_help/fluent_gui_help.xml" subprocess.run( - f"docker cp {container_name}:{xml_source} {_XML_HELP_FILE}", shell=is_linux + f"docker cp {container_name}:{xml_source} {str(_XML_HELP_FILE)}", + shell=is_linux, ) subprocess.run(f"docker container rm {container_name}", shell=is_linux) @@ -161,16 +154,26 @@ def __init__(self, path: str, doc: str, is_command: bool = False): self.children = {} def get_command_path(self, command: str) -> str: + """Get the full path to a command.""" return convert_path_to_grpc_path(self.path + [command]) +class _RenameModuleUnpickler(pickle.Unpickler): + def find_class(self, module, name): + renamed_module = module + if module == "tuigen": + renamed_module = "ansys.fluent.core.codegen.tuigen" + + return super(_RenameModuleUnpickler, self).find_class(renamed_module, name) + + class TUIGenerator: - """Class to generate explicit TUI menu classes.""" + """Generates explicit TUI menu classes.""" - def __init__(self, mode: str, version: str, pyfluent_path: str, sessions: dict): + def __init__(self, mode: str, version: str, sessions: dict): self._mode = mode self._version = version - self._tui_file = _get_tui_filepath(mode, version, pyfluent_path) + self._tui_file = _get_tui_filepath(mode, version) if Path(self._tui_file).exists(): Path(self._tui_file).unlink() self._tui_doc_dir = _get_tui_docdir(mode) @@ -252,19 +255,21 @@ def _write_menu_to_tui_file(self, menu: _TUIMenu, indent: int = 0): return api_tree def generate(self) -> None: + """Generate TUI API classes.""" api_tree = {} Path(self._tui_file).parent.mkdir(exist_ok=True) with open(self._tui_file, "w", encoding="utf8") as self.__writer: if FluentVersion(self._version) == FluentVersion.v222: with open( - os.path.join( - _THIS_DIRNAME, - "data", - f"static_info_{self._version}_{self._mode}.pickle", - ), + ( + Path(__file__) + / ".." + / "data" + / f"static_info_{self._version}_{self._mode}.pickle" + ).resolve(), "rb", ) as f: - self._main_menu = pickle.load(f) + self._main_menu = _RenameModuleUnpickler(f).load() else: info = PyMenu( self._service, self._version, self._mode, self._main_menu.path @@ -287,17 +292,16 @@ def generate(self) -> None: return api_tree -def generate(version, pyfluent_path, sessions: dict): +def generate(version, sessions: dict): + """Generate TUI API classes.""" api_tree = {} if FluentVersion(version) > FluentVersion.v222: _copy_tui_help_xml_file(version) _populate_xml_helpstrings() api_tree[""] = TUIGenerator( - "meshing", version, pyfluent_path, sessions - ).generate() - api_tree[""] = TUIGenerator( - "solver", version, pyfluent_path, sessions + "meshing", version, sessions ).generate() + api_tree[""] = TUIGenerator("solver", version, sessions).generate() if os.getenv("PYFLUENT_HIDE_LOG_SECRETS") != "1": logger.info( "XML help is available but not picked for the following %i paths: ", @@ -311,4 +315,4 @@ def generate(version, pyfluent_path, sessions: dict): if __name__ == "__main__": sessions = {FluentMode.SOLVER: launch_fluent()} version = get_version_for_file_name(session=sessions[FluentMode.SOLVER]) - generate(version, None, sessions) + generate(version, sessions) diff --git a/codegen/write_settings_yaml.py b/src/ansys/fluent/core/codegen/write_settings_yaml.py similarity index 100% rename from codegen/write_settings_yaml.py rename to src/ansys/fluent/core/codegen/write_settings_yaml.py diff --git a/src/ansys/fluent/core/generated/__init__.py b/src/ansys/fluent/core/generated/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index dd0324d4e83..a22500556fb 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -48,7 +48,7 @@ def _parse_server_info_file(file_name: str): def _get_datamodel_attributes(session, attribute: str): try: preferences_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{session._version}." + attribute + f"ansys.fluent.core.generated.datamodel_{session._version}." + attribute ) return preferences_module.Root(session._se_service, attribute, []) except ImportError: diff --git a/src/ansys/fluent/core/session_base_meshing.py b/src/ansys/fluent/core/session_base_meshing.py index 3a03afa3622..eeede8b5a67 100644 --- a/src/ansys/fluent/core/session_base_meshing.py +++ b/src/ansys/fluent/core/session_base_meshing.py @@ -79,7 +79,7 @@ def tui(self): if self._tui is None: try: tui_module = importlib.import_module( - f"ansys.fluent.core.meshing.tui_{self._version}" + f"ansys.fluent.core.generated.meshing.tui_{self._version}" ) self._tui = tui_module.main_menu( self._tui_service, self._version, "meshing", [] @@ -94,7 +94,7 @@ def _meshing_root(self): """Datamodel root of meshing.""" try: meshing_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.meshing" + f"ansys.fluent.core.generated.datamodel_{self._version}.meshing" ) meshing_root = meshing_module.Root(self._se_service, "meshing", []) except ImportError: @@ -115,7 +115,7 @@ def _meshing_utilities_root(self): try: if self.get_fluent_version() >= FluentVersion.v242: meshing_utilities_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.MeshingUtilities" + f"ansys.fluent.core.generated.datamodel_{self._version}.MeshingUtilities" ) meshing_utilities_root = meshing_utilities_module.Root( self._se_service, "MeshingUtilities", [] @@ -140,7 +140,7 @@ def _workflow_se(self): """Datamodel root of workflow.""" try: workflow_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.workflow" + f"ansys.fluent.core.generated.datamodel_{self._version}.workflow" ) workflow_se = workflow_module.Root(self._se_service, "workflow", []) except ImportError: @@ -233,7 +233,7 @@ def PartManagement(self): if self._part_management is None: try: pm_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.PartManagement" + f"ansys.fluent.core.generated.datamodel_{self._version}.PartManagement" ) self._part_management = pm_module.Root( self._se_service, "PartManagement", [] @@ -251,7 +251,7 @@ def PMFileManagement(self): if self._pm_file_management is None: try: pmfm_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.PMFileManagement" + f"ansys.fluent.core.generated.datamodel_{self._version}.PMFileManagement" ) self._pm_file_management = pmfm_module.Root( self._se_service, "PMFileManagement", [] diff --git a/src/ansys/fluent/core/session_meshing.pyi b/src/ansys/fluent/core/session_meshing.pyi index 708567da263..5d5f8e28cd1 100644 --- a/src/ansys/fluent/core/session_meshing.pyi +++ b/src/ansys/fluent/core/session_meshing.pyi @@ -1,11 +1,15 @@ -from ansys.fluent.core.datamodel_241.PMFileManagement import ( +from ansys.fluent.core.generated.datamodel_241.PMFileManagement import ( Root as pmfilemanagement_root, ) -from ansys.fluent.core.datamodel_241.PartManagement import Root as partmanagement_root -from ansys.fluent.core.datamodel_241.meshing import Root as meshing_root -from ansys.fluent.core.datamodel_241.preferences import Root as preferences_root -from ansys.fluent.core.datamodel_241.workflow import Root as workflow_root -from ansys.fluent.core.meshing.tui_241 import main_menu +from ansys.fluent.core.generated.datamodel_241.PartManagement import ( + Root as partmanagement_root, +) +from ansys.fluent.core.generated.datamodel_241.meshing import Root as meshing_root +from ansys.fluent.core.generated.datamodel_241.preferences import ( + Root as preferences_root, +) +from ansys.fluent.core.generated.datamodel_241.workflow import Root as workflow_root +from ansys.fluent.core.generated.meshing.tui_241 import main_menu class Meshing: @property diff --git a/src/ansys/fluent/core/session_pure_meshing.pyi b/src/ansys/fluent/core/session_pure_meshing.pyi index 794ef46b86c..c9296cfe717 100644 --- a/src/ansys/fluent/core/session_pure_meshing.pyi +++ b/src/ansys/fluent/core/session_pure_meshing.pyi @@ -1,11 +1,15 @@ -from ansys.fluent.core.datamodel_241.PMFileManagement import ( +from ansys.fluent.core.generated.datamodel_241.PMFileManagement import ( Root as pmfilemanagement_root, ) -from ansys.fluent.core.datamodel_241.PartManagement import Root as partmanagement_root -from ansys.fluent.core.datamodel_241.meshing import Root as meshing_root -from ansys.fluent.core.datamodel_241.preferences import Root as preferences_root -from ansys.fluent.core.datamodel_241.workflow import Root as workflow_root -from ansys.fluent.core.meshing.tui_241 import main_menu +from ansys.fluent.core.generated.datamodel_241.PartManagement import ( + Root as partmanagement_root, +) +from ansys.fluent.core.generated.datamodel_241.meshing import Root as meshing_root +from ansys.fluent.core.generated.datamodel_241.preferences import ( + Root as preferences_root, +) +from ansys.fluent.core.generated.datamodel_241.workflow import Root as workflow_root +from ansys.fluent.core.generated.meshing.tui_241 import main_menu class PureMeshing: @property diff --git a/src/ansys/fluent/core/session_solver.py b/src/ansys/fluent/core/session_solver.py index 7d05bacadc7..bc6b1e9dc1e 100644 --- a/src/ansys/fluent/core/session_solver.py +++ b/src/ansys/fluent/core/session_solver.py @@ -183,7 +183,7 @@ def tui(self): if self._tui is None: try: tui_module = importlib.import_module( - f"ansys.fluent.core.solver.tui_{self._version}" + f"ansys.fluent.core.generated.solver.tui_{self._version}" ) self._tui = tui_module.main_menu( self._tui_service, self._version, "solver", [] @@ -198,7 +198,7 @@ def _workflow_se(self): """Datamodel root for workflow.""" try: workflow_module = importlib.import_module( - f"ansys.fluent.core.datamodel_{self._version}.workflow" + f"ansys.fluent.core.generated.datamodel_{self._version}.workflow" ) workflow_se = workflow_module.Root(self._se_service, "workflow", []) except ImportError: diff --git a/src/ansys/fluent/core/session_solver.pyi b/src/ansys/fluent/core/session_solver.pyi index 72ee7448d46..04a2e3c48f7 100644 --- a/src/ansys/fluent/core/session_solver.pyi +++ b/src/ansys/fluent/core/session_solver.pyi @@ -1,18 +1,22 @@ -from ansys.fluent.core.datamodel_241.preferences import Root as preferences_root -from ansys.fluent.core.datamodel_241.workflow import Root as workflow_root -from ansys.fluent.core.solver.settings_241.current_parametric_study import ( +from ansys.fluent.core.generated.datamodel_241.preferences import ( + Root as preferences_root, +) +from ansys.fluent.core.generated.datamodel_241.workflow import Root as workflow_root +from ansys.fluent.core.generated.solver.settings_241.current_parametric_study import ( current_parametric_study, ) -from ansys.fluent.core.solver.settings_241.file import file -from ansys.fluent.core.solver.settings_241.mesh import mesh -from ansys.fluent.core.solver.settings_241.parallel import parallel -from ansys.fluent.core.solver.settings_241.parameters import parameters -from ansys.fluent.core.solver.settings_241.parametric_studies import parametric_studies -from ansys.fluent.core.solver.settings_241.results import results -from ansys.fluent.core.solver.settings_241.server import server -from ansys.fluent.core.solver.settings_241.setup import setup -from ansys.fluent.core.solver.settings_241.solution import solution -from ansys.fluent.core.solver.tui_241 import main_menu +from ansys.fluent.core.generated.solver.settings_241.file import file +from ansys.fluent.core.generated.solver.settings_241.mesh import mesh +from ansys.fluent.core.generated.solver.settings_241.parallel import parallel +from ansys.fluent.core.generated.solver.settings_241.parameters import parameters +from ansys.fluent.core.generated.solver.settings_241.parametric_studies import ( + parametric_studies, +) +from ansys.fluent.core.generated.solver.settings_241.results import results +from ansys.fluent.core.generated.solver.settings_241.server import server +from ansys.fluent.core.generated.solver.settings_241.setup import setup +from ansys.fluent.core.generated.solver.settings_241.solution import solution +from ansys.fluent.core.generated.solver.tui_241 import main_menu from ansys.fluent.core.systemcoupling import SystemCoupling class Solver: diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 27ca860c2ce..801f807fd0a 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -1970,7 +1970,7 @@ def get_root( obj_info = flproxy.get_static_info() try: settings = importlib.import_module( - f"ansys.fluent.core.solver.settings_{version}" + f"ansys.fluent.core.generated.solver.settings_{version}" ) if settings.SHASH != _gethash(obj_info): diff --git a/src/ansys/fluent/core/utils/search.py b/src/ansys/fluent/core/utils/search.py index ea50994df6d..32dea96fbc2 100644 --- a/src/ansys/fluent/core/utils/search.py +++ b/src/ansys/fluent/core/utils/search.py @@ -22,17 +22,11 @@ ) -def get_api_tree_file_name(version: str, pyfluent_path: str) -> Path: +def get_api_tree_file_name(version: str) -> Path: """Get API tree file name.""" - return ( - ( - (Path(pyfluent_path) / "ansys" / "fluent" / "core") - if pyfluent_path - else (Path(__file__) / ".." / "..") - ) - / "data" - / f"api_tree_{version}.pickle" - ).resolve() + from ansys.fluent.core import GENERATED_API_DIR + + return (GENERATED_API_DIR / f"api_tree_{version}.pickle").resolve() def _match(source: str, word: str, match_whole_word: bool, match_case: bool): @@ -74,7 +68,7 @@ def _get_version_path_prefix_from_obj(obj: Any): path = [ ( "" - if module.startswith("ansys.fluent.core.meshing") + if module.startswith("ansys.fluent.core.generated.meshing") else "" ), "tui", @@ -191,9 +185,9 @@ def search( if not version: for fluent_version in FluentVersion: version = get_version_for_file_name(fluent_version.value) - if get_api_tree_file_name(version, None).exists(): + if get_api_tree_file_name(version).exists(): break - api_tree_file = get_api_tree_file_name(version, None) + api_tree_file = get_api_tree_file_name(version) with open(api_tree_file, "rb") as f: api_tree = pickle.load(f) diff --git a/tests/test_codegen.py b/tests/test_codegen.py index 92482bd524f..dabd2b1ed0e 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -9,12 +9,20 @@ @pytest.mark.codegen_required def test_allapigen_files(new_solver_session): version = get_version_for_file_name(session=new_solver_session) - importlib.import_module(f"ansys.fluent.core.fluent_version_{version}") - importlib.import_module(f"ansys.fluent.core.meshing.tui_{version}") - importlib.import_module(f"ansys.fluent.core.solver.tui_{version}") - importlib.import_module(f"ansys.fluent.core.datamodel_{version}.meshing") - importlib.import_module(f"ansys.fluent.core.datamodel_{version}.workflow") - importlib.import_module(f"ansys.fluent.core.datamodel_{version}.preferences") - importlib.import_module(f"ansys.fluent.core.datamodel_{version}.PartManagement") - importlib.import_module(f"ansys.fluent.core.datamodel_{version}.PMFileManagement") - importlib.import_module(f"ansys.fluent.core.solver.settings_{version}.root") + importlib.import_module(f"ansys.fluent.core.generated.fluent_version_{version}") + importlib.import_module(f"ansys.fluent.core.generated.meshing.tui_{version}") + importlib.import_module(f"ansys.fluent.core.generated.solver.tui_{version}") + importlib.import_module(f"ansys.fluent.core.generated.datamodel_{version}.meshing") + importlib.import_module(f"ansys.fluent.core.generated.datamodel_{version}.workflow") + importlib.import_module( + f"ansys.fluent.core.generated.datamodel_{version}.preferences" + ) + importlib.import_module( + f"ansys.fluent.core.generated.datamodel_{version}.PartManagement" + ) + importlib.import_module( + f"ansys.fluent.core.generated.datamodel_{version}.PMFileManagement" + ) + importlib.import_module( + f"ansys.fluent.core.generated.solver.settings_{version}.root" + ) diff --git a/tests/test_flobject.py b/tests/test_flobject.py index 2a3158f8f06..897e922e495 100644 --- a/tests/test_flobject.py +++ b/tests/test_flobject.py @@ -1,6 +1,5 @@ """Unit tests for flobject module.""" -# import codegen.settingsgen from collections.abc import MutableMapping import io import weakref @@ -524,7 +523,7 @@ def _disabled_test_settings_gen(): info = Proxy().get_static_info() cls, _ = flobject.get_cls("", info) f = io.StringIO() - codegen.settingsgen.write_settings_classes(f, cls, info) + ansys.fluent.core.codegen.settingsgen.write_settings_classes(f, cls, info) assert ( f.getvalue() == '''### diff --git a/tests/test_type_stub.py b/tests/test_type_stub.py index cec3254d5db..6e1d358906f 100644 --- a/tests/test_type_stub.py +++ b/tests/test_type_stub.py @@ -1,9 +1,8 @@ import ast -from pathlib import Path import pytest -import ansys.fluent.core as pyfluent +from ansys.fluent.core import GENERATED_API_DIR from ansys.fluent.core._version import fluent_release_version from ansys.fluent.core.utils.fluent_version import FluentVersion @@ -14,9 +13,7 @@ def test_settings_stub(): # intellisense engine while typing in editors like vscode. This test validates the # information contained in a type-stub file. version = FluentVersion(fluent_release_version).number - stub_file = ( - Path(pyfluent.__file__).parent / "solver" / f"settings_{version}" / "export.pyi" - ) + stub_file = GENERATED_API_DIR / "solver" / f"settings_{version}" / "export.pyi" assert stub_file.exists() with open(stub_file) as f: module_def = ast.parse(f.read())