Skip to content

Commit 2fd6d48

Browse files
committed
clean-up ExportTask
1 parent 08a735b commit 2fd6d48

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

libs/pyext/src/ecflow/python/ExportTask.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,41 @@
1818
#include "ecflow/python/PythonBinding.hpp"
1919
#include "ecflow/python/PythonUtil.hpp"
2020

21-
// Sized protocol
22-
bool task_len(task_ptr self) {
23-
return self->aliases().size();
21+
namespace {
22+
23+
// Task
24+
25+
std::shared_ptr<Task> Task_init(const std::string& name, const py::args& args, const py::kwargs& kwargs) {
26+
std::cout << "task_init: name: " << name << std::endl;
27+
auto node = std::make_shared<Task>(name);
28+
NodeUtil::add(*node, args);
29+
NodeUtil::add(*node, kwargs);
30+
return node;
2431
}
2532

26-
task_ptr task_enter(task_ptr self) {
33+
task_ptr Task_enter(task_ptr self) {
2734
return self;
2835
}
2936

30-
bool task_exit(task_ptr self, const py::object& type, const py::object& value, const py::object& traceback) {
37+
bool Task_exit(task_ptr self, const py::object& type, const py::object& value, const py::object& traceback) {
3138
return false;
3239
}
3340

34-
std::string task_to_string(task_ptr self) {
41+
std::string Task_str(task_ptr self) {
3542
return ecf::as_string(*self, PrintStyleHolder::getStyle());
3643
}
3744

38-
std::shared_ptr<Task> task_init(const std::string& name, const py::args& args, const py::kwargs& kwargs) {
39-
std::cout << "task_init: name: " << name << std::endl;
40-
auto node = std::make_shared<Task>(name);
41-
NodeUtil::add(*node, args);
42-
NodeUtil::add(*node, kwargs);
43-
return node;
45+
bool Task_len(task_ptr self) {
46+
return self->aliases().size();
4447
}
4548

46-
std::string alias_to_string(alias_ptr self) {
49+
// Alias
50+
51+
std::string Alias_str(alias_ptr self) {
4752
return ecf::as_string(*self, PrintStyleHolder::getStyle());
4853
}
4954

50-
// See: http://wiki.python.org/moin/boost.python/HowTo#boost.function_objects
55+
} // namespace
5156

5257
void export_Task(py::module& m) {
5358

@@ -70,29 +75,21 @@ void export_Task(py::module& m) {
7075

7176
py::class_<Task, Submittable, std::shared_ptr<Task>>(m, "Task", DefsDoc::task_doc())
7277

73-
.def(py::init(&task_init), DefsDoc::task_doc())
78+
.def(py::init(&Task_init), DefsDoc::task_doc())
7479
.def(py::init<const std::string&>(), py::arg("name"))
75-
.def(py::self == py::self) // __eq__
76-
.def("__enter__", &task_enter) // allow with statement, hence indentation support
77-
.def("__exit__", &task_exit) // allow with statement, hence indentation support
78-
.def("__str__", &task_to_string) // __str__
79-
.def("__copy__", pyutil_copy_object<Task>) // __copy__ uses copy constructor
80-
.def("__len__", &task_len) // Implement sized protocol for immediate children
81-
.def("__iter__", &Task::aliases) // implement iter protocol
80+
.def(py::self == py::self)
81+
.def("__enter__", &Task_enter)
82+
.def("__exit__", &Task_exit)
83+
.def("__str__", &Task_str)
84+
.def("__copy__", pyutil_copy_object<Task>)
85+
.def("__len__", &Task_len)
86+
.def("__iter__", &Task::aliases)
8287
.def_property_readonly("aliases", &Task::aliases, "Returns a list of aliases")
8388
.def_property_readonly("nodes", &Task::aliases, "Returns a list of aliases");
8489

85-
#if ECF_ENABLE_PYTHON_PTR_REGISTER
86-
py::register_ptr_to_python<task_ptr>(); // needed for mac and boost 1.6
87-
#endif
88-
8990
py::class_<Alias, Submittable, std::shared_ptr<Alias>>(m, "Alias", DefsDoc::alias_doc())
9091

9192
.def(py::self == py::self)
92-
.def("__str__", &alias_to_string)
93+
.def("__str__", &Alias_str)
9394
.def("__copy__", pyutil_copy_object<Alias>);
94-
95-
#if ECF_ENABLE_PYTHON_PTR_REGISTER
96-
py::register_ptr_to_python<alias_ptr>(); // needed for mac and boost 1.6
97-
#endif
9895
}

0 commit comments

Comments
 (0)