Skip to content

Commit

Permalink
python: replace Ddl.read_ddl_file(path) with Ddl.read_ddl(doc)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Jan 6, 2025
1 parent 8abf494 commit 1957ffb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/gemmi/ddl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct GEMMI_DLL Ddl {
Ddl(Ddl const&) = delete;
Ddl& operator=(Ddl const&) = delete;

/// it moves doc to ddl_docs_ to control lifetime and prevent modifications
void read_ddl(cif::Document&& doc);

bool validate_cif(const cif::Document& doc) const;
Expand Down
7 changes: 4 additions & 3 deletions python/cif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ void add_cif(nb::module_& cif) {
nb::arg("use_context")=true, nb::arg("use_linked_groups")=true,
nb::arg("use_mandatory")=true, nb::arg("use_unique_keys")=true)
.def("set_logger", [](Ddl& self, gemmi::Logger&& logger) { self.logger = std::move(logger); })
.def("read_ddl_file", [](Ddl& self, const std::string& path) {
self.read_ddl(gemmi::read_cif_gz(path));
}, nb::arg("path"))
.def("read_ddl", [](Ddl& self, Document& doc) {
self.read_ddl(std::move(doc));
doc.clear();
}, nb::arg("doc"))
.def("validate_cif", &Ddl::validate_cif)
;
}
8 changes: 5 additions & 3 deletions tests/test_cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,11 @@ def test_validation(self):
""")
msg_list = []
ddl = cif.Ddl(logger=(lambda msg: msg_list.append(msg), 6))
ddl.read_ddl_file(full_path('mmcif_pdbx_v50_frag.dic'))
self.assertTrue(len(msg_list) == 1)
self.assertTrue(msg_list[0].startswith("Bad DDL2: can't parse regex"))
ddl.read_ddl(cif.read(full_path('mmcif_pdbx_v50_frag.dic')))
if msg_list:
# regex for type binary may result in regex_error
self.assertEqual(len(msg_list), 1)
self.assertTrue(msg_list[0].startswith("Bad DDL2: can't parse regex"))
msg_list = []
ddl.validate_cif(doc)
self.assertEqual(msg_list,
Expand Down

0 comments on commit 1957ffb

Please sign in to comment.