Skip to content

Commit

Permalink
fix: proper printout ordering and more details (#365)
Browse files Browse the repository at this point in the history
- fix: smarter printout of changes
- fix: flush printer
- fix: more details from color printout

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Jun 10, 2023
1 parent fb24652 commit b5940ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/scikit_build_core/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ def rich_print(*args: object, **kwargs: object) -> None:
args_2 = tuple(_process_rich(arg) for arg in args)
if args != args_2:
args_2 = (*args_2[:-1], args_2[-1] + colors()["reset"])
print(*args_2, **kwargs) # type: ignore[call-overload] # noqa: T201
print(*args_2, **kwargs, flush=True) # type: ignore[call-overload] # noqa: T201
25 changes: 20 additions & 5 deletions src/scikit_build_core/_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Run:
cwd: os.PathLike[str] | None = None

# Stores last printout, for cleaner debug logging
_prev_env: ClassVar[str] = ""
_prev_env: ClassVar[dict[str, str]] = {}

def live(self, *args: str | os.PathLike[str]) -> None:
"""
Expand All @@ -47,12 +47,19 @@ def _run(
]

if self.env:
msg = "\n ".join(f"{k}={v}" for k, v in sorted(self.env.items()))
if msg != self._prev_env:
if not self._prev_env:
type(self)._prev_env = self.env.copy()
msg = "\n ".join(f"{k}={v}" for k, v in sorted(self.env.items()))
logger.debug("RUNENV:\n {}", msg)
else:
logger.debug("RUNENV: same as last run")
type(self)._prev_env = msg
msg = "\n ".join(
f"{self._key_diff(k)} {k}={self.env.get(k, '<unset>')}"
for k in sorted(self.env.keys() | self._prev_env.keys())
if self._prev_env.get(k, None) != self.env.get(k, None)
)
logger.debug("RUNENV - changes since last run only:\n {}", msg)
type(self)._prev_env = self.env.copy()

logger.debug("RUN: {}", " ".join(options))

return subprocess.run(
Expand All @@ -63,3 +70,11 @@ def _run(
env=self.env,
cwd=self.cwd,
)

def _key_diff(self, k: str) -> str:
assert self.env
if k in self.env and k not in self._prev_env:
return "+"
if k in self._prev_env and k not in self.env:
return "-"
return " "
12 changes: 9 additions & 3 deletions src/scikit_build_core/build/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ def _build_wheel_impl(
cmake = CMake.default_search(
minimum_version=Version(settings.cmake.minimum_version)
)
action = (
"metadata" if wheel_directory is None else "editable" if editable else "wheel"
)
rich_print(
f"[green]***[/green] [bold][green]scikit-build-core {__version__}[/green] using [blue]CMake {cmake.version}[/blue]"
f"[green]***[/green] [bold][green]scikit-build-core {__version__}[/green]",
f"using [blue]CMake {cmake.version}[/blue]",
f"[red]({action})[/red]",
)

with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -187,7 +192,7 @@ def _build_wheel_impl(
path.write_bytes(data)
return WheelImplReturn(wheel_filename=dist_info.name)

rich_print("[green]***[/green] [bold]Configurating CMake...")
rich_print("[green]***[/green] [bold]Configuring CMake...")
defines: dict[str, str] = {}
cache_entries = {f"SKBUILD_{k.upper()}_DIR": v for k, v in wheel_dirs.items()}
builder.configure(
Expand All @@ -212,7 +217,7 @@ def _build_wheel_impl(
rich_print("[green]***[/green] [bold]Installing project into wheel...")
builder.install(install_dir)

rich_print("[green]***[/green] [bold]Making wheel...")
rich_print(f"[green]***[/green] [bold]Making {action}...")
packages = _get_packages(
packages=settings.wheel.packages,
name=normalized_name,
Expand Down Expand Up @@ -295,4 +300,5 @@ def _build_wheel_impl(
raise AssertionError(msg)

wheel_filename: str = wheel.wheelpath.name
rich_print(f"[green]***[/green] [bold]Created[/bold] {wheel_filename}...")
return WheelImplReturn(wheel_filename=wheel_filename, mapping=mapping)

0 comments on commit b5940ed

Please sign in to comment.