2929#include " openPMD/snapshots/StatefulIterator.hpp"
3030
3131#include " openPMD/binding/python/Common.hpp"
32- #include < filesystem>
3332#include < optional>
3433#include < tuple>
3534
35+ #if openPMD_USE_FILESYSTEM_HEADER
36+ #include < filesystem>
37+ #endif
38+
3639#if openPMD_HAVE_MPI
3740// re-implemented signatures:
3841// include <mpi4py/mpi4py.h>
@@ -85,6 +88,26 @@ struct DefineSeriesConstructorPerPathType
8588 return ::auxiliary::json_dumps (obj);
8689 }
8790
91+ static constexpr auto filepath_as_string (std::string const &str)
92+ -> std::string const &
93+ {
94+ return str;
95+ }
96+
97+ #if openPMD_USE_FILESYSTEM_HEADER
98+ static auto filepath_as_string (std::filesystem::path const &path)
99+ -> std::string
100+ {
101+ return path;
102+ }
103+ #else
104+ static auto filepath_as_string (py::object const &path) -> std::string
105+ {
106+ auto casted = path.attr (" __str__" )();
107+ return py::cast<std::string>(casted);
108+ }
109+ #endif
110+
88111 template <typename TupleType>
89112 static void call (py::class_<Series, Attributable> &py_class)
90113 {
@@ -96,9 +119,10 @@ struct DefineSeriesConstructorPerPathType
96119 py::init ([](PathType const &filepath,
97120 Access at,
98121 JsonCfgType const &options) {
99- auto options_ = json_cfg_as_string (options);
122+ decltype (auto ) filepath_ = filepath_as_string (filepath);
123+ decltype (auto ) options_ = json_cfg_as_string (options);
100124 py::gil_scoped_release release;
101- return new Series (filepath , at, options_);
125+ return new Series (filepath_ , at, options_);
102126 }),
103127 py::arg (" filepath" ),
104128 py::arg (" access" ),
@@ -155,7 +179,8 @@ It will be replaced with an automatically determined file name extension:
155179 Access at,
156180 py::object &comm,
157181 JsonCfgType const &options) {
158- auto options_ = json_cfg_as_string (options);
182+ decltype (auto ) filepath_ = filepath_as_string (filepath);
183+ decltype (auto ) options_ = json_cfg_as_string (options);
159184 auto variant = pythonObjectAsMpiComm (comm);
160185 if (auto errorMsg =
161186 std::get_if<py_object_to_mpi_comm_error>(&variant))
@@ -185,7 +210,7 @@ It will be replaced with an automatically determined file name extension:
185210 {
186211 py::gil_scoped_release release;
187212 return new Series (
188- filepath ,
213+ filepath_ ,
189214 at,
190215 std::get<MPI_Comm>(variant),
191216 options_);
@@ -343,8 +368,14 @@ not possible once it has been closed.
343368 ::internal::DefineSeriesConstructorPerPathType,
344369 std::tuple<std::string, std::string>,
345370 std::tuple<std::string, py::object>,
371+ #if openPMD_USE_FILESYSTEM_HEADER
346372 std::tuple<std::filesystem::path, std::string>,
347- std::tuple<std::filesystem::path, py::object> >::template call (cl);
373+ std::tuple<std::filesystem::path, py::object>
374+ #else
375+ std::tuple<py::object, std::string>,
376+ std::tuple<py::object, py::object>
377+ #endif
378+ >::template call (cl);
348379
349380 cl.def (" __bool__" , &Series::operator bool )
350381 .def (" __len__" , [](Series const &s) { return s.iterations .size (); })
0 commit comments