From 6b25a1451bccec83fc1c003719431c62edcdadf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Tue, 8 Jul 2025 17:48:06 +0200 Subject: [PATCH] Update following move of IFileTree glob() and walk() to free function. --- src/mobase/wrappers/pyfiletree.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/mobase/wrappers/pyfiletree.cpp b/src/mobase/wrappers/pyfiletree.cpp index b9a477a..6dacf26 100644 --- a/src/mobase/wrappers/pyfiletree.cpp +++ b/src/mobase/wrappers/pyfiletree.cpp @@ -163,9 +163,11 @@ namespace mo2::python { .value("SKIP", IFileTree::WalkReturn::SKIP) .export_values(); - py::enum_(iFileTreeClass, "GlobPatternType") - .value("GLOB", IFileTree::GlobPatternType::GLOB) - .value("REGEX", IFileTree::GlobPatternType::REGEX) + // in C++ this is not an inner enum due to the conditional feature of glob(), + // but in Python this makes more sense as a inner enum + py::enum_(iFileTreeClass, "GlobPatternType") + .value("GLOB", GlobPatternType::GLOB) + .value("REGEX", GlobPatternType::REGEX) .export_values(); // Non-mutable operations: @@ -187,17 +189,21 @@ namespace mo2::python { QString>(&IFileTree::walk, py::const_), py::arg("callback"), py::arg("sep") = "\\"); - iFileTreeClass.def("walk", [](IFileTree const* tree) { - return make_generator(tree->walk()); + // the walk() and glob() generator version are free functions in C++ due to the + // conditional nature, but in Python, it makes more sense to have them as method + // of IFileTree directly + + iFileTreeClass.def("walk", [](std::shared_ptr tree) { + return make_generator(walk(tree)); }); iFileTreeClass.def( - "glob", // &IFileTree::glob, - [](IFileTree const* tree, QString pattern, - IFileTree::GlobPatternType patternType) { - return make_generator(tree->glob(pattern, patternType)); + "glob", + [](std::shared_ptr tree, QString pattern, + GlobPatternType patternType) { + return make_generator(glob(tree, pattern, patternType)); }, - py::arg("pattern"), py::arg("type") = IFileTree::GlobPatternType::GLOB); + py::arg("pattern"), py::arg("type") = GlobPatternType::GLOB); // Kind-of-static operations: iFileTreeClass.def("createOrphanTree", &IFileTree::createOrphanTree,