Skip to content

Commit 7968e34

Browse files
committed
Add more PathLike support
1 parent c6fcd80 commit 7968e34

File tree

13 files changed

+86
-57
lines changed

13 files changed

+86
-57
lines changed

src/ansys/fluent/core/examples/downloads.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from pathlib import Path
2828
import re
2929
import shutil
30-
from typing import TypeAlias
3130
import zipfile
3231

3332
import ansys.fluent.core as pyfluent
33+
from ansys.fluent.core.types import PathType
3434
from ansys.fluent.core.utils.networking import check_url_exists, get_url_content
3535

3636
logger = logging.getLogger("pyfluent.networking")
@@ -72,9 +72,6 @@ def _get_file_url(file_name: str, directory: str | None = None) -> str:
7272
return f"https://github.com/ansys/example-data/raw/main/{file_name}"
7373

7474

75-
PathType: TypeAlias = "os.PathLike[str | bytes] | str | bytes"
76-
77-
7875
def _retrieve_file(
7976
url: str,
8077
file_name: str,

src/ansys/fluent/core/filereader/case_file.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import numpy as np
5050

5151
from ansys.fluent.core.solver.error_message import allowed_name_error_message
52+
from ansys.fluent.core.types import PathType
5253

5354
from . import lispy
5455
from .pre_processor import remove_unsupported_xml_chars
@@ -616,17 +617,17 @@ class CaseFile(RPVarProcessor):
616617

617618
def __init__(
618619
self,
619-
case_file_name: str | None = None,
620-
project_file_name: str | None = None,
620+
case_file_name: "PathType | None" = None,
621+
project_file_name: "PathType | None" = None,
621622
) -> None:
622623
"""Initialize a CaseFile object. Exactly one file path argument must be
623624
specified.
624625
625626
Parameters
626627
----------
627-
case_file_name : str
628+
case_file_name : :class:`os.PathLike` | str | None
628629
The path of a case file.
629-
project_file_name : str
630+
project_file_name : :class:`os.PathLike` | str | None
630631
The path of a project file from which the case file is selected.
631632
"""
632633
self._is_case_file = False

src/ansys/fluent/core/launcher/launcher.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from ansys.fluent.core.session_pure_meshing import PureMeshing
5959
from ansys.fluent.core.session_solver import Solver
6060
from ansys.fluent.core.session_solver_icing import SolverIcing
61+
from ansys.fluent.core.types import PathType
6162
from ansys.fluent.core.utils.deprecate import all_deprecators
6263
from ansys.fluent.core.utils.fluent_version import FluentVersion
6364

@@ -162,14 +163,14 @@ def launch_fluent(
162163
graphics_driver: (
163164
FluentWindowsGraphicsDriver | FluentLinuxGraphicsDriver | str | None
164165
) = None,
165-
case_file_name: str | None = None,
166-
case_data_file_name: str | None = None,
166+
case_file_name: "PathType | None" = None,
167+
case_data_file_name: "PathType | None" = None,
167168
lightweight_mode: bool | None = None,
168169
mode: FluentMode | str | None = None,
169170
py: bool | None = None,
170171
gpu: bool | list[int] | None = None,
171-
cwd: str | None = None,
172-
fluent_path: str | None = None,
172+
cwd: "PathType | None" = None,
173+
fluent_path: "PathType | None" = None,
173174
topy: str | list | None = None,
174175
start_watchdog: bool | None = None,
175176
scheduler_options: dict | None = None,
@@ -254,9 +255,9 @@ def launch_fluent(
254255
``"null"``, ``"x11"``, ``"opengl2"``, ``"opengl"`` or ``"auto"``. The default is
255256
``FluentWindowsGraphicsDriver.AUTO`` in Windows and
256257
``FluentLinuxGraphicsDriver.AUTO`` in Linux.
257-
case_file_name : str, optional
258+
case_file_name : :class:`os.PathLike` or str, optional
258259
If provided, the case file at ``case_file_name`` is read into the Fluent session.
259-
case_data_file_name : str, optional
260+
case_data_file_name : :class:`os.PathLike` or str, optional
260261
If provided, the case and data files at ``case_data_file_name`` are read into the Fluent session.
261262
lightweight_mode : bool, optional
262263
Whether to run in lightweight mode. In lightweight mode, the lightweight settings are read into the
@@ -278,9 +279,9 @@ def launch_fluent(
278279
clamped to the value of ``processor_count``. Please refer to
279280
*Starting the Fluent GPU Solver* section in *Fluent's User Guide* for more
280281
information like how to determine the GPU IDs.
281-
cwd : str, Optional
282+
cwd : :class:`os.PathLike` or str, optional
282283
Working directory for the Fluent client.
283-
fluent_path: str, Optional
284+
fluent_path: :class:`os.PathLike` or str, optional
284285
User provided Fluent installation path.
285286
topy : bool or str, optional
286287
A boolean flag to write the equivalent Python journal(s) from the journal(s) passed.

src/ansys/fluent/core/launcher/slurm_launcher.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
from ansys.fluent.core.session_pure_meshing import PureMeshing
9292
from ansys.fluent.core.session_solver import Solver
9393
from ansys.fluent.core.session_solver_icing import SolverIcing
94+
from ansys.fluent.core.types import PathType
9495
from ansys.fluent.core.utils.fluent_version import FluentVersion
9596

9697
logger = logging.getLogger("pyfluent.launcher")
@@ -298,13 +299,13 @@ def __init__(
298299
env: Dict[str, Any] | None = None,
299300
cleanup_on_exit: bool = True,
300301
start_transcript: bool = True,
301-
case_file_name: str | None = None,
302-
case_data_file_name: str | None = None,
302+
case_file_name: "PathType | None" = None,
303+
case_data_file_name: "PathType | None" = None,
303304
lightweight_mode: bool | None = None,
304305
py: bool | None = None,
305306
gpu: bool | None = None,
306-
cwd: str | None = None,
307-
fluent_path: str | None = None,
307+
cwd: "PathType | None" = None,
308+
fluent_path: "PathType | None" = None,
308309
topy: str | list | None = None,
309310
start_watchdog: bool | None = None,
310311
scheduler_options: dict | None = None,
@@ -359,10 +360,10 @@ def __init__(
359360
default is ``True``. You can stop and start the streaming of the
360361
Fluent transcript subsequently via the method calls, ``transcript.start()``
361362
and ``transcript.stop()`` on the session object.
362-
case_file_name : str, optional
363+
case_file_name : :class:`os.PathLike` or str, optional
363364
Name of the case file to read into the
364365
Fluent session. The default is ``None``.
365-
case_data_file_name : str, optional
366+
case_data_file_name : :class:`os.PathLike` or str, optional
366367
Name of the case data file. If names of both a case file and case data file are provided, they are read into the Fluent session.
367368
lightweight_mode : bool, optional
368369
Whether to run in lightweight mode. In lightweight mode, the lightweight settings are read into the
@@ -375,9 +376,9 @@ def __init__(
375376
If True, Fluent will run in Python mode. Default is None.
376377
gpu : bool, optional
377378
If True, Fluent will start with GPU Solver.
378-
cwd : str, Optional
379+
cwd : :class:`os.PathLike` or str, optional
379380
Working directory for the Fluent client.
380-
fluent_path: str, Optional
381+
fluent_path: :class:`os.PathLike` or str, optional
381382
User provided Fluent installation path.
382383
topy : bool or str, optional
383384
A boolean flag to write the equivalent Python journal(s) from the journal(s) passed.

src/ansys/fluent/core/launcher/standalone_launcher.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
_get_server_info_file_names,
7070
)
7171
import ansys.fluent.core.launcher.watchdog as watchdog
72+
from ansys.fluent.core.types import PathType
7273
from ansys.fluent.core.utils.fluent_version import FluentVersion
7374

7475
logger = logging.getLogger("pyfluent.launcher")
@@ -95,13 +96,13 @@ def __init__(
9596
cleanup_on_exit: bool = True,
9697
dry_run: bool = False,
9798
start_transcript: bool = True,
98-
case_file_name: str | None = None,
99-
case_data_file_name: str | None = None,
99+
case_file_name: "PathType | None" = None,
100+
case_data_file_name: "PathType | None" = None,
100101
lightweight_mode: bool | None = None,
101102
py: bool | None = None,
102103
gpu: bool | None = None,
103-
cwd: str | None = None,
104-
fluent_path: str | None = None,
104+
cwd: "PathType | None" = None,
105+
fluent_path: "PathType | None" = None,
105106
topy: str | list | None = None,
106107
start_watchdog: bool | None = None,
107108
file_transfer_service: Any | None = None,
@@ -150,9 +151,9 @@ def __init__(
150151
start_transcript : bool, optional
151152
Indicates whether to start streaming the Fluent transcript in the client. Defaults to True;
152153
streaming can be controlled via `transcript.start()` and `transcript.stop()` methods on the session object.
153-
case_file_name : str, optional
154+
case_file_name : :class:`os.PathLike` or str, optional
154155
Name of the case file to read into the Fluent session. Defaults to None.
155-
case_data_file_name : str, optional
156+
case_data_file_name : :class:`os.PathLike` or str, optional
156157
Name of the case data file. If both case and data files are provided, they are read into the session.
157158
lightweight_mode : bool, optional
158159
If True, runs in lightweight mode where mesh settings are read into a background solver session,
@@ -161,9 +162,9 @@ def __init__(
161162
If True, runs Fluent in Python mode. Defaults to None.
162163
gpu : bool, optional
163164
If True, starts Fluent with GPU Solver enabled.
164-
cwd : str, optional
165+
cwd : :class:`os.PathLike` or str, optional
165166
Working directory for the Fluent client.
166-
fluent_path: str, optional
167+
fluent_path: :class:`os.PathLike` or str, optional
167168
User-specified path for Fluent installation.
168169
topy : bool or str, optional
169170
A flag indicating whether to write equivalent Python journals from provided journal files; can also specify

src/ansys/fluent/core/meshing/meshing_workflow.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
from __future__ import annotations
2727

2828
from enum import Enum
29+
import os
2930

3031
from ansys.fluent.core.services.datamodel_se import PyMenuGeneric
32+
from ansys.fluent.core.types import PathType
3133
from ansys.fluent.core.utils.fluent_version import FluentVersion
3234
from ansys.fluent.core.workflow import Workflow
3335

@@ -272,7 +274,7 @@ def __init__(
272274
self,
273275
workflow: PyMenuGeneric,
274276
meshing: PyMenuGeneric,
275-
file_path: str,
277+
file_path: PathType,
276278
fluent_version: FluentVersion,
277279
) -> None:
278280
"""Initialize a ``LoadWorkflow`` instance.
@@ -283,8 +285,8 @@ def __init__(
283285
Underlying workflow object.
284286
meshing : PyMenuGeneric
285287
Meshing object.
286-
file_path: str
287-
Path to the saved workflow.
288+
file_path: os.PathLike[str | bytes] | str | bytes
289+
Path to the saved workflow file.
288290
fluent_version: FluentVersion
289291
Version of Fluent in this session.
290292
"""
@@ -293,7 +295,7 @@ def __init__(
293295
)
294296
self._meshing = meshing
295297
self._unsubscribe_root_affected_callback()
296-
self._load_workflow(file_path=file_path)
298+
self._load_workflow(file_path=os.fspath(file_path))
297299

298300

299301
class CreateWorkflow(Workflow):

src/ansys/fluent/core/parametric.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@
5151
"""
5252

5353
from math import ceil
54+
import os
5455
from typing import Any, Dict
5556

5657
from ansys.fluent.core.launcher.launcher import launch_fluent
58+
from ansys.fluent.core.types import PathType
5759
from ansys.fluent.core.utils.execution import asynchronous
5860

5961
BASE_DP_NAME = "Base DP"
@@ -293,11 +295,13 @@ class LocalParametricStudy:
293295
If the design point is not found.
294296
"""
295297

296-
def __init__(self, case_filepath: str, base_design_point_name: str = "Base DP"):
298+
def __init__(
299+
self, case_filepath: PathType, base_design_point_name: str = "Base DP"
300+
):
297301
"""Initialize LocalParametricStudy."""
298302
from ansys.fluent.core.filereader.casereader import CaseReader
299303

300-
self.case_filepath = case_filepath
304+
self.case_filepath = os.fspath(case_filepath)
301305
base_design_point = LocalDesignPoint(base_design_point_name)
302306
case_reader = CaseReader(case_file_name=case_filepath)
303307

src/ansys/fluent/core/services/app_utilities.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from dataclasses import dataclass
2626
from enum import Enum
27+
import os
2728
from typing import List, Tuple
2829

2930
import grpc
@@ -37,6 +38,7 @@
3738
TracingInterceptor,
3839
)
3940
from ansys.fluent.core.streaming_services.events_streaming import SolverEvent
41+
from ansys.fluent.core.types import PathType
4042

4143

4244
class AppUtilitiesService:
@@ -328,9 +330,9 @@ def exit(self) -> None:
328330
"""Exit."""
329331
self.scheme.exec(("(exit-server)",))
330332

331-
def set_working_directory(self, path: str) -> None:
333+
def set_working_directory(self, path: PathType) -> None:
332334
"""Change client cortex dir."""
333-
self.scheme.eval(f'(syncdir "{path}")')
335+
self.scheme.eval(f'(syncdir "{os.fspath(path)}")')
334336

335337

336338
class AppUtilities:
@@ -474,10 +476,10 @@ def exit(self) -> None:
474476
request = AppUtilitiesProtoModule.ExitRequest()
475477
self.service.exit(request)
476478

477-
def set_working_directory(self, path: str) -> None:
479+
def set_working_directory(self, path: PathType) -> None:
478480
"""Change client cortex dir."""
479481
request = AppUtilitiesProtoModule.SetWorkingDirectoryRequest()
480-
request.path = path
482+
request.path = os.fspath(path)
481483
self.service.set_working_directory(request)
482484

483485

src/ansys/fluent/core/session.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from enum import Enum
2626
import json
2727
import logging
28+
import os
2829
from typing import Any, Callable, Dict
2930
import warnings
3031
import weakref
@@ -46,6 +47,7 @@
4647
)
4748
from ansys.fluent.core.streaming_services.events_streaming import EventsManager
4849
from ansys.fluent.core.streaming_services.transcript_streaming import Transcript
50+
from ansys.fluent.core.types import PathType
4951
from ansys.fluent.core.utils.fluent_version import FluentVersion
5052

5153
from .rpvars import RPVars
@@ -452,15 +454,15 @@ def download(self, file_name: str, local_directory: str | None = None):
452454
if self._file_transfer_service:
453455
return self._file_transfer_service.download(file_name, local_directory)
454456

455-
def chdir(self, path: str) -> None:
457+
def chdir(self, path: PathType) -> None:
456458
"""Change Fluent working directory.
457459
458460
Parameters
459461
----------
460-
path : str
462+
path : os.PathLike[str | bytes] | str | bytes
461463
Path of the directory to change.
462464
"""
463-
self._app_utilities.set_working_directory(path)
465+
self._app_utilities.set_working_directory(os.fspath(path))
464466

465467
def __enter__(self):
466468
return self

src/ansys/fluent/core/session_base_meshing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""Provides a module to get base Meshing session."""
2424

2525
import logging
26+
import os
2627

2728
from ansys.fluent.core.fluent_connection import FluentConnection
2829
from ansys.fluent.core.meshing.meshing_workflow import (
@@ -35,6 +36,7 @@
3536
_make_datamodel_module,
3637
_make_tui_module,
3738
)
39+
from ansys.fluent.core.types import PathType
3840
from ansys.fluent.core.utils.fluent_version import (
3941
FluentVersion,
4042
get_version_for_file_name,
@@ -169,12 +171,12 @@ def topology_based_meshing_workflow(self, initialize: bool = True):
169171
)
170172
return self._current_workflow
171173

172-
def load_workflow(self, file_path: str):
174+
def load_workflow(self, file_path: PathType):
173175
"""Datamodel root of workflow."""
174176
self._current_workflow = LoadWorkflow(
175177
_make_datamodel_module(self, "workflow"),
176178
self.meshing,
177-
file_path,
179+
os.fspath(file_path),
178180
self.get_fluent_version(),
179181
)
180182
return self._current_workflow

0 commit comments

Comments
 (0)