Skip to content

Commit 5af54d9

Browse files
leakecleakehenryiii
authored
Remove shlex.quote to fix issues when filenames have spaces (#38)
* The shlex.quote is breaking file paths that have spaces in them, as it adds an extra quote so files look like "'my file with spaces.h'" rather than simply "my file with spaces.h". Removing the shlex lines fixes that issue. * Apply suggestions from code review --------- Co-authored-by: leake <[email protected]> Co-authored-by: Henry Schreiner <[email protected]>
1 parent 20a0959 commit 5af54d9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pybind11_mkdoc/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def _append_include_dir(args: list, include_dir: str, verbose: bool = True):
3535
"""
3636

3737
if os.path.isdir(include_dir):
38-
args.append(f"-I{shlex.quote(include_dir)}")
38+
args.append(f"-I{include_dir}")
3939
elif verbose:
40-
print(f"Include directoy '{shlex.quote(include_dir)}' does not exist!")
40+
print(f"Include directory {include_dir!r} does not exist!")
4141

4242

4343
def _append_definition(args: list, definition: str, verbose: bool = True):
@@ -61,9 +61,9 @@ def _append_definition(args: list, definition: str, verbose: bool = True):
6161
"""
6262

6363
try:
64-
macro, value = definition.strip().split('=')
65-
macro = shlex.quote(macro.strip())
66-
value = shlex.quote(value.strip()) if value else '1'
64+
macro, _, value = definition.partition('=')
65+
macro = macro.strip()
66+
value = value.strip() if value else '1'
6767

6868
args.append(f"-D{macro}={value}")
6969
except ValueError as exc:
@@ -72,9 +72,9 @@ def _append_definition(args: list, definition: str, verbose: bool = True):
7272
if re.search(r'^[A-Za-z_][A-Za-z0-9_]*', definition):
7373
args.append(f"-D{definition}")
7474
else:
75-
print(f"Failed to parse definition: {shlex.quote(definition)}")
75+
print(f"Failed to parse definition: {definition}")
7676
except:
77-
print(f"Failed to parse definition: {shlex.quote(definition)}")
77+
print(f"Failed to parse definition: {definition}")
7878

7979

8080

@@ -128,10 +128,10 @@ def main():
128128
_append_definition(mkdoc_args, arg[2:])
129129
else:
130130
# append argument as is and hope for the best
131-
mkdoc_args.append(shlex.quote(arg))
131+
mkdoc_args.append(arg)
132132

133133
for header in parsed_args.header:
134-
mkdoc_args.append(shlex.quote(header))
134+
mkdoc_args.append(header)
135135

136136
mkdoc(mkdoc_args, docstring_width, mkdoc_out)
137137

0 commit comments

Comments
 (0)