diff --git a/doc/python/conf.py b/doc/python/conf.py index 2c7a475..63123f9 100644 --- a/doc/python/conf.py +++ b/doc/python/conf.py @@ -58,14 +58,6 @@ magnum.TARGET_WEBGL = DoNotPrintValue() magnum.TARGET_EGL = DoNotPrintValue() magnum.TARGET_VK = DoNotPrintValue() -# Otherwise it blows during doc generation up because there's no content -# TODO is there a way to make Python not execute the property when inspecting -# it?! -# TODO also, it's a static property together with has_current, and as such it -# has no docstring -- fix -delattr(magnum.gl.Context, 'current') -setattr(magnum.gl.Context, 'current', DoNotPrintValue()) - # TODO ugh... can this be expressed directly in pybind? and the docs parsed # from it so i don't need to repeat them in docs/*.rst files? for i in [magnum.text.AbstractFont, diff --git a/src/python/magnum/gl.cpp b/src/python/magnum/gl.cpp index 998b9a5..a9e6ae0 100644 --- a/src/python/magnum/gl.cpp +++ b/src/python/magnum/gl.cpp @@ -373,21 +373,27 @@ void gl(py::module_& m) { .def_property_readonly_static("has_current", [](const py::object&) { return GL::Context::hasCurrent(); }, "Whether there is any current context") - .def_property_readonly_static("current", [](const py::object&) { - if(!GL::Context::hasCurrent()) { - PyErr_SetString(PyExc_RuntimeError, "no current context"); - throw py::error_already_set{}; - } - - py::object owner = py::none{}; - auto* glContextOwner = reinterpret_cast*>(py::get_shared_data("magnumGLContextOwner")); - if(glContextOwner && glContextOwner->first) { - CORRADE_INTERNAL_ASSERT(glContextOwner->second); - owner = Corrade::pyObjectFromInstance(glContextOwner->first, *glContextOwner->second); - } - - return ContextHolder{&GL::Context::current(), std::move(owner)}; - }, "Current context") + .def_property_readonly_static("current", + std::getenv("MCSS_GENERATING_OUTPUT") ? + [](const py::object&) { + return ContextHolder{nullptr}; + } : + [](const py::object&) { + if(!GL::Context::hasCurrent()) { + PyErr_SetString(PyExc_RuntimeError, "no current context"); + throw py::error_already_set{}; + } + + py::object owner = py::none{}; + auto* glContextOwner = reinterpret_cast*>(py::get_shared_data("magnumGLContextOwner")); + if(glContextOwner && glContextOwner->first) { + CORRADE_INTERNAL_ASSERT(glContextOwner->second); + owner = Corrade::pyObjectFromInstance(glContextOwner->first, *glContextOwner->second); + } + + return ContextHolder{&GL::Context::current(), std::move(owner)}; + } + , "Current context") /** @todo context switching (needs additions to the "who owns current context instance" variable -- a map?) */ .def_property_readonly("version", &GL::Context::version, "OpenGL version")