Generate a viable PXD file
(self, dfile, internal_file_name, xml_output_path)
| 367 | return empty |
| 368 | |
| 369 | def get_pxd_from_class(self, dfile, internal_file_name, xml_output_path): |
| 370 | """ |
| 371 | Generate a viable PXD file |
| 372 | """ |
| 373 | |
| 374 | compound = dfile.compound |
| 375 | comp_name = compound.get_compoundname() |
| 376 | |
| 377 | # |
| 378 | # Step 1: generate cimport includes |
| 379 | # |
| 380 | includes = "" |
| 381 | if len(compound.get_includes()) == 1: |
| 382 | try: |
| 383 | reffile = os.path.join(xml_output_path, compound.get_includes()[0].get_refid() + ".xml") |
| 384 | # read includes from ref file |
| 385 | dreffile = DoxygenXMLFile(reffile).parse_doxygen() |
| 386 | include_compound = dreffile.get_compounddef() |
| 387 | except Exception as e: |
| 388 | print ("Error: Could not read includes from file for compound %s with error %s" % (comp_name, e.message)) |
| 389 | include_compound = compound |
| 390 | else: |
| 391 | include_compound = compound |
| 392 | |
| 393 | for inc in include_compound.get_includes(): |
| 394 | val = inc.getValueOf_() |
| 395 | if val.startswith("OpenMS"): |
| 396 | header_file = val.split("/")[-1] |
| 397 | if header_file.endswith(".h"): |
| 398 | header_file = header_file[:-2] |
| 399 | # We do not import certain headers since we did not wrap them in Python |
| 400 | if header_file in ["Exception", "Macros", "config", "StandardTypes"]: |
| 401 | continue |
| 402 | includes += "from %s cimport *\n" % header_file |
| 403 | |
| 404 | # |
| 405 | # Step 2: class definition |
| 406 | # |
| 407 | parent_classes = [n.getValueOf_() for n in compound.basecompoundref] |
| 408 | namespace = "::".join(comp_name.split("::")[:-1]) |
| 409 | preferred_classname = "_".join(comp_name.split("::")[1:]) |
| 410 | preferred_classname = comp_name.split("::")[-1] |
| 411 | cldef = "\n" |
| 412 | cldef += 'cdef extern from "<%s>" namespace "%s":\n' % (internal_file_name, namespace) |
| 413 | cldef += "\n" |
| 414 | |
| 415 | inherit_txt = "" |
| 416 | true_cppname = '"%s"' % comp_name |
| 417 | if len(parent_classes) > 0: |
| 418 | inherit_txt = "(%s)" % ",".join(parent_classes) |
| 419 | true_cppname = '' # Cython does not accept this if mixed with inheritance |
| 420 | |
| 421 | if compound.templateparamlist is None: |
| 422 | cldef += ' cdef cppclass %s%s %s:\n' % (preferred_classname, inherit_txt, true_cppname) |
| 423 | else: |
| 424 | targs = [p.get_declname() for p in compound.templateparamlist.get_param()] |
| 425 | cldef += ' cdef cppclass %s[%s]%s:\n' % (preferred_classname, ",".join(targs), inherit_txt) |
| 426 | cldef += ' #\n' |
no test coverage detected