Skip to content

Commit c4469f6

Browse files
authored
test: nicer exit, minor refactors (#213)
Pulled from #212. Signed-off-by: Henry Schreiner <[email protected]>
1 parent 5a7d8f4 commit c4469f6

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/scikit_build_core/build/_wheelfile.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def basename(self) -> str:
9393
def wheelpath(self) -> Path:
9494
return self.folder / f"{self.basename}.whl"
9595

96+
@property
97+
def dist_info(self) -> str:
98+
return f"{self.name_ver}.dist-info"
99+
96100
@staticmethod
97101
def timestamp(mtime: float | None = None) -> tuple[int, int, int, int, int, int]:
98102
timestamp = int(os.environ.get("SOURCE_DATE_EPOCH", mtime or time.time()))
@@ -145,7 +149,7 @@ def build(self, wheel_dirs: dict[str, Path]) -> None:
145149

146150
dist_info_contents = self.dist_info_contents()
147151
for key, data in dist_info_contents.items():
148-
self.writestr(f"{self.name_ver}.dist-info/{key}", data)
152+
self.writestr(f"{self.dist_info}/{key}", data)
149153

150154
def write(self, filename: str, arcname: str | None = None) -> None:
151155
"""Write a file to the archive."""
@@ -179,7 +183,7 @@ def __enter__(self) -> Self:
179183

180184
def __exit__(self, *args: object) -> None:
181185
assert self.zipfile is not None
182-
record = f"{self.name_ver}.dist-info/RECORD"
186+
record = f"{self.dist_info}/RECORD"
183187
data = io.StringIO()
184188
writer = csv.writer(data, delimiter=",", quotechar='"', lineterminator="\n")
185189
for member in self.zipfile.infolist():

src/scikit_build_core/build/wheel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class WheelImplReturn:
7777

7878
def _build_wheel_impl(
7979
wheel_directory: str | None,
80-
config_settings: dict[str, list[str] | str] | None = None,
81-
metadata_directory: str | None = None,
80+
config_settings: dict[str, list[str] | str] | None,
81+
metadata_directory: str | None,
8282
) -> WheelImplReturn:
8383
"""
8484
Build a wheel or just prepare metadata (if wheel dir is None).
@@ -98,6 +98,8 @@ def _build_wheel_impl(
9898
msg = "project.version is not statically specified, must be present currently"
9999
raise AssertionError(msg)
100100

101+
normalized_name = metadata.name.replace("-", "_").replace(".", "_")
102+
101103
cmake = CMake.default_search(
102104
minimum_version=Version(settings.cmake.minimum_version)
103105
)
@@ -203,7 +205,7 @@ def _build_wheel_impl(
203205
rich_print("[green]***[/green] [bold]Making wheel...")
204206
mapping = _copy_python_packages_to_wheel(
205207
packages=settings.wheel.packages,
206-
name=metadata.name.replace("-", "_").replace(".", "_"),
208+
name=normalized_name,
207209
platlib_dir=wheel_dirs["platlib"],
208210
include=settings.sdist.include,
209211
exclude=settings.sdist.exclude,

tests/conftest.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def run(self, *args: str, capture: Literal[False] = ...) -> None:
108108
...
109109

110110
def run(self, *args: str, capture: bool = False) -> str | None:
111+
__tracebackhide__ = True
111112
env = os.environ.copy()
112113
env["PATH"] = f"{self.executable.parent}{os.pathsep}{env['PATH']}"
113114
env["VIRTUAL_ENV"] = str(self.env_dir)
@@ -116,20 +117,31 @@ def run(self, *args: str, capture: bool = False) -> str | None:
116117
env["PIP_NO_INDEX"] = "ON"
117118
env["PIP_FIND_LINKS"] = str(self.wheelhouse)
118119

120+
str_args = [os.fspath(a) for a in args]
121+
119122
if capture:
120-
return subprocess.run(
121-
[os.fspath(a) for a in args],
122-
check=True,
123+
result = subprocess.run(
124+
str_args,
125+
check=False,
123126
capture_output=True,
124127
text=True,
125128
env=env,
126-
).stdout.strip()
127-
128-
subprocess.run(
129-
[os.fspath(a) for a in args],
130-
check=True,
129+
)
130+
if result.returncode != 0:
131+
print(result.stdout, file=sys.stdout)
132+
print(result.stderr, file=sys.stderr)
133+
print("FAILED RUN:", *str_args, file=sys.stderr)
134+
raise SystemExit(result.returncode)
135+
return result.stdout.strip()
136+
137+
result_bytes = subprocess.run(
138+
str_args,
139+
check=False,
131140
env=env,
132141
)
142+
if result_bytes.returncode != 0:
143+
print("FAILED RUN:", *str_args, file=sys.stderr)
144+
raise SystemExit(result_bytes.returncode)
133145
return None
134146

135147
def execute(self, command: str) -> str:

0 commit comments

Comments
 (0)