summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2023-04-12 20:33:40 +0200
committerAlexis Hildebrandt <afh@surryhill.net>2023-04-12 21:53:11 +0200
commit9244a27f9548a1d39fb01348fde66ff81f5150a4 (patch)
tree0f9d06a762a9a9939e1f37be60cf2b5e47da7983 /src
parent5f78556078d2e61d5c0ef44e36d58f3864cd84d1 (diff)
downloadfork-ledger-9244a27f9548a1d39fb01348fde66ff81f5150a4.tar.gz
fork-ledger-9244a27f9548a1d39fb01348fde66ff81f5150a4.tar.bz2
fork-ledger-9244a27f9548a1d39fb01348fde66ff81f5150a4.zip
Refactor python related types into ledger::python namespace
Diffstat (limited to 'src')
-rw-r--r--src/py_account.cc7
-rw-r--r--src/py_amount.cc1
-rw-r--r--src/py_balance.cc1
-rw-r--r--src/py_commodity.cc13
-rw-r--r--src/py_item.cc1
-rw-r--r--src/py_journal.cc12
-rw-r--r--src/py_session.cc7
-rw-r--r--src/py_times.cc6
-rw-r--r--src/py_utils.cc2
-rw-r--r--src/py_value.cc1
-rw-r--r--src/py_xact.cc5
-rw-r--r--src/pyinterp.cc31
-rw-r--r--src/pyinterp.h24
-rw-r--r--src/pyutils.h6
-rw-r--r--src/textual.cc2
15 files changed, 65 insertions, 54 deletions
diff --git a/src/py_account.cc b/src/py_account.cc
index 67218c8b..2e1fd35b 100644
--- a/src/py_account.cc
+++ b/src/py_account.cc
@@ -40,6 +40,7 @@
namespace ledger {
using namespace flags;
+using namespace python;
using namespace boost::python;
namespace {
@@ -232,11 +233,11 @@ void export_account()
.def("__len__", accounts_len)
.def("__getitem__", accounts_getitem, return_internal_reference<>())
- .def("__iter__", python::range<return_internal_reference<> >
+ .def("__iter__", boost::python::range<return_internal_reference<> >
(&account_t::accounts_begin, &account_t::accounts_end))
- .def("accounts", python::range<return_internal_reference<> >
+ .def("accounts", boost::python::range<return_internal_reference<> >
(&account_t::accounts_begin, &account_t::accounts_end))
- .def("posts", python::range<return_internal_reference<> >
+ .def("posts", boost::python::range<return_internal_reference<> >
(&account_t::posts_begin, &account_t::posts_end))
.def("has_xdata", &account_t::has_xdata)
diff --git a/src/py_amount.cc b/src/py_amount.cc
index ce5c26d8..ae554f58 100644
--- a/src/py_amount.cc
+++ b/src/py_amount.cc
@@ -39,6 +39,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
namespace {
diff --git a/src/py_balance.cc b/src/py_balance.cc
index 9b476244..47cd7fc9 100644
--- a/src/py_balance.cc
+++ b/src/py_balance.cc
@@ -39,6 +39,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
namespace {
diff --git a/src/py_commodity.cc b/src/py_commodity.cc
index 28074b5c..3ae6801f 100644
--- a/src/py_commodity.cc
+++ b/src/py_commodity.cc
@@ -40,6 +40,7 @@
namespace ledger {
using namespace flags;
+using namespace python;
using namespace boost::python;
namespace {
@@ -120,8 +121,8 @@ namespace {
return (*i).second.get();
}
- python::list py_pool_keys(commodity_pool_t& pool) {
- python::list keys;
+ list py_pool_keys(commodity_pool_t& pool) {
+ list keys;
BOOST_REVERSE_FOREACH
(const commodity_pool_t::commodities_map::value_type& pair,
pool.commodities) {
@@ -296,15 +297,15 @@ void export_commodity()
.def("has_key", py_pool_contains)
.def("__contains__", py_pool_contains)
.def("__iter__",
- python::range<return_internal_reference<> >
+ boost::python::range<return_internal_reference<> >
(py_pool_commodities_begin, py_pool_commodities_end))
.def("iteritems",
- python::range<return_internal_reference<> >
+ boost::python::range<return_internal_reference<> >
(py_pool_commodities_begin, py_pool_commodities_end))
- .def("iterkeys", python::range<>(py_pool_commodities_keys_begin,
+ .def("iterkeys", boost::python::range<>(py_pool_commodities_keys_begin,
py_pool_commodities_keys_end))
.def("itervalues",
- python::range<return_internal_reference<> >
+ boost::python::range<return_internal_reference<> >
(py_pool_commodities_values_begin, py_pool_commodities_values_end))
;
diff --git a/src/py_item.cc b/src/py_item.cc
index a23ebe5f..3a458000 100644
--- a/src/py_item.cc
+++ b/src/py_item.cc
@@ -40,6 +40,7 @@
namespace ledger {
using namespace flags;
+using namespace python;
using namespace boost::python;
namespace {
diff --git a/src/py_journal.cc b/src/py_journal.cc
index 08a4ebf1..d96618e7 100644
--- a/src/py_journal.cc
+++ b/src/py_journal.cc
@@ -241,7 +241,7 @@ void export_journal()
boost::noncopyable >("PostCollectorWrapper", no_init)
.def("__len__", &collector_wrapper::length)
.def("__getitem__", posts_getitem, return_internal_reference<>())
- .def("__iter__", python::range<return_internal_reference<> >
+ .def("__iter__", boost::python::range<return_internal_reference<> >
(&collector_wrapper::begin, &collector_wrapper::end))
;
@@ -306,15 +306,15 @@ void export_journal()
with_custodian_and_ward_postcall<1, 0> >())
#endif
- .def("__iter__", python::range<return_internal_reference<> >
+ .def("__iter__", boost::python::range<return_internal_reference<> >
(&journal_t::xacts_begin, &journal_t::xacts_end))
- .def("xacts", python::range<return_internal_reference<> >
+ .def("xacts", boost::python::range<return_internal_reference<> >
(&journal_t::xacts_begin, &journal_t::xacts_end))
- .def("auto_xacts", python::range<return_internal_reference<> >
+ .def("auto_xacts", boost::python::range<return_internal_reference<> >
(&journal_t::auto_xacts_begin, &journal_t::auto_xacts_end))
- .def("period_xacts", python::range<return_internal_reference<> >
+ .def("period_xacts", boost::python::range<return_internal_reference<> >
(&journal_t::period_xacts_begin, &journal_t::period_xacts_end))
- .def("sources", python::range<return_internal_reference<> >
+ .def("sources", boost::python::range<return_internal_reference<> >
(&journal_t::sources_begin, &journal_t::sources_end))
#if 0
.def("read", py_read)
diff --git a/src/py_session.cc b/src/py_session.cc
index 02529334..3606adc6 100644
--- a/src/py_session.cc
+++ b/src/py_session.cc
@@ -38,6 +38,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
namespace {
@@ -78,12 +79,12 @@ void export_session()
scope().attr("session") =
object(ptr(static_cast<session_t *>(python_session.get())));
scope().attr("close_journal_files") =
- python::make_function(&py_close_journal_files);
+ boost::python::make_function(&py_close_journal_files);
scope().attr("read_journal") =
- python::make_function(&py_read_journal,
+ boost::python::make_function(&py_read_journal,
return_internal_reference<>());
scope().attr("read_journal_from_string") =
- python::make_function(&py_read_journal_from_string,
+ boost::python::make_function(&py_read_journal_from_string,
return_internal_reference<>());
}
diff --git a/src/py_times.cc b/src/py_times.cc
index 79bacad7..d2afb5c8 100644
--- a/src/py_times.cc
+++ b/src/py_times.cc
@@ -40,6 +40,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
struct date_to_python
@@ -81,7 +82,6 @@ struct date_from_python
typedef register_python_conversion<date_t, date_to_python, date_from_python>
date_python_conversion;
-
struct datetime_to_python
{
static PyObject* convert(const datetime_t& moment)
@@ -145,7 +145,6 @@ typedef register_python_conversion<datetime_t,
datetime_to_python, datetime_from_python>
datetime_python_conversion;
-
/* Convert time_duration to/from python */
struct duration_to_python
{
@@ -185,7 +184,7 @@ struct duration_from_python
}
static void construct(PyObject* obj_ptr,
- python::converter::rvalue_from_python_stage1_data * data)
+ converter::rvalue_from_python_stage1_data * data)
{
PyDateTime_Delta const* pydelta
= reinterpret_cast<PyDateTime_Delta*>(obj_ptr);
@@ -217,7 +216,6 @@ typedef register_python_conversion<time_duration_t,
duration_to_python, duration_from_python>
duration_python_conversion;
-
datetime_t py_parse_datetime(const string& str) {
return parse_datetime(str);
}
diff --git a/src/py_utils.cc b/src/py_utils.cc
index 1a28f087..5dae1ab9 100644
--- a/src/py_utils.cc
+++ b/src/py_utils.cc
@@ -37,6 +37,7 @@
namespace ledger {
using namespace flags;
+using namespace python;
using namespace boost::python;
struct bool_to_python
@@ -74,7 +75,6 @@ struct bool_from_python
typedef register_python_conversion<bool, bool_to_python, bool_from_python>
bool_python_conversion;
-
struct string_to_python
{
static PyObject* convert(const string& str)
diff --git a/src/py_value.cc b/src/py_value.cc
index 30c32e94..52597c9a 100644
--- a/src/py_value.cc
+++ b/src/py_value.cc
@@ -38,6 +38,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(value_overloads, value, 0, 2)
diff --git a/src/py_xact.cc b/src/py_xact.cc
index a0aa24d6..9a1017ba 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -38,6 +38,7 @@
namespace ledger {
+using namespace python;
using namespace boost::python;
namespace {
@@ -104,9 +105,9 @@ void export_xact()
.def("finalize", &xact_base_t::finalize)
- .def("__iter__", python::range<return_internal_reference<> >
+ .def("__iter__", boost::python::range<return_internal_reference<> >
(&xact_t::posts_begin, &xact_t::posts_end))
- .def("posts", python::range<return_internal_reference<> >
+ .def("posts", boost::python::range<return_internal_reference<> >
(&xact_t::posts_begin, &xact_t::posts_end))
.def("valid", &xact_base_t::valid)
diff --git a/src/pyinterp.cc b/src/pyinterp.cc
index 6a261609..71bbea22 100644
--- a/src/pyinterp.cc
+++ b/src/pyinterp.cc
@@ -41,6 +41,7 @@
namespace ledger {
using namespace python;
+using namespace boost::python;
shared_ptr<python_interpreter_t> python_session;
@@ -110,7 +111,7 @@ python_module_t::python_module_t(const string& name)
import_module(name);
}
-python_module_t::python_module_t(const string& name, python::object obj)
+python_module_t::python_module_t(const string& name, object obj)
: scope_t(), module_name(name), module_globals()
{
module_object = obj;
@@ -119,7 +120,7 @@ python_module_t::python_module_t(const string& name, python::object obj)
void python_module_t::import_module(const string& name, bool import_direct)
{
- object mod = python::import(name.c_str());
+ object mod = import(name.c_str());
if (! mod)
throw_(std::runtime_error,
_f("Module import failed (couldn't find %1%)") % name);
@@ -177,27 +178,27 @@ void python_interpreter_t::initialize()
void python_interpreter_t::hack_system_paths()
{
// Hack ledger.__path__ so it points to a real location
- python::object sys_module = python::import("sys");
- python::object sys_dict = sys_module.attr("__dict__");
+ object sys_module = import("sys");
+ object sys_dict = sys_module.attr("__dict__");
- python::list paths(sys_dict["path"]);
+ list paths(sys_dict["path"]);
#if DEBUG_ON
bool path_initialized = false;
#endif
- int n = python::extract<int>(paths.attr("__len__")());
+ int n = extract<int>(paths.attr("__len__")());
for (int i = 0; i < n; i++) {
- python::extract<std::string> str(paths[i]);
+ extract<std::string> str(paths[i]);
path pathname(str());
DEBUG("python.interp", "sys.path = " << pathname);
if (exists(pathname / "ledger" / "__init__.py")) {
- if (python::object module_ledger = python::import("ledger")) {
+ if (object module_ledger = import("ledger")) {
DEBUG("python.interp",
"Setting ledger.__path__ = " << (pathname / "ledger"));
- python::object ledger_dict = module_ledger.attr("__dict__");
- python::list temp_list;
+ object ledger_dict = module_ledger.attr("__dict__");
+ list temp_list;
temp_list.append((pathname / "ledger").string());
ledger_dict["__path__"] = temp_list;
@@ -223,12 +224,12 @@ object python_interpreter_t::import_option(const string& str)
if (! is_initialized)
initialize();
- python::object sys_module = python::import("sys");
- python::object sys_dict = sys_module.attr("__dict__");
+ object sys_module = import("sys");
+ object sys_dict = sys_module.attr("__dict__");
path file(str);
string name(str);
- python::list paths(sys_dict["path"]);
+ list paths(sys_dict["path"]);
if (contains(str, ".py")) {
path& cwd(parsing_context.get_current().current_directory);
@@ -380,7 +381,7 @@ expr_t::ptr_op_t python_module_t::lookup(const symbol_t::kind_t kind,
case symbol_t::FUNCTION:
DEBUG("python.interp", "Python lookup: " << name);
if (module_globals.has_key(name.c_str())) {
- if (python::object obj = module_globals.get(name.c_str())) {
+ if (object obj = module_globals.get(name.c_str())) {
if (PyModule_Check(obj.ptr())) {
shared_ptr<python_module_t> mod;
python_module_map_t::iterator i =
@@ -527,7 +528,7 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args)
arglist.append(convert_value_to_python(args.value()));
if (PyObject * val =
- PyObject_CallObject(func.ptr(), python::tuple(arglist).ptr())) {
+ PyObject_CallObject(func.ptr(), boost::python::tuple(arglist).ptr())) {
extract<value_t> xval(val);
value_t result;
if (xval.check()) {
diff --git a/src/pyinterp.h b/src/pyinterp.h
index 57fb176b..45bb7adb 100644
--- a/src/pyinterp.h
+++ b/src/pyinterp.h
@@ -52,19 +52,19 @@ namespace ledger {
class python_module_t : public scope_t, public noncopyable
{
public:
- string module_name;
- python::object module_object;
- python::dict module_globals;
+ string module_name;
+ boost::python::object module_object;
+ boost::python::dict module_globals;
explicit python_module_t(const string& name);
- explicit python_module_t(const string& name, python::object obj);
+ explicit python_module_t(const string& name, boost::python::object obj);
void import_module(const string& name, bool import_direct = false);
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
- void define_global(const string& name, python::object obj) {
+ void define_global(const string& name, boost::python::object obj) {
module_globals[name] = obj;
}
@@ -102,7 +102,7 @@ public:
void initialize();
void hack_system_paths();
- python::object import_option(const string& name);
+ boost::python::object import_option(const string& name);
enum py_eval_mode_t {
PY_EVAL_EXPR,
@@ -110,9 +110,9 @@ public:
PY_EVAL_MULTI
};
- python::object eval(std::istream& in, py_eval_mode_t mode = PY_EVAL_EXPR);
- python::object eval(const string& str, py_eval_mode_t mode = PY_EVAL_EXPR);
- python::object eval(const char * c_str, py_eval_mode_t mode = PY_EVAL_EXPR) {
+ boost::python::object eval(std::istream& in, py_eval_mode_t mode = PY_EVAL_EXPR);
+ boost::python::object eval(const string& str, py_eval_mode_t mode = PY_EVAL_EXPR);
+ boost::python::object eval(const char * c_str, py_eval_mode_t mode = PY_EVAL_EXPR) {
return eval(string(c_str), mode);
}
@@ -122,14 +122,14 @@ public:
functor_t();
protected:
- python::object func;
+ boost::python::object func;
public:
string name;
- functor_t(python::object _func, const string& _name)
+ functor_t(boost::python::object _func, const string& _name)
: func(_func), name(_name) {
- TRACE_CTOR(functor_t, "python::object, const string&");
+ TRACE_CTOR(functor_t, "boost::python::object, const string&");
}
functor_t(const functor_t& other)
: func(other.func), name(other.name) {
diff --git a/src/pyutils.h b/src/pyutils.h
index aa9c4451..c02be37b 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -39,6 +39,8 @@
*/
#pragma once
+namespace ledger { namespace python {
+
template <typename T, typename TfromPy>
struct object_from_python
{
@@ -142,6 +144,8 @@ PyObject * str_to_py_unicode(const T& str)
return object(handle<>(borrowed(uni))).ptr();
}
+} } // namespace ledger::python
+
namespace boost { namespace python {
// Use expr to create the PyObject corresponding to x
@@ -178,7 +182,7 @@ namespace boost { namespace python {
: handle<> \
{ \
arg_to_python(T const& x) \
- : python::handle<>(expr) {} \
+ : boost::python::handle<>(expr) {} \
}; \
}
diff --git a/src/textual.cc b/src/textual.cc
index 5276c92b..38142119 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -1257,7 +1257,7 @@ void instance_t::python_directive(char * line)
python_session->initialize();
python_session->main_module->define_global
- ("journal", python::object(python::ptr(context.journal)));
+ ("journal", boost::python::object(boost::python::ptr(context.journal)));
python_session->eval(script.str(), python_interpreter_t::PY_EVAL_MULTI);
}