From 8e678f3b0f3545253d27e29b720700b6ea80efcf Mon Sep 17 00:00:00 2001 From: geisserml Date: Mon, 12 Feb 2024 23:44:48 +0100 Subject: [PATCH] normalize filepaths 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. --- src/ctypesgen/printer_json.py | 2 ++ src/ctypesgen/printer_python.py | 2 +- tests/json_expects.py | 5 +---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ctypesgen/printer_json.py b/src/ctypesgen/printer_json.py index 7f1253a7..322e8141 100755 --- a/src/ctypesgen/printer_json.py +++ b/src/ctypesgen/printer_json.py @@ -1,4 +1,5 @@ import json +from pathlib import Path from ctypesgen.ctypedescs import CtypesBitfield @@ -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: diff --git a/src/ctypesgen/printer_python.py b/src/ctypesgen/printer_python.py index c00410d8..6b220633 100755 --- a/src/ctypesgen/printer_python.py +++ b/src/ctypesgen/printer_python.py @@ -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):] diff --git a/tests/json_expects.py b/tests/json_expects.py index 80375108..714a1dab 100644 --- a/tests/json_expects.py +++ b/tests/json_expects.py @@ -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)