Skip to content

Commit 7568be0

Browse files
tae-junpre-commit-ci[bot]henryiii
authored
fix: path_to_module to handle hidden files (e.g. .clang-tidy) correctly (#987)
It works fine with normal install `pip install .` but not for editable install `pip install -e .` I got the error below without this fix because it can't handle hidden file's extension corretly: ``` File "/opt/miniconda3/envs/pyapl/lib/python3.12/site-packages/scikit_build_core/build/_pathutil.py", line 31, in path_to_module path = path.with_name(path.name.split(".", 1)[0]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/miniconda3/envs/pyapl/lib/python3.12/pathlib.py", line 634, in with_name raise ValueError("Invalid name %r" % (name)) ValueError: Invalid name '' ``` For example, if it's `.clang-tidy`, the original splitting `path.name.split(".", 1)[0]` results empty string. --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Henry Schreiner <[email protected]>
1 parent 2f402a6 commit 7568be0

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/scikit_build_core/build/_editable.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def libdir_to_installed(libdir: Path) -> dict[str, str]:
7070
Convert a mapping of files to modules to a mapping of modules to installed files.
7171
"""
7272
return {
73-
path_to_module(v.relative_to(libdir)): str(v.relative_to(libdir))
73+
path_to_module(pth): str(pth)
7474
for v in scantree(libdir)
75+
if is_valid_module(pth := v.relative_to(libdir))
7576
}

src/scikit_build_core/build/_pathutil.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def scantree(path: Path) -> Generator[Path, None, None]:
2828

2929

3030
def path_to_module(path: Path) -> str:
31-
path = path.with_name(path.name.split(".", 1)[0])
31+
name, _, _ = path.name.partition(".")
32+
assert name, f"Empty name should be filtered by is_valid_module first, got {path}"
33+
path = path.with_name(name)
3234
if path.name == "__init__":
3335
path = path.parent
3436
return ".".join(path.parts)

tests/packages/navigate_editable/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ python_add_library(c_module MODULE src/shared_pkg/c_module.c WITH_SOABI)
1212
set(CMakeVar "Some_value_C")
1313
configure_file(src/shared_pkg/data/generated.txt.in
1414
shared_pkg/data/c_generated.txt)
15+
configure_file(src/shared_pkg/data/generated.txt.in shared_pkg/data/.hidden)
1516

1617
install(
1718
TARGETS c_module
1819
DESTINATION shared_pkg/
1920
COMPONENT PythonModule)
2021
install(FILES ${PROJECT_BINARY_DIR}/shared_pkg/data/c_generated.txt
2122
DESTINATION shared_pkg/data/)
23+
install(FILES ${PROJECT_BINARY_DIR}/shared_pkg/data/.hidden
24+
DESTINATION shared_pkg/data/)

0 commit comments

Comments
 (0)