44(Docs WIP).
55"""
66
7-
87import argparse
98import os
109import re
1110import shlex
12- import sys
13-
14- from .mkdoc_lib import mkdoc
1511
12+ from pybind11_mkdoc .mkdoc_lib import mkdoc
1613
1714__version__ = "2.6.2.dev1"
1815
1916
20- def _append_include_dir (args : list , include_dir : str , verbose : bool = True ):
17+ def _append_include_dir (args : list , include_dir : str , * , verbose : bool = True ):
2118 """
2219 Add an include directory to an argument list (if it exists).
2320
@@ -37,10 +34,10 @@ def _append_include_dir(args: list, include_dir: str, verbose: bool = True):
3734 if os .path .isdir (include_dir ):
3835 args .append (f"-I{ shlex .quote (include_dir )} " )
3936 elif verbose :
40- print ( f"Include directoy ' { shlex . quote ( include_dir ) } ' does not exist!" )
37+ pass
4138
4239
43- def _append_definition (args : list , definition : str , verbose : bool = True ):
40+ def _append_definition (args : list , definition : str ):
4441 """
4542 Add a compiler definition to an argument list.
4643
@@ -61,21 +58,20 @@ def _append_definition(args: list, definition: str, verbose: bool = True):
6158 """
6259
6360 try :
64- macro , value = definition .strip ().split ('=' )
61+ macro , value = definition .strip ().split ("=" )
6562 macro = shlex .quote (macro .strip ())
66- value = shlex .quote (value .strip ()) if value else '1'
63+ value = shlex .quote (value .strip ()) if value else "1"
6764
6865 args .append (f"-D{ macro } ={ value } " )
69- except ValueError as exc :
66+ except ValueError :
7067 # most likely means there was no '=' given
7168 # check if argument is valid identifier
72- if re .search (r' ^[A-Za-z_][A-Za-z0-9_]*' , definition ):
69+ if re .search (r" ^[A-Za-z_][A-Za-z0-9_]*" , definition ):
7370 args .append (f"-D{ definition } " )
7471 else :
75- print (f"Failed to parse definition: { shlex .quote (definition )} " )
76- except :
77- print (f"Failed to parse definition: { shlex .quote (definition )} " )
78-
72+ pass
73+ except Exception :
74+ pass
7975
8076
8177def main ():
@@ -86,26 +82,53 @@ def main():
8682 """
8783
8884 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 )
85+ prog = "pybind11_mkdoc" ,
86+ description = "Processes a sequence of C/C++ headers and extracts comments for use in pybind11 binding code." ,
87+ epilog = "(Other compiler flags that Clang understands can also be supplied)" ,
88+ allow_abbrev = False ,
89+ )
9390
9491 parser .add_argument ("-v" , "--version" , action = "version" , version = f"%(prog)s { __version__ } " )
9592
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." )
93+ parser .add_argument (
94+ "-o" ,
95+ "--output" ,
96+ action = "store" ,
97+ type = str ,
98+ dest = "output" ,
99+ metavar = "<file>" ,
100+ help = "Write to the specified file (default: use stdout)." ,
101+ )
102+
103+ parser .add_argument (
104+ "-w" ,
105+ "--width" ,
106+ action = "store" ,
107+ type = int ,
108+ dest = "width" ,
109+ metavar = "<width>" ,
110+ help = "Specify docstring width before wrapping." ,
111+ )
112+
113+ parser .add_argument (
114+ "-I" ,
115+ action = "append" ,
116+ type = str ,
117+ dest = "include_dirs" ,
118+ metavar = "<dir>" ,
119+ help = "Specify an directory to add to the list of include search paths." ,
120+ )
121+
122+ parser .add_argument (
123+ "-D" ,
124+ action = "append" ,
125+ type = str ,
126+ metavar = "<macro>=<value>" ,
127+ dest = "definitions" ,
128+ help = "Specify a compiler definition, i.e. define <macro> to <value> (or 1 if <value> omitted)." ,
129+ )
130+
131+ parser .add_argument ("header" , type = str , nargs = "+" , help = "A header file to process." )
109132
110133 [parsed_args , unparsed_args ] = parser .parse_known_args ()
111134
@@ -130,8 +153,7 @@ def main():
130153 # append argument as is and hope for the best
131154 mkdoc_args .append (shlex .quote (arg ))
132155
133- for header in parsed_args .header :
134- mkdoc_args .append (shlex .quote (header ))
156+ mkdoc_args .extend (shlex .quote (header ) for header in parsed_args .header )
135157
136158 mkdoc (mkdoc_args , docstring_width , mkdoc_out )
137159
0 commit comments