Skip to content

Commit

Permalink
normalize filepaths
Browse files Browse the repository at this point in the history
This should fix inconsistent forward/backward slash sourceinfo.

I'd be intrigued to find out what causes this inconsistency in the first
place, though.
It might have something to do with the pathlib migration, i.e. a fork
change. Since I added the `replace("\\\\", "\\")` myself, I'd presume
that it used to work upstream.
  • Loading branch information
mara004 committed Feb 12, 2024
1 parent f500bcf commit 8e678f3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/ctypesgen/printer_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from pathlib import Path
from ctypesgen.ctypedescs import CtypesBitfield


Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(self, outpath, options, data, argv):

res = []
for kind, desc in data:
desc.src = (str(Path(desc.src[0]).as_posix()), *desc.src[1:])
item = method_table[kind](desc)
if item: res.append(item)
with outpath.open("w", encoding="utf-8") as fh:
Expand Down
2 changes: 1 addition & 1 deletion src/ctypesgen/printer_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, outpath, opts, data, argv):
@classmethod
def _txtpath(cls, s):
# Returns a path string suitable for embedding into the output, with private paths stripped
s = str(s)
s = str( Path(s).as_posix() )
for p, x in cls.PRIVATE_PATHS_TABLE:
if s.startswith(p):
return x + s[len(p):]
Expand Down
5 changes: 1 addition & 4 deletions tests/json_expects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ def _replace_anon_tag(self, json, tag, new_tag):
if value == tag:
json[key] = new_tag
elif key == "src" and isinstance(value, list) and value:
# for whatever reason, on windows ctypesgen's json output contains double slashes in paths, whereas the expectation contains only single slashes, so normalize the output
if sys.platform == "win32":
value[0] = value[0].replace("\\\\", "\\")
# # ignore the line number so changing headers does not cause erroneous test fails
# ignore the line number so changing headers does not cause erroneous test fails
value[1] = None
else:
self._replace_anon_tag(value, tag, new_tag)
Expand Down

0 comments on commit 8e678f3

Please sign in to comment.