Skip to content

Commit f0d3ea8

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

6 files changed

Lines changed: 1308 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 --force-reinstall ./dist/commoncode-32.5.2-py3-none-any.whl
167167

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

src/commoncode/resource.py

Lines changed: 15 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):
@@ -615,6 +616,9 @@ def err(_error):
615616
if not created.is_file:
616617
parents_by_loc[created.location] = created
617618

619+
if TRACE_DEEP:
620+
logger_debug(f"parents_by_loc: {parents_by_loc}")
621+
618622
# we start walking through all the input locations
619623
for included_location in includes:
620624
# Walk over the directory and build the resource tree
@@ -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,
@@ -669,7 +678,7 @@ def _create_resources_common_prefix_to_inputs(self, root, includes):
669678
_, _, extra_dir_path = included_path.rpartition(root.location)
670679
extra_dirs = extra_dir_path.strip("/").split("/")
671680
if TRACE_DEEP:
672-
logger_debug(f"_create_resources_common_prefix_to_inputs: root:{root.location}, includes: {includes}")
681+
logger_debug(f"_create_resources_common_prefix_to_inputs: included_path:{included_path}, extra_dirs: {extra_dirs}")
673682

674683
dir_resource = root
675684
for dir_segment in extra_dirs:
@@ -678,8 +687,9 @@ def _create_resources_common_prefix_to_inputs(self, root, includes):
678687
parent=dir_resource,
679688
is_file=False,
680689
)
681-
if TRACE:
682-
logger_debug("Codebase.create_resources:", dir_resource)
690+
if TRACE_DEEP:
691+
logger_debug(f"_create_resources_common_prefix_to_inputs: dir_resource:{dir_resource}, extra_dirs: {extra_dirs}")
692+
683693
yield dir_resource
684694

685695
def _create_root_resource(self):

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)