<commit_before>#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <iostream>

#include "nifty/python/converter.hxx"

namespace py = pybind11;



namespace nifty{
namespace graph{
    void initSubmoduleGraph(py::module & );
}
namespace tools{
    void initSubmoduleTools(py::module &);
}
#ifdef WITH_HDF5
namespace hdf5{
    void initSubmoduleHdf5(py::module & );
}
#endif
}

PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);


struct Configuration{

};


PYBIND11_PLUGIN(_nifty) {
    py::module niftyModule("_nifty", "nifty python bindings");

    using namespace nifty;



    //graph::initSubmoduleGraph(niftyModule);
    tools::initSubmoduleTools(niftyModule);

    #ifdef WITH_HDF5
    hdf5::initSubmoduleHdf5(niftyModule);
    #endif
<commit_msg>python: Register a translator for Gurobi exceptions so they can be shown in Python.<commit_after>#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <sstream>

#include "nifty/python/converter.hxx"

namespace py = pybind11;

#ifdef WITH_GUROBI
    #include <gurobi_c++.h>
#endif

namespace nifty{
namespace graph{
    void initSubmoduleGraph(py::module & );
}
namespace tools{
    void initSubmoduleTools(py::module &);
}
#ifdef WITH_HDF5
namespace hdf5{
    void initSubmoduleHdf5(py::module & );
}
#endif
}

PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);


struct Configuration{

};


PYBIND11_PLUGIN(_nifty) {
    py::module niftyModule("_nifty", "nifty python bindings");

    using namespace nifty;



    //graph::initSubmoduleGraph(niftyModule);
    tools::initSubmoduleTools(niftyModule);

    #ifdef WITH_HDF5
    hdf5::initSubmoduleHdf5(niftyModule);
    #endif

    #ifdef WITH_GUROBI
        // Translate Gurobi exceptions to Python exceptions
        // (Must do this explicitly since GRBException doesn't inherit from std::exception)
        static py::exception<GRBException> exc(niftyModule, "GRBException");
        py::register_exception_translator([](std::exception_ptr p) {
            try {
                if (p) std::rethrow_exception(p);
            } catch (const GRBException &e) {
                std::ostringstream ss;
                ss << e.getMessage() << " (Error code:" << e.getErrorCode() << ")";
                exc(ss.str().c_str());
            }
        });
    #endif

{'fraction_non_alphanumeric': 0.12342459800086919, 'fraction_numerical': 0.01564537157757497, 'mean_word_length': 3.756198347107438, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2726537', 'n_tokens_mistral': 830, 'n_tokens_neox': 794, 'n_words': 153}