Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
extract_docstrings.py
Go to the documentation of this file.
1#-------------------------------------------------------------------------------
2# Author: Enric Tejedor <enric.tejedor.saavedra@cern.ch> CERN
3#-------------------------------------------------------------------------------
4
5################################################################################
6# Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. #
7# All rights reserved. #
8# #
9# For the licensing terms see $ROOTSYS/LICENSE. #
10# For the list of contributors see $ROOTSYS/README/CREDITS. #
11################################################################################
12
13# Code that extracts the docstrings from pythonization files and stores them
14# in .pyzdoc files, so that doxygen can process them later to merge the
15# documentation they contain with that of C++ files
16
17import ast
18import sys
19from os import path, walk
20
21if len(sys.argv) < 2:
22 print("Please provide the directory where documented .py files are.")
23 exit(1)
24
25pyz_dir = sys.argv[1]
26
27(_, _, filenames) = next(walk(pyz_dir))
28
29# Iterate over pythonization files
30for pyz_file in filenames:
31 if not pyz_file.endswith('.py'):
32 continue
33
34 pyz_file_path = pyz_dir + path.sep + pyz_file
35 with open(pyz_file_path) as fd:
36 file_contents = fd.read()
37
38 # Docs for pythonizations are provided as a module-level docstring
39 module = ast.parse(file_contents)
40 ds = ast.get_docstring(module)
41 if ds is not None:
42 with open(pyz_file_path + '.pyzdoc', 'w') as pyz_doc_file:
43 pyz_doc_file.write(ds)
44