Skip to content

Commit af316fc

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

6 files changed

Lines changed: 1307 additions & 18 deletions

File tree

configure.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ if %ERRORLEVEL% neq 0 (
163163
%FLOT_REQUIREMENTS%
164164

165165
"%CFG_BIN_DIR%\flot" --pyproject pyproject-commoncode.toml
166-
"%CFG_BIN_DIR%\pip" install ./dist/commoncode*.whl
166+
"%CFG_BIN_DIR%\pip" install "%CFG_BIN_DIR%\dist\commoncode-32.5.2-py3-none-any.whl"
167167

168168
"%CFG_BIN_DIR%\pip" install ^
169169
--upgrade ^

src/commoncode/resource.py

Lines changed: 14 additions & 5 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
@@ -64,7 +65,7 @@
6465

6566
# Tracing flags
6667
TRACE = False
67-
TRACE_DEEP = False
68+
TRACE_DEEP = True
6869

6970

7071
def logger_debug(*args):
@@ -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,10 @@ 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
618+
619+
if TRACE_DEEP:
620+
logger_debug(f"parents_by_loc: {parents_by_loc}")
617621

618622
# we start walking through all the input locations
619623
for included_location in includes:
@@ -624,7 +628,12 @@ def err(_error):
624628
max_depth=self.max_depth,
625629
error_handler=err,
626630
):
627-
parent = parents_by_loc.pop(top)
631+
if TRACE_DEEP:
632+
logger_debug(f"parents_by_loc: {parents_by_loc}")
633+
try:
634+
parent = parents_by_loc.pop(top)
635+
except KeyError:
636+
raise Exception(parents_by_loc, includes, root.location, )
628637
for created in self._create_resources(
629638
parent=parent,
630639
top=top,
@@ -634,7 +643,7 @@ def err(_error):
634643
):
635644
# on the plain, bare FS, files cannot be parents
636645
if not created.is_file:
637-
parents_by_loc[created.location] = created
646+
parents_by_loc[to_os_native_path(created.location)] = created
638647

639648
def _create_resources(self, parent, top, dirs, files, skip_ignored=skip_ignored):
640649
"""

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)