3131#include " openPMD/binding/python/Common.hpp"
3232#include < filesystem>
3333#include < optional>
34+ #include < tuple>
3435
3536#if openPMD_HAVE_MPI
3637// re-implemented signatures:
@@ -72,16 +73,34 @@ namespace internal
7273{
7374struct DefineSeriesConstructorPerPathType
7475{
75- template <typename PathType>
76+ static constexpr auto json_cfg_as_string (std::string const &str)
77+ -> std::string const &
78+ {
79+ return str;
80+ }
81+
82+ static auto json_cfg_as_string (py::object const &obj) -> std::string
83+ {
84+ py::module_ json = py::module_::import (" json" );
85+ auto dumps = json.attr (" dumps" );
86+ auto dumped = dumps (obj);
87+ return py::cast<std::string>(dumped);
88+ }
89+
90+ template <typename TupleType>
7691 static void call (py::class_<Series, Attributable> &py_class)
7792 {
93+ using PathType = typename std::tuple_element<0 , TupleType>::type;
94+ using JsonCfgType = typename std::tuple_element<1 , TupleType>::type;
95+
7896 py_class
7997 .def (
8098 py::init ([](PathType const &filepath,
8199 Access at,
82- std::string const &options) {
100+ JsonCfgType const &options) {
101+ auto options_ = json_cfg_as_string (options);
83102 py::gil_scoped_release release;
84- return new Series (filepath, at, options );
103+ return new Series (filepath, at, options_ );
85104 }),
86105 py::arg (" filepath" ),
87106 py::arg (" access" ),
@@ -137,7 +156,8 @@ It will be replaced with an automatically determined file name extension:
137156 py::init ([](PathType const &filepath,
138157 Access at,
139158 py::object &comm,
140- std::string const &options) {
159+ JsonCfgType const &options) {
160+ auto options_ = json_cfg_as_string (options);
141161 auto variant = pythonObjectAsMpiComm (comm);
142162 if (auto errorMsg = std::get_if<std::string>(&variant))
143163 {
@@ -147,7 +167,10 @@ It will be replaced with an automatically determined file name extension:
147167 {
148168 py::gil_scoped_release release;
149169 return new Series (
150- filepath, at, std::get<MPI_Comm>(variant), options);
170+ filepath,
171+ at,
172+ std::get<MPI_Comm>(variant),
173+ options_);
151174 }
152175 }),
153176 py::arg (" filepath" ),
@@ -299,8 +322,10 @@ not possible once it has been closed.
299322 py::class_<Series, Attributable> cl (m, " Series" );
300323 ::auxiliary::ForEachType<
301324 ::internal::DefineSeriesConstructorPerPathType,
302- std::string,
303- std::filesystem::path>::template call (cl);
325+ std::tuple<std::string, std::string>,
326+ std::tuple<std::string, py::object>,
327+ std::tuple<std::filesystem::path, std::string>,
328+ std::tuple<std::filesystem::path, py::object> >::template call (cl);
304329
305330 cl.def (" __bool__" , &Series::operator bool )
306331 .def (" __len__" , [](Series const &s) { return s.iterations .size (); })
0 commit comments