Skip to content

Commit f1d489b

Browse files
authored
fix: expand info printing (#651)
Add info print functionality to a few more modules Signed-off-by: Henry Schreiner <[email protected]>
1 parent 875cb68 commit f1d489b

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

src/scikit_build_core/_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def addHandler(self, handler: logging.Handler) -> None: # noqa: N802
7979
logger = ScikitBuildLogger(raw_logger)
8080

8181

82-
ANY_ESCAPE = re.compile(r"\[([\w\s/]*)\]")
82+
ANY_ESCAPE = re.compile(r"\[([\w\s/]+)\]")
8383

8484

8585
_COLORS = {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
from .. import __version__
7+
from .._logging import rich_print
8+
from ..program_search import info_print as ip_program_search
9+
from .get_requires import GetRequires
10+
from .sysconfig import info_print as ip_sysconfig
11+
from .wheel_tag import WheelTag
12+
13+
__all__ = ["main"]
14+
15+
16+
def __dir__() -> list[str]:
17+
return __all__
18+
19+
20+
def main() -> None:
21+
rich_print(f"[bold]Scikit-build-core {__version__}[/bold] on Python {sys.version}")
22+
23+
ip_sysconfig(color="green")
24+
25+
rich_print(f"[bold blue]Default Wheel Tag:[/bold] {WheelTag.compute_best([])}")
26+
rich_print(
27+
"[blue] - Note: use [bold]python -m scikit_build_core.builder.wheel_tag[/bold] for further options[/blue]"
28+
)
29+
30+
if Path("pyproject.toml").is_file():
31+
req = GetRequires()
32+
all_req = [*req.cmake(), *req.ninja(), *req.dynamic_metadata()]
33+
rich_print(f"[bold red]Get Requires:[/bold] {all_req!r}")
34+
35+
ip_program_search(color="magenta")
36+
37+
38+
if __name__ == "__main__":
39+
main()

src/scikit_build_core/builder/sysconfig.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING
99

10-
from .._logging import logger
10+
from .._logging import logger, rich_print
1111

1212
if TYPE_CHECKING:
1313
from collections.abc import Mapping
@@ -18,6 +18,7 @@
1818
"get_python_include_dir",
1919
"get_python_library",
2020
"get_soabi",
21+
"info_print",
2122
]
2223

2324

@@ -169,3 +170,33 @@ def get_numpy_include_dir() -> Path | None:
169170
return None
170171

171172
return Path(np.get_include())
173+
174+
175+
def info_print(*, color: str = "") -> None:
176+
"""
177+
Print information about the Python environment.
178+
"""
179+
180+
rich_print(
181+
f"[bold {color}]Detected Python Library:[/bold] {get_python_library(os.environ, abi3=False)}"
182+
)
183+
rich_print(
184+
f"[bold {color}]Detected ABI3 Python Library:[/bold] {get_python_library(os.environ, abi3=True)}"
185+
)
186+
rich_print(
187+
f"[bold {color}]Detected Python Include Directory:[/bold] {get_python_include_dir()}"
188+
)
189+
rich_print(
190+
f"[bold {color}]Detected NumPy Include Directory:[/bold] {get_numpy_include_dir()}"
191+
)
192+
rich_print(f"[bold {color}]Detected Platform:[/bold] {get_platform()}")
193+
rich_print(
194+
f"[bold {color}]Detected SOABI:[/bold] {get_soabi(os.environ, abi3=False)}"
195+
)
196+
rich_print(
197+
f"[bold {color}]Detected ABI3 SOABI:[/bold] {get_soabi(os.environ, abi3=True)}"
198+
)
199+
200+
201+
if __name__ == "__main__":
202+
info_print()

src/scikit_build_core/program_search.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from packaging.version import InvalidVersion, Version
1010

11-
from ._logging import logger
11+
from ._logging import logger, rich_print
1212
from ._shutil import Run
1313

1414
if TYPE_CHECKING:
@@ -149,3 +149,20 @@ def best_program(
149149
return program
150150

151151
return None
152+
153+
154+
def info_print(*, color: str = "") -> None:
155+
"""
156+
Print information about the program search.
157+
"""
158+
rich_print(f"[bold {color}]Detected CMake and Ninja[/bold] (all versions):")
159+
for n, prog in enumerate(get_cmake_programs()):
160+
s = " " if n else "*"
161+
rich_print(f"{s} [bold {color}]CMake:[/bold] {prog.path} {prog.version!r}")
162+
for n, prog in enumerate(get_ninja_programs()):
163+
s = " " if n else "*"
164+
rich_print(f"{s} [bold {color}]Ninja:[/bold] {prog.path} {prog.version!r}")
165+
166+
167+
if __name__ == "__main__":
168+
info_print()

tests/test_printouts.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from scikit_build_core.builder.__main__ import main
2+
3+
4+
def test_builder_printout(capsys):
5+
main()
6+
out, err = capsys.readouterr()
7+
assert "Detected Python Library" in out

0 commit comments

Comments
 (0)