Skip to content

Commit 356dffc

Browse files
committed
Portable repr
1 parent 98d3e1c commit 356dffc

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

core/python/modconstruct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,5 @@ def PipelineAddCallable(self, callable, name=None, subprocess=False, **kwargs):
278278

279279
# Add this as G3Pipeline's Add method so it takes any Python callable
280280
G3Pipeline.Add = PipelineAddCallable
281-
G3Pipeline.__repr__ = lambda self: repr(self._pipelineinfo.pipelineinfo) if hasattr(self, '_pipelineinfo') else 'pipe = spt3g.core.G3Pipeline()'
281+
G3Pipeline.__repr__ = lambda self: repr(self._pipelineinfo.pipelineinfo) if hasattr(self, '_pipelineinfo') else 'pipe = {}.G3Pipeline()'.format(G3Pipeline.__module__)
282282

core/src/G3PipelineInfo.cxx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,20 @@ G3PipelineInfo::Description() const
229229
}
230230

231231
static std::string
232-
G3PipelineInfo_repr(const G3PipelineInfo &pi)
232+
G3PipelineInfo_repr(const py::object &pi)
233233
{
234-
std::string rv;
235-
rv = "pipe = spt3g.core.G3Pipeline()";
234+
std::ostringstream rv;
235+
rv << "pipe = ";
236+
rv << py::extract<std::string>(pi.attr("__class__").attr("__module__"))();
237+
rv << ".G3Pipeline()";
236238

237-
for (auto i : pi.modules)
238-
rv += "\n" + G3ModuleConfig_repr(i);
239-
return rv;
239+
for (auto i : py::extract<const G3PipelineInfo &>(pi)().modules)
240+
rv << "\n" << G3ModuleConfig_repr(i);
241+
return rv.str();
240242
}
241243

242244
static void
243-
G3PipelineInfo_run(const G3PipelineInfo &pi)
245+
G3PipelineInfo_run(const py::object &pi)
244246
{
245247
py::object main = py::module_::import("__main__");
246248
py::dict global = py::dict(main.attr("__dict__"));

core/src/G3Quat.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,12 @@ quat_str(const Quat &q)
800800
}
801801

802802
static std::string
803-
quat_repr(const Quat &q)
803+
quat_repr(const py::object &q)
804804
{
805805
std::ostringstream oss;
806-
oss << "spt3g.core.Quat" << q;
806+
oss << py::extract<std::string>(q.attr("__class__").attr("__module__"))() << ".";
807+
oss << py::extract<std::string>(q.attr("__class__").attr("__name__"))();
808+
oss << py::extract<const Quat &>(q)();
807809
return oss.str();
808810
}
809811
}

0 commit comments

Comments
 (0)