Skip to content

Commit 19d96d4

Browse files
themarpehenryiii
authored andcommitted
Added capability to specify docstring width
1 parent 2627803 commit 19d96d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pybind11_mkdoc/__main__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
mkdoc_out = None
77
mkdoc_help = False
88
mkdoc_args = []
9+
docstring_width = None
910

1011
i = 1
1112
while i < len(sys.argv):
@@ -18,6 +19,11 @@
1819
i += 1 # Skip next
1920
elif arg.startswith('-o'):
2021
mkdoc_out = arg[2:]
22+
elif arg == '-w':
23+
docstring_width = int(sys.argv[i + 1])
24+
i += 1 # Skip next
25+
elif arg.startswith('-w'):
26+
docstring_width = int(arg[2:])
2127
elif arg == '-I':
2228
# Concatenate include directive and path
2329
mkdoc_args.append(arg + sys.argv[i + 1])
@@ -38,10 +44,12 @@
3844
3945
-o <filename> Write to the specified filename (default: use stdout)
4046
47+
-w <width> Specify docstring width before wrapping
48+
4149
-I <path> Specify an include directory
4250
4351
-Dkey=value Specify a compiler definition
4452
4553
(Other compiler flags that Clang understands can also be supplied)""")
4654
else:
47-
mkdoc(mkdoc_args, mkdoc_out)
55+
mkdoc(mkdoc_args, docstring_width, mkdoc_out)

pybind11_mkdoc/mkdoc_lib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
job_count = cpu_count()
6363
job_semaphore = Semaphore(job_count)
6464
errors_detected = False
65+
docstring_width = int(70)
6566

6667

6768
class NoFilenamesError(ValueError):
@@ -165,7 +166,7 @@ def process_comment(comment):
165166
wrapper.expand_tabs = True
166167
wrapper.replace_whitespace = True
167168
wrapper.drop_whitespace = True
168-
wrapper.width = 70
169+
wrapper.width = docstring_width
169170
wrapper.initial_indent = wrapper.subsequent_indent = ''
170171

171172
result = ''
@@ -376,7 +377,10 @@ def write_header(comments, out_file=sys.stdout):
376377
''', file=out_file)
377378

378379

379-
def mkdoc(args, output=None):
380+
def mkdoc(args, width, output=None):
381+
if width != None:
382+
global docstring_width
383+
docstring_width = int(width)
380384
comments = extract_all(args)
381385
if errors_detected:
382386
return

0 commit comments

Comments
 (0)