Repository navigation
refactor: Group session classes in separate package - #5343
Conversation
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
Pull request overview
This PR groups solver, meshing, and file sessions under ansys.fluent.core.session, refactors meshing inheritance, and updates related imports and documentation.
Changes:
- Introduces grouped session modules and private base classes.
- Updates imports, tests, launchers, settings, and API documentation support.
- Defers optional
h5pyimports and updates CI scheduling.
Reviewed changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Reviewed change / finding |
|---|---|
tests/test_settings_api.py |
Updates solver import. |
tests/test_session.py |
Updates private base-session import. Moderate (2 votes): patch the private parser module/function actually used by the launcher; the package no longer exports _parse_server_info_file. |
tests/test_public_api.py |
Adjusts public API expectations. |
tests/test_physical_quantities.py |
Updates file-session import. |
tests/test_meshingmode/test_meshing_launch.py |
Updates meshing help assertion. |
tests/test_launcher_remote.py |
Updates session imports. |
tests/test_file_session.py |
Updates file-session imports. |
src/ansys/fluent/core/utils/setup_for_fluent.py |
Uses the grouped solver module. |
src/ansys/fluent/core/session/solver.py |
Updates solver structure and documentation. |
src/ansys/fluent/core/session/solver_lite.py |
Updates lightweight solver structure. |
src/ansys/fluent/core/session/solver_icing.py |
Updates Icing solver structure. |
src/ansys/fluent/core/session/solver_aero.py |
Updates Aero solver structure. |
src/ansys/fluent/core/session/pure_meshing.py |
Adds the reorganized pure-meshing session. Moderate (2 votes): preserve the previous positional legacy argument contract for load_workflow and create_workflow. |
src/ansys/fluent/core/session/meshing.py |
Updates meshing inheritance and imports. |
src/ansys/fluent/core/session/file.py |
Relocates the file-session implementation. |
src/ansys/fluent/core/session/_utilities.py |
Updates session utility references. |
src/ansys/fluent/core/session/_shared.py |
Adds shared session helpers. |
src/ansys/fluent/core/session/_session.py |
Adds the private base-session module. |
src/ansys/fluent/core/session/_base_meshing.py |
Makes base meshing inherit from base session. |
src/ansys/fluent/core/session/__init__.py |
Defines the session package API and hierarchy. Nit (4 votes): update documentation generators and references to deleted module paths. Moderate (3 votes): preserve old import paths with shims or explicitly treat the change as breaking. |
src/ansys/fluent/core/session_pure_meshing.py |
Removes the superseded module. |
src/ansys/fluent/core/services/settings.py |
Centralizes interactive-mode behavior. |
src/ansys/fluent/core/launcher/standalone_launcher.py |
Updates type imports. |
src/ansys/fluent/core/launcher/slurm_launcher.py |
Updates session imports. |
src/ansys/fluent/core/launcher/server_info.py |
Uses the private parser module. |
src/ansys/fluent/core/launcher/pim_launcher.py |
Updates session imports. |
src/ansys/fluent/core/launcher/launcher.py |
Updates session imports. |
src/ansys/fluent/core/launcher/launch_options.py |
Updates session type mappings. |
src/ansys/fluent/core/launcher/fluent_container.py |
Uses the private parser module. |
src/ansys/fluent/core/launcher/container_launcher.py |
Updates session imports. |
src/ansys/fluent/core/filereader/data_file.py |
Lazily imports h5py. Moderate (2 votes): prevent the broad handler from masking ModuleNotFoundError with a generic runtime error. |
src/ansys/fluent/core/filereader/case_file.py |
Lazily imports h5py. Moderate (2 votes): prevent the broad handler from masking ModuleNotFoundError with a generic runtime error. |
src/ansys/fluent/core/__init__.py |
Updates package exports. |
doc/changelog.d/5343.miscellaneous.md |
Records the session grouping change. |
.github/workflows/test-run-dev-version-nightly.yml |
Changes the nightly schedule. |
Suppressed comments (3)
src/ansys/fluent/core/launcher/launcher.py:74
- The runtime imports now use the grouped package, but this module's
launch_fluentreturn docstring still links to deletedansys.fluent.core.session_*modules (lines 379-382). Sphinx will emit broken cross-references for the public launcher API; update those targets toansys.fluent.core.session.meshing,.pure_meshing,.solver, and.solver_icing.
from ansys.fluent.core.session.meshing import Meshing
from ansys.fluent.core.session.pure_meshing import PureMeshing
from ansys.fluent.core.session.solver import Solver
from ansys.fluent.core.session.solver_aero import SolverAero
from ansys.fluent.core.session.solver_icing import SolverIcing
src/ansys/fluent/core/launcher/slurm_launcher.py:103
- The runtime imports now use the grouped package, but this module's public future/result docstrings still link to deleted
ansys.fluent.core.session_*modules (lines 348-351 and 551-554). Sphinx will emit broken cross-references; update those targets to the correspondingansys.fluent.core.session.*modules.
from ansys.fluent.core.session.meshing import Meshing
from ansys.fluent.core.session.pure_meshing import PureMeshing
from ansys.fluent.core.session.solver import Solver
from ansys.fluent.core.session.solver_aero import SolverAero
from ansys.fluent.core.session.solver_icing import SolverIcing
src/ansys/fluent/core/session/init.py:30
FileSessionis one of the concrete classes re-exported below, but it is instantiated directly for offline file reading and is not created bylaunch_fluent. This new package docstring should limit the launcher statement to live sessions or explicitly mentionFileSession.
The two non-user-facing base classes (``BaseSession``, ``BaseMeshing``) live in
private modules and must not be instantiated directly. All concrete session
objects are created via :func:`ansys.fluent.core.launch_fluent`.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 43 changed files in this pull request and generated 4 comments.
Suppressed comments (8)
src/ansys/fluent/core/init.py:46
- Removing the old session modules means
pyfluent.session_solveris no longer an attribute of the package. The exampleexamples/00-fluent/lunar_lander_thermal.py:238evaluatespyfluent.session_solver.Solverat function definition time (it has no postponed-annotation import), so importing that example now raisesAttributeError. Update that annotation topyfluent.session.solver.Solveror retain a compatibility module attribute.
from ansys.fluent.core.session import *
from ansys.fluent.core.session.session import BaseSession as Fluent
from ansys.fluent.core.session.utilities import *
src/ansys/fluent/core/session/init.py:30
- The package docstring states that all concrete session objects are created via
launch_fluent, butFileSessionis re-exported below and is intentionally constructed directly for offline use. This makes the new API overview incorrect; qualify the statement to live Fluent sessions or explicitly mention theFileSessionexception.
The two non-user-facing base classes (``BaseSession``, ``BaseMeshing``) live in
private modules and must not be instantiated directly. All concrete session
objects are created via :func:`ansys.fluent.core.launch_fluent`.
src/ansys/fluent/core/session/init.py:46
- These
*Sessionaliases do not provide backward compatibility for the old public module imports: this refactor deletes modules such asansys.fluent.core.file_sessionandansys.fluent.core.session_solver, but adds no forwarding shims. Existing consumers using those paths therefore getModuleNotFoundError, despite this new docstring's backward-compatibility claim and the stated no-usability impact. Add deprecated forwarding modules or explicitly treat this as a breaking API change.
Each concrete class is re-exported here with a ``Session`` suffix for backward
compatibility and convenience:
src/ansys/fluent/core/session/base_meshing.py:98
- This docstring says both leaf classes add no further public methods, but
Meshingdefinesswitch_to_solver()inmeshing.py:56. The generated hierarchy page will therefore misdescribe the public API; distinguishPureMeshingfromMeshinghere.
src/ansys/fluent/core/session/base_meshing.py:449 meshing_workflow_new.get_current_workflow()calls theload_workflow_handlewith onlyinitialize=Falsewhen it discovers a workflow that was loaded outside this Python object. Makingfile_pathmandatory here turns that path into aTypeError; the previousfile_path=Nonedefault was required for this callback, since the newLoadWorkflowskips the actual load wheninitialize=False. Keepfile_pathoptional (or change the callback to provide a path) sosession.current_workflowcontinues to work for externally loaded workflows.
src/ansys/fluent/core/session/session.py:107- The direct-instantiation guard makes the existing
tests/test_launcher_remote.py:139construction raiseTypeErrorbefore the test reachesFluentConnection.wait_process_finished(), which is the operation expected to raiseUnsupportedRemoteFluentInstance. Update that caller to use a concrete session or the private_create_instancefactory; otherwise this existing test fails after the guard is added.
src/ansys/fluent/core/session/session.py:107 - Because
core/__init__.pycontinues to exportBaseSessionas the publicansys.fluent.core.Fluentsymbol, this identity check also makespyfluent.Fluent(...)raise the newTypeError. The public alias was constructible before this change and remains in the public API tests. Either remove/deprecate that export and update the API contract, or provide a constructible compatibility class instead of guarding the aliased class.
tests/test_launcher_remote.py:51 - This import now refers to a class that deliberately rejects direct construction, but the test still calls
BaseSession(...)later at line 139. If this test is enabled, the new guard raisesTypeErrorinstead of the expectedUnsupportedRemoteFluentInstance; construct a concrete session or use the private test factory there.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 43 changed files in this pull request and generated 4 comments.
Suppressed comments (8)
Previously missed (2) — in code that hasn't changed since the last review.
src/ansys/fluent/core/session/base_meshing.py:97
- This class docstring says both leaf classes add no further public methods, but
Meshingexplicitly adds the publicswitch_to_solvermethod (and documents it in meshing.py). That contradiction will misdescribe the key difference betweenMeshingandPureMeshingin the API reference; clarify thatMeshingis the exception.
doc/api_rstgen.py:76 - The generated API now enters through
session/session_contents, butdoc/deprecated_pyfluent_apis.pystill links toansys.fluent.core.session.BaseSession.BaseSessionis no longer exported by this package (it lives insession.session, and that private module is not generated), so the deprecated-API roles will remain unresolved in the documentation build. Update these targets to a documented concrete session API or add the appropriate private-module documentation/alias.
session/session_contents
.github/workflows/test-run-dev-version-nightly.yml:5
- This changes the nightly workflow from 03:00 to 01:00 UTC, which is unrelated to grouping session modules and changes CI resource scheduling. Unless this timing change is intentional, revert it or document its operational reason in the PR.
- cron: "0 1 * * *"
src/ansys/fluent/core/init.py:77
- The runtime compatibility alias does not repair the generated API references:
doc/deprecated_pyfluent_apis.pystill targetsansys.fluent.core.file_session.*, whiledoc/api_rstgen.pynow removes thefile_sessionAPI page. The deprecated API table will therefore contain unresolved roles even though the old import may work; update those references or retain a compatibility API page.
_sys.modules["ansys.fluent.core.file_session"] = ansys_fluent_core_session_file
src/ansys/fluent/core/session/init.py:70
- Because this package no longer re-exports
BaseSession, the existing entries indoc/deprecated_pyfluent_apis.pythat targetansys.fluent.core.session.BaseSession.*now refer to a nonexistent object. Generating the deprecated API page will leave those Sphinx roles unresolved; update them toansys.fluent.core.session.session.BaseSessionor retain a compatibility package alias.
__all__ = [
"MeshingSession",
"PureMeshingSession",
"SolverSession",
"SolverAeroSession",
src/ansys/fluent/core/session/init.py:30
- This new package docstring links to
ansys.fluent.core.launch_fluent, but the API generator documents the function fromansys.fluent.core.launcher.launcherand does not generate a top-levelansys.fluent.coreautomodule page. Use the canonical launcher module target so the session index does not introduce an unresolved cross-reference.
objects are created via :func:`ansys.fluent.core.launch_fluent`.
src/ansys/fluent/core/session/base_meshing.py:449
BaseMeshing._get_current_workflow()passesself.load_workflowtomeshing_workflow_new.get_current_workflow(), which invokes that callback asload_workflow_handle(initialize=False)when Fluent reports a loaded workflow. Makingfile_pathrequired here therefore makesmeshing.current_workflowraiseTypeErrorfor loaded workflows. Preserve the previousNonedefault; the non-initializing path does not need a file path.
src/ansys/fluent/core/session/session.py:107BaseSessionis still exported as the publicansys.fluent.core.Fluentalias, so this new guard also makespyfluent.Fluent(...)unusable. The public API test explicitly preservesFluent, and it previously referred to this constructible class; either remove/deprecate that alias as a deliberate breaking change or preserve a compatible construction path before enforcing the guard.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
N.b. The branch name could have been |
Thanks @seanpearsonuk,Noted. |
Co-authored-by: Sean Pearson <93727996+seanpearsonuk@users.noreply.github.com>
Context
Some parts of the PyFluent code can be better grouped together, for example the sessions, for better rendering of the api docs.
Change Summary
All solver, meshing and File Session related files are grouped together in the sessions dir.
Proper module docstring and exposure to api docs.
the unexposed modules have been renamed to be private.
The complex inheritance structure of the
PureMeshinggetting derived fromBaseSessiondirectly has been resolved intoBaseSession->BaseMeshing->PureMeshingandMeshing, similar structure to the solver.All import paths modified.
Rationale
To better render api reference.
Impact
No impact to usability, only the codebase is better structured and improved readability of the modules.