feat: implement platform-specific path handling in mapdl.directory - #4079
Conversation
|
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
Reviewer's GuideThis PR introduces platform-aware path handling by wrapping the Mapdl working directory string in an OS-specific pathlib.PurePath object via a new helper and updates the directory getter/setter to use it, with corresponding adjustments to existing tests and a new test for join behavior. Class diagram for updated Mapdl directory path handlingclassDiagram
class MapdlCore {
+platform: str
+_path: pathlib.PurePath
+directory: property
+directory(path: Union[str, pathlib.Path])
+_wrap_directory(path: str) pathlib.PurePath
}
MapdlCore --> "1" pathlib.PurePath : uses
class pathlib.PurePath
class pathlib.PureWindowsPath
class pathlib.PurePosixPath
pathlib.PureWindowsPath --|> pathlib.PurePath
pathlib.PurePosixPath --|> pathlib.PurePath
MapdlCore ..> pathlib.PureWindowsPath : returns if platform=="windows"
MapdlCore ..> pathlib.PurePosixPath : returns if platform=="linux" or fallback
Class diagram for _wrap_directory helper methodclassDiagram
class MapdlCore {
+_wrap_directory(path: str) pathlib.PurePath
}
class pathlib.PureWindowsPath
class pathlib.PurePosixPath
MapdlCore ..> pathlib.PureWindowsPath : returns on Windows
MapdlCore ..> pathlib.PurePosixPath : returns on Linux/Other
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds platform-aware path handling for the mapdl.directory property, so it now returns a PurePath specific to Windows or POSIX and updates tests to use pathlib.
- Introduces
_wrap_directoryto producePureWindowsPathorPurePosixPathdepending onmapdl.platform. - Updates the
directorygetter/setter to call_wrap_directoryinstead of storing raw strings. - Refactors tests to import
pathliband assert againstPurePathbehavior.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_mapdl.py | Switched from Path import to pathlib, added a new test to assert PurePath behavior. |
| src/ansys/mapdl/core/mapdl_core.py | Added _wrap_directory and updated directory getter/setter to return PurePath objects. |
Comments suppressed due to low confidence (1)
src/ansys/mapdl/core/mapdl_core.py:559
- The
directoryproperty is annotated to returnstrbut now returns apathlib.PurePath. Update the return type annotation topathlib.PurePath(orUnion[str, pathlib.PurePath]) to reflect the new behavior.
path = path.replace("\\", "/")
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4079 +/- ##
==========================================
- Coverage 91.84% 91.80% -0.05%
==========================================
Files 187 187
Lines 15023 15032 +9
==========================================
+ Hits 13798 13800 +2
- Misses 1225 1232 +7 🚀 New features to boost your workflow:
|
|
@pyansys-ci-bot LGTM. |
…4079) * feat: implement platform-specific path handling in _MapdlCore and update tests * chore: adding changelog file 4079.miscellaneous.md [dependabot-skip] * fix: handle uninitialized MAPDL platform in _wrap_directory method * Update tests/test_mapdl.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * fix: avoid string operations on Path object * test: enhance directory path handling with platform-specific parameterization --------- Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

Description
As the title.
So we can do:
Issue linked
Close #4078
Checklist
draftif it is not ready to be reviewed yet.feat: adding new MAPDL command)Summary by Sourcery
Introduce OS-aware path handling for mapdl.directory by wrapping paths in pathlib.PureWindowsPath or pathlib.PurePosixPath, and update tests accordingly
New Features:
Enhancements:
Tests: