modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

feature: broader path-like support #1729

Closed wpbonelli closed 1 year ago

wpbonelli commented 1 year ago

Is your feature request related to a problem? Please describe. FloPy currently expects strings for some path parameters (files/dirs to read from or write to, etc). #1712 recently added support for pathlib.Path to some internals, allowing path-like objects to be passed e.g. to MFSimulation's ctor.

Describe the solution you'd like Extending path-like support to all user-facing APIs would be convenient for use with modern pathlib.Path, removing the need to wrap with str(...), without breaking existing string usages. Type hint Union[str, os.PathLike] could be used in the spirit of PEP 519 — further SO discussions here and here. In many cases Path/path-like are already implicitly supported and docstrings could just be updated, but this is not universally true and some refactoring would be needed.

mwtoews commented 1 year ago

Thanks for raising this. I've been slowly working on this since October 2022, e.g. #1583, #1603. With some of the previous refactoring, I've generally found path manipulation with pathlib to be simpler and easier to read than os.path.

Some general tips:

wpbonelli commented 1 year ago

Closed by #1730. Some notebooks and tests still use strings instead of paths, but maybe not a terrible idea to keep it that way to exercise both options