Skip to content

Commit 230c72d

Browse files
Fix multiple path bug in windows
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
1 parent 815e454 commit 230c72d

5 files changed

Lines changed: 1296 additions & 15 deletions

File tree

src/commoncode/resource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from commoncode.fileutils import file_name
5050
from commoncode.fileutils import parent_directory
5151
from commoncode.fileutils import splitext_name
52+
from commoncode.system import to_os_native_path
5253

5354
"""
5455
This module provides Codebase and Resource objects as an abstraction for files
@@ -586,7 +587,7 @@ def _create_resources_from_root(self, root, includes, ignores):
586587
# track resources parents by location during construction.
587588
# NOTE: this cannot exhaust memory on a large codebase, because we do
588589
# not keep parents already walked and we walk topdown.
589-
parents_by_loc = {root.location: root}
590+
parents_by_loc = {to_os_native_path(root.location): root}
590591

591592
def err(_error):
592593
"""os.walk error handler"""
@@ -613,7 +614,7 @@ def err(_error):
613614
includes=includes,
614615
):
615616
if not created.is_file:
616-
parents_by_loc[created.location] = created
617+
parents_by_loc[to_os_native_path(created.location)] = created
617618

618619
# we start walking through all the input locations
619620
for included_location in includes:
@@ -634,7 +635,7 @@ def err(_error):
634635
):
635636
# on the plain, bare FS, files cannot be parents
636637
if not created.is_file:
637-
parents_by_loc[created.location] = created
638+
parents_by_loc[to_os_native_path(created.location)] = created
638639

639640
def _create_resources(self, parent, top, dirs, files, skip_ignored=skip_ignored):
640641
"""

src/commoncode/system.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from commoncode.distro import parse_os_release
1414

1515

16+
def to_os_native_path(path):
17+
"""
18+
Normalize a path to use the native OS path separator.
19+
"""
20+
OS_PATH_SEP = "\\" if on_windows else "/"
21+
22+
return path.replace("/", OS_PATH_SEP).replace("\\", OS_PATH_SEP).rstrip(OS_PATH_SEP)
23+
24+
1625
def os_arch():
1726
"""
1827
Return a tuple for the current the OS and architecture.

src/commoncode/testcase.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from commoncode.archive import extract_zip_raw
3030
from commoncode.archive import tar_can_extract # NOQA
3131
from commoncode.system import on_posix
32-
from commoncode.system import on_windows
32+
from commoncode.system import to_os_native_path
3333

3434
# a base test dir specific to a given test run
3535
# to ensure that multiple tests run can be launched in parallel
@@ -39,15 +39,6 @@
3939
timing_threshold = sys.maxsize
4040

4141

42-
def to_os_native_path(path):
43-
"""
44-
Normalize a path to use the native OS path separator.
45-
"""
46-
OS_PATH_SEP = "\\" if on_windows else "/"
47-
48-
return path.replace("/", OS_PATH_SEP).replace("\\", OS_PATH_SEP).rstrip(OS_PATH_SEP)
49-
50-
5142
def get_test_loc(
5243
test_path,
5344
test_data_dir,

0 commit comments

Comments
 (0)