Skip to content

Commit

Permalink
Maybe make the bindings properly this time
Browse files Browse the repository at this point in the history
  • Loading branch information
xchang1 committed Dec 4, 2024
1 parent 0a68c99 commit 645f0f2
Show file tree
Hide file tree
Showing 30 changed files with 3,019 additions and 2,779 deletions.
20 changes: 16 additions & 4 deletions bdsg/cmake_bindings/bdsg.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
#include <stdexcept>
#include <functional>
#include <string>

#include <pybind11/pybind11.h>
Expand All @@ -20,11 +21,12 @@ void bind_bdsg_graph_proxy_1(std::function< pybind11::module &(std::string const
void bind_bdsg_internal_wang_hash(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_mapped_structs(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_mapped_structs_1(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_utility(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_hash_map(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_handlegraph_expanding_overlay_graph(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_strand_split_overlay(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_is_single_stranded(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_eades_algorithm(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_internal_base_packed_graph(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_handlegraph_path_position_handle_graph(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_packed_path_position_overlay(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_packed_path_position_overlay_1(std::function< pybind11::module &(std::string const &namespace_) > &M);
Expand All @@ -49,13 +51,22 @@ PYBIND11_MODULE(bdsg, root_module) {

modules[""] = root_module;

static std::vector<std::string> const reserved_python_words {"nonlocal", "global", };

auto mangle_namespace_name(
[](std::string const &ns) -> std::string {
if ( std::find(reserved_python_words.begin(), reserved_python_words.end(), ns) == reserved_python_words.end() ) return ns;
else return ns+'_';
}
);

std::vector< std::pair<std::string, std::string> > sub_modules {
{"", "bdsg"},
{"bdsg", "algorithms"},
{"", "handlegraph"},
{"", "std"},
};
for(auto &p : sub_modules ) modules[p.first.size() ? p.first+"::"+p.second : p.second] = modules[p.first].def_submodule(p.second.c_str(), ("Bindings for " + p.first + "::" + p.second + " namespace").c_str() );
for(auto &p : sub_modules ) modules[p.first.size() ? p.first+"::"+p.second : p.second] = modules[p.first].def_submodule( mangle_namespace_name(p.second).c_str(), ("Bindings for " + p.first + "::" + p.second + " namespace").c_str() );

//pybind11::class_<std::shared_ptr<void>>(M(""), "_encapsulated_data_");

Expand All @@ -71,11 +82,12 @@ PYBIND11_MODULE(bdsg, root_module) {
bind_bdsg_internal_wang_hash(M);
bind_bdsg_internal_mapped_structs(M);
bind_bdsg_internal_mapped_structs_1(M);
bind_bdsg_internal_utility(M);
bind_bdsg_internal_hash_map(M);
bind_handlegraph_expanding_overlay_graph(M);
bind_bdsg_overlays_strand_split_overlay(M);
bind_bdsg_internal_is_single_stranded(M);
bind_bdsg_internal_eades_algorithm(M);
bind_bdsg_internal_base_packed_graph(M);
bind_handlegraph_path_position_handle_graph(M);
bind_bdsg_overlays_packed_path_position_overlay(M);
bind_bdsg_overlays_packed_path_position_overlay_1(M);
Expand Down
3 changes: 2 additions & 1 deletion bdsg/cmake_bindings/bdsg.sources
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ bdsg/graph_proxy_1.cpp
bdsg/internal/wang_hash.cpp
bdsg/internal/mapped_structs.cpp
bdsg/internal/mapped_structs_1.cpp
bdsg/internal/utility.cpp
bdsg/internal/hash_map.cpp
handlegraph/expanding_overlay_graph.cpp
bdsg/overlays/strand_split_overlay.cpp
bdsg/internal/is_single_stranded.cpp
bdsg/internal/eades_algorithm.cpp
bdsg/internal/base_packed_graph.cpp
handlegraph/path_position_handle_graph.cpp
bdsg/overlays/packed_path_position_overlay.cpp
bdsg/overlays/packed_path_position_overlay_1.cpp
Expand Down
8 changes: 4 additions & 4 deletions bdsg/cmake_bindings/bdsg/graph_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <utility>
#include <vector>

#include <pybind11/pybind11.h>
#include <functional>
#include <pybind11/pybind11.h>
#include <string>
#include <bdsg/internal/binder_hook_compile.hpp>
#include <pybind11/stl.h>
Expand All @@ -31,9 +31,9 @@

#ifndef BINDER_PYBIND11_TYPE_CASTER
#define BINDER_PYBIND11_TYPE_CASTER
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
PYBIND11_DECLARE_HOLDER_TYPE(T, T*);
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>);
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, T*)
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
#endif

void bind_bdsg_graph_proxy(std::function< pybind11::module &(std::string const &namespace_) > &M)
Expand Down
8 changes: 4 additions & 4 deletions bdsg/cmake_bindings/bdsg/graph_proxy_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <utility>
#include <vector>

#include <pybind11/pybind11.h>
#include <functional>
#include <pybind11/pybind11.h>
#include <string>
#include <bdsg/internal/binder_hook_compile.hpp>
#include <pybind11/stl.h>
Expand All @@ -30,9 +30,9 @@

#ifndef BINDER_PYBIND11_TYPE_CASTER
#define BINDER_PYBIND11_TYPE_CASTER
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
PYBIND11_DECLARE_HOLDER_TYPE(T, T*);
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>);
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, T*)
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
#endif

void bind_bdsg_graph_proxy_1(std::function< pybind11::module &(std::string const &namespace_) > &M)
Expand Down
Loading

0 comments on commit 645f0f2

Please sign in to comment.