parameters: (args)
docstring: Extract all docstrings and write header.
docstring_summary: Extract all docstrings and write header.
docstring_tokens: Extract all docstrings and write header .
function: def extract_docstrings(args):
      """
      Extract all docstrings and write header.
      """
      start = time.time()
      xml_count = 0
      names = set()
      docs = []
  
      logger.info(
          "Extracting docstrings from Doxygen XML: {path}".format(
              path=args.xmldir
          )
      )
  
      # Walk doxygen XML files for docstrings
      for filename in os.listdir(args.xmldir):
          if os.path.splitext(filename)[1] == ".xml":
              xml_count += 1
              logger.info("Processing file: {path}".format(path=filename))
  
              tree = ET.parse(os.path.join(args.xmldir, filename))
              root = tree.getroot()
              
              # Compound object/namespace
              for compounddef_elem in root.iter("compounddef"):
                  if compounddef_elem.attrib["kind"] not in KINDS_COMPOUND:
                      continue
  
                  compound_name = compounddef_elem.find("compoundname").text
                  if "::" not in compound_name:
                      # Generalize OCIO namespace
                      compound_name = "PyOpenColorIO"
                      
                  compound_full_name = compound_name.split("::")[-1]
                  compound_doc = render_docstring(
                      compounddef_elem,
                      compound_full_name,
                      names
                  )
                  docs.append(compound_doc)
  
                  # Compound member
                  for memberdef_elem in compounddef_elem.iter("memberdef"):
                      if memberdef_elem.attrib["kind"] not in KINDS_MEMBER:
                          continue
  
                      member_name = memberdef_elem.find("name").text
                      if (compound_name == "PyOpenColorIO" and
                              "operator" in member_name):
                          # Insert return type to distinguish OCIO namespace 
                          # operators. Argument types may be needed in the 
                          # future as well.
                          member_name = "_".join([
                              memberdef_elem.find("type").text, 
                              member_name
                          ])
  
                      member_full_name = "{compound}_{member}".format(
                          compound=compound_full_name, 
                          member=member_name
                      )
                      member_doc = render_docstring(
                          memberdef_elem,
                          member_full_name,
                          names
                      )
                      docs.append(member_doc)
  
                      # Enum value
                      for enumvalue_elem in memberdef_elem.iter("enumvalue"):
                          value_name = enumvalue_elem.find("name").text
  
                          value_full_name = "{member}_{value}".format(
                              member=member_full_name,
                              value=value_name
                          )
                          enumvalue_doc = render_docstring(
                              enumvalue_elem,
                              value_full_name,
                              names
                          )
                          docs.append(enumvalue_doc)
  
      # Write docstring header
      logger.info("Writing docstring header: {path}".format(path=args.header))
      with open(args.header, "w", encoding="utf-8") as header_file:
          header_file.write(HEADER_TEMPLATE.format(docs="\n\n".join(docs)))
  
      logger.info(
          "{doc_count:d} docstrings extracted from {xml_count:d} XML files in "
          "{duration:.2f} seconds".format(
              doc_count=len(docs),
              xml_count=xml_count,
              duration=time.time() - start
          )
      )
function_tokens: def extract_docstrings ( args ) : start = time . time ( ) xml_count = 0 names = set ( ) docs = [ ] logger . info ( "Extracting docstrings from Doxygen XML: {path}" . format ( path = args . xmldir ) ) # Walk doxygen XML files for docstrings for filename in os . listdir ( args . xmldir ) : if os . path . splitext ( filename ) [ 1 ] == ".xml" : xml_count += 1 logger . info ( "Processing file: {path}" . format ( path = filename ) ) tree = ET . parse ( os . path . join ( args . xmldir , filename ) ) root = tree . getroot ( ) # Compound object/namespace for compounddef_elem in root . iter ( "compounddef" ) : if compounddef_elem . attrib [ "kind" ] not in KINDS_COMPOUND : continue compound_name = compounddef_elem . find ( "compoundname" ) . text if "::" not in compound_name : # Generalize OCIO namespace compound_name = "PyOpenColorIO" compound_full_name = compound_name . split ( "::" ) [ - 1 ] compound_doc = render_docstring ( compounddef_elem , compound_full_name , names ) docs . append ( compound_doc ) # Compound member for memberdef_elem in compounddef_elem . iter ( "memberdef" ) : if memberdef_elem . attrib [ "kind" ] not in KINDS_MEMBER : continue member_name = memberdef_elem . find ( "name" ) . text if ( compound_name == "PyOpenColorIO" and "operator" in member_name ) : # Insert return type to distinguish OCIO namespace  # operators. Argument types may be needed in the  # future as well. member_name = "_" . join ( [ memberdef_elem . find ( "type" ) . text , member_name ] ) member_full_name = "{compound}_{member}" . format ( compound = compound_full_name , member = member_name ) member_doc = render_docstring ( memberdef_elem , member_full_name , names ) docs . append ( member_doc ) # Enum value for enumvalue_elem in memberdef_elem . iter ( "enumvalue" ) : value_name = enumvalue_elem . find ( "name" ) . text value_full_name = "{member}_{value}" . format ( member = member_full_name , value = value_name ) enumvalue_doc = render_docstring ( enumvalue_elem , value_full_name , names ) docs . append ( enumvalue_doc ) # Write docstring header logger . info ( "Writing docstring header: {path}" . format ( path = args . header ) ) with open ( args . header , "w" , encoding = "utf-8" ) as header_file : header_file . write ( HEADER_TEMPLATE . format ( docs = "\n\n" . join ( docs ) ) ) logger . info ( "{doc_count:d} docstrings extracted from {xml_count:d} XML files in " "{duration:.2f} seconds" . format ( doc_count = len ( docs ) , xml_count = xml_count , duration = time . time ( ) - start ) )