Browse Source

python: handle Windows paths in trade.AbstractSceneConverter.begin_file().

Consistently with convert_to_file() and other APIs elsewhere.
next
Vladimír Vondruš 3 years ago
parent
commit
52fe802932
  1. 5
      doc/python/magnum.trade.rst
  2. 11
      src/python/magnum/trade.cpp

5
doc/python/magnum.trade.rst

@ -523,6 +523,11 @@
.. py:function:: magnum.trade.AbstractSceneConverter.begin_file
:raise RuntimeError: If beginning the conversion fails
For compatibility with :ref:`os.path`, on Windows this function converts
all backslashes in :p:`filename` to forward slashes before passing it to
:dox:`Trade::AbstractSceneConverter::beginFike()`, which expects forward
slashes as directory separators on all platforms.
.. py:function:: magnum.trade.AbstractSceneConverter.end_file
:raise AssertionError: If no conversion is in progress
:raise RuntimeError: If ending the conversion fails

11
src/python/magnum/trade.cpp

@ -1712,7 +1712,16 @@ void trade(py::module_& m) {
/** @todo begin/end (MeshOptimizer), begin/end data */
/** @todo drop std::string in favor of our own string caster */
.def("begin_file", [](Trade::AbstractSceneConverter& self, const std::string& filename) {
if(!self.beginFile(filename)) {
if(!self.beginFile(
#ifdef CORRADE_TARGET_WINDOWS
/* To allow people to conveniently use Python's os.path, we
need to convert backslashes to forward slashes as all
Corrade and Magnum APIs expect forward */
Utility::Path::fromNativeSeparators(filename)
#else
filename
#endif
)) {
PyErr_SetString(PyExc_RuntimeError, "beginning the conversion failed");
throw py::error_already_set{};
}

Loading…
Cancel
Save