Skip to content

Commit 03b9024

Browse files
authored
refactor: minor changes from editable work (#214)
Pulling a bit from #212 Signed-off-by: Henry Schreiner <[email protected]>
1 parent c4469f6 commit 03b9024

File tree

4 files changed

+62
-40
lines changed

4 files changed

+62
-40
lines changed

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def tests(session: nox.Session) -> None:
3636
Run the unit and regular tests.
3737
"""
3838
env = {"PIP_DISABLE_PIP_VERSION_CHECK": "1"}
39-
extra = []
39+
extra = ["rich"]
4040
# This will not work if system CMake is too old (<3.15)
4141
if shutil.which("cmake") is None and shutil.which("cmake3") is None:
4242
extra.append("cmake")

src/scikit_build_core/_shutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _run(
4444

4545
if self.env:
4646
logger.debug(
47-
"RUNENV: {}", " ".join(f"{k}={v}" for k, v in self.env.items())
47+
"RUNENV:\n {}", "\n ".join(f"{k}={v}" for k, v in self.env.items())
4848
)
4949
logger.debug("RUN: {}", " ".join(options))
5050

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Sequence
4+
from pathlib import Path
5+
6+
from ._file_processor import each_unignored_file
7+
8+
__all__ = ["packages_to_file_mapping"]
9+
10+
11+
def __dir__() -> list[str]:
12+
return __all__
13+
14+
15+
def packages_to_file_mapping(
16+
*,
17+
packages: Sequence[str],
18+
platlib_dir: Path,
19+
include: Sequence[str],
20+
exclude: Sequence[str],
21+
) -> dict[str, str]:
22+
mapping = {}
23+
for package in packages:
24+
source_package = Path(package)
25+
base_path = source_package.parent
26+
for filepath in each_unignored_file(
27+
source_package,
28+
include=include,
29+
exclude=exclude,
30+
):
31+
package_dir = platlib_dir / filepath.relative_to(base_path)
32+
if not package_dir.is_file():
33+
mapping[str(filepath)] = str(package_dir)
34+
35+
return mapping

src/scikit_build_core/build/wheel.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from ..builder.wheel_tag import WheelTag
1919
from ..cmake import CMake, CMaker
2020
from ..settings.skbuild_read_settings import SettingsReader
21-
from ._file_processor import each_unignored_file
2221
from ._init import setup_logging
22+
from ._pathutil import packages_to_file_mapping
2323
from ._wheelfile import WheelWriter
2424

2525
__all__: list[str] = ["_build_wheel_impl"]
@@ -29,44 +29,24 @@ def __dir__() -> list[str]:
2929
return __all__
3030

3131

32-
def _copy_python_packages_to_wheel(
33-
*,
34-
packages: Sequence[str] | None,
35-
name: str,
36-
platlib_dir: Path,
37-
include: Sequence[str],
38-
exclude: Sequence[str],
39-
) -> dict[str, str]:
40-
mapping = {}
41-
if packages is None:
42-
# Auto package discovery
43-
packages = []
44-
for base_path in (Path("src"), Path(".")):
45-
path = base_path / name
46-
if path.is_dir() and (
47-
(path / "__init__.py").is_file() or (path / "__init__.pyi").is_file()
48-
):
49-
logger.info("Discovered Python package at {}", path)
50-
packages += [str(path)]
51-
break
52-
else:
53-
logger.debug("Didn't find a Python package for {}", name)
54-
55-
for package in packages:
56-
source_package = Path(package)
57-
base_path = source_package.parent
58-
for filepath in each_unignored_file(
59-
source_package,
60-
include=include,
61-
exclude=exclude,
32+
def _get_packages(*, packages: Sequence[str] | None, name: str) -> list[str]:
33+
if packages is not None:
34+
return list(packages)
35+
36+
# Auto package discovery
37+
packages = []
38+
for base_path in (Path("src"), Path(".")):
39+
path = base_path / name
40+
if path.is_dir() and (
41+
(path / "__init__.py").is_file() or (path / "__init__.pyi").is_file()
6242
):
63-
package_dir = platlib_dir / filepath.relative_to(base_path)
64-
if not package_dir.is_file():
65-
package_dir.parent.mkdir(exist_ok=True, parents=True)
66-
shutil.copyfile(filepath, package_dir)
67-
mapping[str(filepath)] = str(package_dir)
43+
logger.info("Discovered Python package at {}", path)
44+
packages += [str(path)]
45+
break
46+
else:
47+
logger.debug("Didn't find a Python package for {}", name)
6848

69-
return mapping
49+
return packages
7050

7151

7252
@dataclasses.dataclass
@@ -203,14 +183,21 @@ def _build_wheel_impl(
203183
builder.install(install_dir)
204184

205185
rich_print("[green]***[/green] [bold]Making wheel...")
206-
mapping = _copy_python_packages_to_wheel(
186+
packages = _get_packages(
207187
packages=settings.wheel.packages,
208188
name=normalized_name,
189+
)
190+
mapping = packages_to_file_mapping(
191+
packages=packages,
209192
platlib_dir=wheel_dirs["platlib"],
210193
include=settings.sdist.include,
211194
exclude=settings.sdist.exclude,
212195
)
213196

197+
for filepath, package_dir in mapping.items():
198+
Path(package_dir).parent.mkdir(exist_ok=True, parents=True)
199+
shutil.copyfile(filepath, package_dir)
200+
214201
for item in wheel_dirs["scripts"].iterdir():
215202
with item.open("rb") as f:
216203
content = f.read(len(b"#!python"))

0 commit comments

Comments
 (0)