Skip to content

Commit 1def483

Browse files
feat: accept pathlib.Path as input in missing methods (#1385)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 8af9de9 commit 1def483

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

doc/changelog.d/1385.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
accept pathlib.Path as input in missing methods

src/ansys/geometry/core/designer/design.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def __build_export_file_location(self, location: Path | str | None, ext: str) ->
311311
"""
312312
return (Path(location) if location else Path.cwd()) / f"{self.name}.{ext}"
313313

314-
def export_to_scdocx(self, location: Path | str | None = None) -> str:
314+
def export_to_scdocx(self, location: Path | str | None = None) -> Path:
315315
"""Export the design to an scdocx file.
316316
317317
Parameters
@@ -322,7 +322,7 @@ def export_to_scdocx(self, location: Path | str | None = None) -> str:
322322
323323
Returns
324324
-------
325-
str
325+
~pathlib.Path
326326
The path to the saved file.
327327
"""
328328
# Define the file location
@@ -334,7 +334,7 @@ def export_to_scdocx(self, location: Path | str | None = None) -> str:
334334
# Return the file location
335335
return file_location
336336

337-
def export_to_parasolid_text(self, location: Path | str | None = None) -> str:
337+
def export_to_parasolid_text(self, location: Path | str | None = None) -> Path:
338338
"""Export the design to a Parasolid text file.
339339
340340
Parameters
@@ -345,7 +345,7 @@ def export_to_parasolid_text(self, location: Path | str | None = None) -> str:
345345
346346
Returns
347347
-------
348-
str
348+
~pathlib.Path
349349
The path to the saved file.
350350
"""
351351
# Determine the extension based on the backend type
@@ -360,7 +360,7 @@ def export_to_parasolid_text(self, location: Path | str | None = None) -> str:
360360
# Return the file location
361361
return file_location
362362

363-
def export_to_parasolid_bin(self, location: Path | str | None = None) -> str:
363+
def export_to_parasolid_bin(self, location: Path | str | None = None) -> Path:
364364
"""Export the design to a Parasolid binary file.
365365
366366
Parameters
@@ -371,7 +371,7 @@ def export_to_parasolid_bin(self, location: Path | str | None = None) -> str:
371371
372372
Returns
373373
-------
374-
str
374+
~pathlib.Path
375375
The path to the saved file.
376376
"""
377377
# Determine the extension based on the backend type
@@ -386,7 +386,7 @@ def export_to_parasolid_bin(self, location: Path | str | None = None) -> str:
386386
# Return the file location
387387
return file_location
388388

389-
def export_to_fmd(self, location: Path | str | None = None) -> str:
389+
def export_to_fmd(self, location: Path | str | None = None) -> Path:
390390
"""Export the design to an FMD file.
391391
392392
Parameters
@@ -397,7 +397,7 @@ def export_to_fmd(self, location: Path | str | None = None) -> str:
397397
398398
Returns
399399
-------
400-
str
400+
~pathlib.Path
401401
The path to the saved file.
402402
"""
403403
# Define the file location
@@ -409,7 +409,7 @@ def export_to_fmd(self, location: Path | str | None = None) -> str:
409409
# Return the file location
410410
return file_location
411411

412-
def export_to_step(self, location: Path | str | None = None) -> str:
412+
def export_to_step(self, location: Path | str | None = None) -> Path:
413413
"""Export the design to a STEP file.
414414
415415
Parameters
@@ -420,7 +420,7 @@ def export_to_step(self, location: Path | str | None = None) -> str:
420420
421421
Returns
422422
-------
423-
str
423+
~pathlib.Path
424424
The path to the saved file.
425425
"""
426426
# Define the file location
@@ -432,7 +432,7 @@ def export_to_step(self, location: Path | str | None = None) -> str:
432432
# Return the file location
433433
return file_location
434434

435-
def export_to_iges(self, location: Path | str = None) -> str:
435+
def export_to_iges(self, location: Path | str = None) -> Path:
436436
"""Export the design to an IGES file.
437437
438438
Parameters
@@ -443,7 +443,7 @@ def export_to_iges(self, location: Path | str = None) -> str:
443443
444444
Returns
445445
-------
446-
str
446+
~pathlib.Path
447447
The path to the saved file.
448448
"""
449449
# Define the file location
@@ -455,7 +455,7 @@ def export_to_iges(self, location: Path | str = None) -> str:
455455
# Return the file location
456456
return file_location
457457

458-
def export_to_pmdb(self, location: Path | str | None = None) -> str:
458+
def export_to_pmdb(self, location: Path | str | None = None) -> Path:
459459
"""Export the design to a PMDB file.
460460
461461
Parameters
@@ -466,7 +466,7 @@ def export_to_pmdb(self, location: Path | str | None = None) -> str:
466466
467467
Returns
468468
-------
469-
str
469+
~pathlib.Path
470470
The path to the saved file.
471471
"""
472472
# Define the file location

src/ansys/geometry/core/modeler.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _upload_file(
285285
@protect_grpc
286286
def open_file(
287287
self,
288-
file_path: str,
288+
file_path: str | Path,
289289
upload_to_server: bool = True,
290290
import_options: ImportOptions = ImportOptions(),
291291
) -> "Design":
@@ -301,7 +301,7 @@ def open_file(
301301
302302
Parameters
303303
----------
304-
file_path : str
304+
file_path : str, ~pathlib.Path
305305
Path of the file to open. The extension of the file must be included.
306306
upload_to_server : bool
307307
True if the service is running on a remote machine. If service is running on the local
@@ -314,6 +314,9 @@ def open_file(
314314
Design
315315
Newly imported design.
316316
"""
317+
# Use str format of Path object here
318+
file_path = str(file_path) if isinstance(file_path, Path) else file_path
319+
317320
# Format-specific logic - upload the whole containing folder for assemblies
318321
if upload_to_server:
319322
if any(
@@ -343,7 +346,7 @@ def __repr__(self) -> str:
343346

344347
@protect_grpc
345348
def run_discovery_script_file(
346-
self, file_path: str, script_args: dict[str, str] | None = None, import_design=False
349+
self, file_path: str | Path, script_args: dict[str, str] | None = None, import_design=False
347350
) -> tuple[dict[str, str], Optional["Design"]]:
348351
"""Run a Discovery script file.
349352
@@ -374,7 +377,7 @@ def run_discovery_script_file(
374377
375378
Parameters
376379
----------
377-
file_path : str
380+
file_path : str, ~pathlib.Path
378381
Path of the file. The extension of the file must be included.
379382
script_args : dict[str, str], optional.
380383
Arguments to pass to the script. By default, ``None``.
@@ -398,6 +401,9 @@ def run_discovery_script_file(
398401
If the Discovery script fails to run. Otherwise, assume that the script
399402
ran successfully.
400403
"""
404+
# Use str format of Path object here
405+
file_path = str(file_path) if isinstance(file_path, Path) else file_path
406+
401407
serv_path = self._upload_file(file_path)
402408
ga_stub = DbuApplicationStub(self._grpc_client.channel)
403409
request = RunScriptFileRequest(

0 commit comments

Comments
 (0)