44(Docs WIP).
55"""
66
7-
87import argparse
98import os
109import re
11- import shlex
12- import sys
13-
14- from .mkdoc_lib import mkdoc
1510
11+ from pybind11_mkdoc .mkdoc_lib import mkdoc
1612
1713__version__ = "2.6.2.dev1"
1814
1915
20- def _append_include_dir (args : list , include_dir : str , verbose : bool = True ):
16+ def _append_include_dir (args : list , include_dir : str , * , verbose : bool = True ):
2117 """
2218 Add an include directory to an argument list (if it exists).
2319
@@ -37,10 +33,10 @@ def _append_include_dir(args: list, include_dir: str, verbose: bool = True):
3733 if os .path .isdir (include_dir ):
3834 args .append (f"-I{ include_dir } " )
3935 elif verbose :
40- print ( f"Include directory { include_dir !r } does not exist!" )
36+ pass
4137
4238
43- def _append_definition (args : list , definition : str , verbose : bool = True ):
39+ def _append_definition (args : list , definition : str ):
4440 """
4541 Add a compiler definition to an argument list.
4642
@@ -61,21 +57,20 @@ def _append_definition(args: list, definition: str, verbose: bool = True):
6157 """
6258
6359 try :
64- macro , _ , value = definition .partition ('=' )
60+ macro , _ , value = definition .partition ("=" )
6561 macro = macro .strip ()
66- value = value .strip () if value else '1'
62+ value = value .strip () if value else "1"
6763
6864 args .append (f"-D{ macro } ={ value } " )
69- except ValueError as exc :
65+ except ValueError :
7066 # most likely means there was no '=' given
7167 # check if argument is valid identifier
72- if re .search (r' ^[A-Za-z_][A-Za-z0-9_]*' , definition ):
68+ if re .search (r" ^[A-Za-z_][A-Za-z0-9_]*" , definition ):
7369 args .append (f"-D{ definition } " )
7470 else :
75- print (f"Failed to parse definition: { definition } " )
76- except :
77- print (f"Failed to parse definition: { definition } " )
78-
71+ pass
72+ except Exception :
73+ pass
7974
8075
8176def main ():
@@ -86,26 +81,53 @@ def main():
8681 """
8782
8883 parser = argparse .ArgumentParser (
89- prog = 'pybind11_mkdoc' ,
90- description = "Processes a sequence of C/C++ headers and extracts comments for use in pybind11 binding code." ,
91- epilog = "(Other compiler flags that Clang understands can also be supplied)" ,
92- allow_abbrev = False )
84+ prog = "pybind11_mkdoc" ,
85+ description = "Processes a sequence of C/C++ headers and extracts comments for use in pybind11 binding code." ,
86+ epilog = "(Other compiler flags that Clang understands can also be supplied)" ,
87+ allow_abbrev = False ,
88+ )
9389
9490 parser .add_argument ("-v" , "--version" , action = "version" , version = f"%(prog)s { __version__ } " )
9591
96- parser .add_argument ("-o" , "--output" , action = "store" , type = str , dest = "output" , metavar = "<file>" ,
97- help = "Write to the specified file (default: use stdout)." )
98-
99- parser .add_argument ("-w" , "--width" , action = "store" , type = int , dest = "width" , metavar = "<width>" ,
100- help = "Specify docstring width before wrapping." )
101-
102- parser .add_argument ("-I" , action = "append" , type = str , dest = "include_dirs" , metavar = "<dir>" ,
103- help = "Specify an directory to add to the list of include search paths." )
104-
105- parser .add_argument ("-D" , action = "append" , type = str , metavar = "<macro>=<value>" , dest = "definitions" ,
106- help = "Specify a compiler definition, i.e. define <macro> to <value> (or 1 if <value> omitted)." )
107-
108- parser .add_argument ("header" , type = str , nargs = '+' , help = "A header file to process." )
92+ parser .add_argument (
93+ "-o" ,
94+ "--output" ,
95+ action = "store" ,
96+ type = str ,
97+ dest = "output" ,
98+ metavar = "<file>" ,
99+ help = "Write to the specified file (default: use stdout)." ,
100+ )
101+
102+ parser .add_argument (
103+ "-w" ,
104+ "--width" ,
105+ action = "store" ,
106+ type = int ,
107+ dest = "width" ,
108+ metavar = "<width>" ,
109+ help = "Specify docstring width before wrapping." ,
110+ )
111+
112+ parser .add_argument (
113+ "-I" ,
114+ action = "append" ,
115+ type = str ,
116+ dest = "include_dirs" ,
117+ metavar = "<dir>" ,
118+ help = "Specify an directory to add to the list of include search paths." ,
119+ )
120+
121+ parser .add_argument (
122+ "-D" ,
123+ action = "append" ,
124+ type = str ,
125+ metavar = "<macro>=<value>" ,
126+ dest = "definitions" ,
127+ help = "Specify a compiler definition, i.e. define <macro> to <value> (or 1 if <value> omitted)." ,
128+ )
129+
130+ parser .add_argument ("header" , type = str , nargs = "+" , help = "A header file to process." )
109131
110132 [parsed_args , unparsed_args ] = parser .parse_known_args ()
111133
@@ -130,8 +152,7 @@ def main():
130152 # append argument as is and hope for the best
131153 mkdoc_args .append (arg )
132154
133- for header in parsed_args .header :
134- mkdoc_args .append (header )
155+ mkdoc_args .extend (header for header in parsed_args .header )
135156
136157 mkdoc (mkdoc_args , docstring_width , mkdoc_out )
137158
0 commit comments