From 19397c0f6b06f0d31eddb61be8577cf96d48f08e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 3 Sep 2024 10:48:52 -0400 Subject: [PATCH 1/2] Strip possibly present trailing / before adding one Without that users must have trailing / removed, but nobody checks for that etc. So now we have "raw//" etc, e.g. at https://bids-specification.readthedocs.io/en/latest/derivatives/common-data-types.html#example-use-of-a-descriptionstsv-file With this change it would make it easier on user and guaranteed to render consistently correctly --- tools/examplecode/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/examplecode/example.py b/tools/examplecode/example.py index efe8232c96..29da732c69 100644 --- a/tools/examplecode/example.py +++ b/tools/examplecode/example.py @@ -69,7 +69,7 @@ def _add_dictionary( # We are dealing with a directory else: - self._tree.append(f"{prefix}{connector} {entry}{os.sep}") + self._tree.append(f"{prefix}{connector} {entry.rstrip(os.sep)}{os.sep}") prefix += ( self.PIPE_PREFIX if index != entries_count - 1 else self.SPACE_PREFIX ) From 81e7a43334e979efb8a4462fb845defd319a44c3 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 3 Sep 2024 10:53:01 -0400 Subject: [PATCH 2/2] Use posixpath.sep instead of os.sep to have consistent across OS rendering --- tools/examplecode/example.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/examplecode/example.py b/tools/examplecode/example.py index 29da732c69..21f358f886 100644 --- a/tools/examplecode/example.py +++ b/tools/examplecode/example.py @@ -7,7 +7,7 @@ """ -import os +import posixpath class DirectoryTree: @@ -69,7 +69,9 @@ def _add_dictionary( # We are dealing with a directory else: - self._tree.append(f"{prefix}{connector} {entry.rstrip(os.sep)}{os.sep}") + self._tree.append( + f"{prefix}{connector} {entry.rstrip(posixpath.sep)}{posixpath.sep}" + ) prefix += ( self.PIPE_PREFIX if index != entries_count - 1 else self.SPACE_PREFIX )