diff --git a/python/include/pythontarget.h b/python/include/pythontarget.h index effbe0344..a828e0689 100644 --- a/python/include/pythontarget.h +++ b/python/include/pythontarget.h @@ -102,6 +102,22 @@ PyObject* py_schedule_copy(PyObject* self, PyObject* args); */ PyObject* py_request_stop(PyObject* self, PyObject* args); +/** + * @brief Return the source directory path (where the main .lf file is) as a string. + * @param self The lf object. + * @param args Empty. + * @return PyObject* A Python string. + */ +PyObject* py_source_directory(PyObject* self, PyObject* args); + +/** + * @brief Return the root project directory path as a string. + * @param self The lf object. + * @param args Empty. + * @return PyObject* A Python string. + */ +PyObject* py_package_directory(PyObject* self, PyObject* args); + ////////////////////////////////////////////////////////////// ///////////// Main function callable from Python code PyObject* py_main(PyObject* self, PyObject* args); diff --git a/python/lib/pythontarget.c b/python/lib/pythontarget.c index a485efaf5..3a3e7b2b4 100644 --- a/python/lib/pythontarget.c +++ b/python/lib/pythontarget.c @@ -162,6 +162,26 @@ PyObject* py_request_stop(PyObject* self, PyObject* args) { return Py_None; } +PyObject* py_source_directory(PyObject* self, PyObject* args) { +#ifndef LF_SOURCE_DIRECTORY + // This should not occur. + PyErr_SetString(PyExc_RuntimeError, "LF_SOURCE_DIRECTORY constant is not defined."); + return NULL; +#else + return PyUnicode_DecodeFSDefault(LF_SOURCE_DIRECTORY); +#endif +} + +PyObject* py_package_directory(PyObject* self, PyObject* args) { +#ifndef LF_PACKAGE_DIRECTORY + // This should not occur. + PyErr_SetString(PyExc_RuntimeError, "LF_PACKAGE_DIRECTORY constant is not defined."); + return NULL; +#else + return PyUnicode_DecodeFSDefault(LF_PACKAGE_DIRECTORY); +#endif +} + /** * Parse Python's 'argv' (from sys.argv()) into a pair of C-style * 'argc' (the size of command-line parameters array) @@ -299,12 +319,15 @@ PyObject* py_main(PyObject* self, PyObject* py_args) { * @see schedule_copy * @see request_stop */ -static PyMethodDef GEN_NAME(MODULE_NAME, _methods)[] = {{"start", py_main, METH_VARARGS, NULL}, - {"schedule_copy", py_schedule_copy, METH_VARARGS, NULL}, - {"tag", py_lf_tag, METH_NOARGS, NULL}, - {"tag_compare", py_tag_compare, METH_VARARGS, NULL}, - {"request_stop", py_request_stop, METH_NOARGS, "Request stop"}, - {NULL, NULL, 0, NULL}}; +static PyMethodDef GEN_NAME(MODULE_NAME, _methods)[] = { + {"start", py_main, METH_VARARGS, NULL}, + {"schedule_copy", py_schedule_copy, METH_VARARGS, NULL}, + {"tag", py_lf_tag, METH_NOARGS, NULL}, + {"tag_compare", py_tag_compare, METH_VARARGS, NULL}, + {"request_stop", py_request_stop, METH_NOARGS, "Request stop"}, + {"source_directory", py_source_directory, METH_NOARGS, "Source directory path for .lf file"}, + {"package_directory", py_package_directory, METH_NOARGS, "Root package directory path"}, + {NULL, NULL, 0, NULL}}; /** * Define the Lingua Franca module.