Skip to content

Commit

Permalink
fix two previous commits and rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Oct 2, 2024
1 parent c8755d8 commit 0347eb1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ if (USE_PYTHON)
PYTHON_PATH py
DEPENDS gemmi_py
PATTERN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/python/stubs.pat"
MARKER_FILE py.typed
MARKER_FILE py/gemmi/py.typed
)
nanobind_add_stub(
gemmi_cif_stub
Expand Down Expand Up @@ -603,9 +603,10 @@ if (USE_PYTHON)
PATTERN "[._]*" EXCLUDE)
if (GENERATE_STUBS AND NOT CMAKE_CROSSCOMPILING)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/py/py.typed"
"${CMAKE_CURRENT_BINARY_DIR}/py/__init__.pyi"
"${CMAKE_CURRENT_BINARY_DIR}/py/cif.pyi"
"${CMAKE_CURRENT_BINARY_DIR}/py/gemmi/__init__.py"
"${CMAKE_CURRENT_BINARY_DIR}/py/gemmi/py.typed"
"${CMAKE_CURRENT_BINARY_DIR}/py/gemmi/__init__.pyi"
"${CMAKE_CURRENT_BINARY_DIR}/py/gemmi/cif.pyi"
DESTINATION "${Python_SITEARCH}/gemmi" COMPONENT py)
endif()
endif()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sdist.include = [
"python/*.cpp",
"python/*.h*",
"python/stubs.pat",
"python/gemmi/__init__.py",
"third_party/README",
"third_party/*.h",
"third_party/zlib/*",
Expand Down
62 changes: 32 additions & 30 deletions python/gemmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ void add_misc(nb::module_& m) {
}, nb::arg("nbins"), nb::arg("obs"), nb::arg("calc"));
}

NB_MODULE(_gemmi, mg_) {
nb::module_ mg = nb::module_::import_("gemmi");
mg.doc() = "Python bindings to GEMMI - a library used in macromolecular\n"
NB_MODULE(_gemmi, m_) {
// unusual setup: importing gemmi._gemmi adds classes and functions to gemmi
(void) m_;
nb::module_ m = nb::module_::import_("gemmi");
m.doc() = "Python bindings to GEMMI - a library used in macromolecular\n"
"crystallography and related fields";
mg.attr("__version__") = GEMMI_VERSION;
m.attr("__version__") = GEMMI_VERSION;

nb::register_exception_translator([](const std::exception_ptr& p, void*) {
try {
Expand All @@ -171,30 +173,30 @@ NB_MODULE(_gemmi, mg_) {
}
});

nb::module_ cif = mg.def_submodule("cif", "CIF file format");
add_cif(cif);
add_symmetry(mg);
add_unitcell(mg);
add_elem(mg);
add_meta(mg);
add_mol(mg);
add_small(mg);
add_misc(mg);
add_grid(mg);
add_recgrid(mg);
add_ccp4(mg);
add_sf(mg);
add_cif_read(cif);
add_mtz(mg);
add_hkl(mg);
add_chemcomp(mg);
add_monlib(mg);
add_topo(mg);
add_alignment(mg);
add_search(mg);
add_read_structure(mg);
add_scaling(mg);
add_custom(mg);

mg.def("set_leak_warnings", nb::set_leak_warnings);
nb::module_ mcif = m.def_submodule("cif", "CIF file format");
add_cif(mcif);
add_symmetry(m);
add_unitcell(m);
add_elem(m);
add_meta(m);
add_mol(m);
add_small(m);
add_misc(m);
add_grid(m);
add_recgrid(m);
add_ccp4(m);
add_sf(m);
add_cif_read(mcif);
add_mtz(m);
add_hkl(m);
add_chemcomp(m);
add_monlib(m);
add_topo(m);
add_alignment(m);
add_search(m);
add_read_structure(m);
add_scaling(m);
add_custom(m);

m.def("set_leak_warnings", nb::set_leak_warnings);
}

0 comments on commit 0347eb1

Please sign in to comment.