Repository: scikit-build/scikit-build-core
Pull request #651 (2024-02-26 20:19:57)

fix: expand info printing
Add info print functionality to a few more modules


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) Report
Attention: Patch coverage is `14.89362%` with `40 lines` in your changes are missing coverage. Please review.
> Project coverage is 85.24%. Comparing base [(`925bee5`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/925bee58812bf1515f0005bc3a14491099112990?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) to head [(`b7fa136`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).
> Report is 1 commits behind head on main.

| [Files](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) | Patch % | Lines |
|---|---|---|
| [src/scikit\_build\_core/builder/\_\_main\_\_.py](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build#diff-c3JjL3NjaWtpdF9idWlsZF9jb3JlL2J1aWxkZXIvX19tYWluX18ucHk=) | 0.00% | [24 Missing :warning: ](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) |
| [src/scikit\_build\_core/builder/sysconfig.py](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build#diff-c3JjL3NjaWtpdF9idWlsZF9jb3JlL2J1aWxkZXIvc3lzY29uZmlnLnB5) | 27.27% | [8 Missing :warning: ](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) |
| [src/scikit\_build\_core/program\_search.py](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build#diff-c3JjL3NjaWtpdF9idWlsZF9jb3JlL3Byb2dyYW1fc2VhcmNoLnB5) | 27.27% | [8 Missing :warning: ](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #651      +/-   ##
==========================================
- Coverage   86.23%   85.24%   -0.99%     
==========================================
  Files          63       64       +1     
  Lines        3233     3274      +41     
==========================================
+ Hits         2788     2791       +3     
- Misses        445      483      +38     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/651?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).


Patch:
diff --git a/docs/cmakelists.md b/docs/cmakelists.md
index 0681186..3bc3efc 100644
--- a/docs/cmakelists.md
+++ b/docs/cmakelists.md
@@ -42,7 +42,26 @@ If you are making a Limited ABI / Stable API package, you'll need the
 
 If you want to cross-compile to Windows ARM, you'll need to use
 `${SKBUILD_SOABI}`, which is always correct, instead of trusting FindPython's
-`Python_SOABI` value.
+`Python_SOABI` value. You can manually set the extension suffix after making a
+target:
+
+```cmake
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+    set_property (TARGET ${name} PROPERTY SUFFIX "$.{SKBUILD_SOSABI}.pyd")
+else()
+    set_property (TARGET ${name} PROPERTY SUFFIX ".${SKBUILD_SOSABI}${CMAKE_SHARED_MODULE_SUFFIX}")
+endif()
+```
+
+A quicker way to do this would be to instead override `Python_SOABI` after
+`find_package(Python)`:
+
+```cmake
+set(Python_SOABI ${SKBUILD_SOABI})
+```
+
+However, this isn't officially supported upstream, and only works due to the way
+this variable is used when creating targets.
 
 :::
 
diff --git a/src/scikit_build_core/_logging.py b/src/scikit_build_core/_logging.py
index 2c6fa25..b70c451 100644
--- a/src/scikit_build_core/_logging.py
+++ b/src/scikit_build_core/_logging.py
@@ -79,7 +79,7 @@ class ScikitBuildLogger:
 logger = ScikitBuildLogger(raw_logger)
 
 
-ANY_ESCAPE = re.compile(r"\[([\w\s/]*)\]")
+ANY_ESCAPE = re.compile(r"\[([\w\s/]+)\]")
 
 
 _COLORS = {
diff --git a/src/scikit_build_core/builder/__main__.py b/src/scikit_build_core/builder/__main__.py
new file mode 100644
index 0000000..21aa4c9
--- /dev/null
+++ b/src/scikit_build_core/builder/__main__.py
@@ -0,0 +1,39 @@
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+from .. import __version__
+from .._logging import rich_print
+from ..program_search import info_print as ip_program_search
+from .get_requires import GetRequires
+from .sysconfig import info_print as ip_sysconfig
+from .wheel_tag import WheelTag
+
+__all__ = ["main"]
+
+
+def __dir__() -> list[str]:
+    return __all__
+
+
+def main() -> None:
+    rich_print(f"[bold]Scikit-build-core {__version__}[/bold] on Python {sys.version}")
+
+    ip_sysconfig(color="green")
+
+    rich_print(f"[bold blue]Default Wheel Tag:[/bold] {WheelTag.compute_best([])}")
+    rich_print(
+        "[blue] - Note: use [bold]python -m scikit_build_core.builder.wheel_tag[/bold] for further options[/blue]"
+    )
+
+    if Path("pyproject.toml").is_file():
+        req = GetRequires()
+        all_req = [*req.cmake(), *req.ninja(), *req.dynamic_metadata()]
+        rich_print(f"[bold red]Get Requires:[/bold] {all_req!r}")
+
+    ip_program_search(color="magenta")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/src/scikit_build_core/builder/sysconfig.py b/src/scikit_build_core/builder/sysconfig.py
index e8ad537..98e14c6 100644
--- a/src/scikit_build_core/builder/sysconfig.py
+++ b/src/scikit_build_core/builder/sysconfig.py
@@ -7,7 +7,7 @@ import sysconfig
 from pathlib import Path
 from typing import TYPE_CHECKING
 
-from .._logging import logger
+from .._logging import logger, rich_print
 
 if TYPE_CHECKING:
     from collections.abc import Mapping
@@ -18,6 +18,7 @@ __all__ = [
     "get_python_include_dir",
     "get_python_library",
     "get_soabi",
+    "info_print",
 ]
 
 
@@ -169,3 +170,33 @@ def get_numpy_include_dir() -> Path | None:
         return None
 
     return Path(np.get_include())
+
+
+def info_print(*, color: str = "") -> None:
+    """
+    Print information about the Python environment.
+    """
+
+    rich_print(
+        f"[bold {color}]Detected Python Library:[/bold] {get_python_library(os.environ, abi3=False)}"
+    )
+    rich_print(
+        f"[bold {color}]Detected ABI3 Python Library:[/bold] {get_python_library(os.environ, abi3=True)}"
+    )
+    rich_print(
+        f"[bold {color}]Detected Python Include Directory:[/bold] {get_python_include_dir()}"
+    )
+    rich_print(
+        f"[bold {color}]Detected NumPy Include Directory:[/bold] {get_numpy_include_dir()}"
+    )
+    rich_print(f"[bold {color}]Detected Platform:[/bold] {get_platform()}")
+    rich_print(
+        f"[bold {color}]Detected SOABI:[/bold] {get_soabi(os.environ, abi3=False)}"
+    )
+    rich_print(
+        f"[bold {color}]Detected ABI3 SOABI:[/bold] {get_soabi(os.environ, abi3=True)}"
+    )
+
+
+if __name__ == "__main__":
+    info_print()
diff --git a/src/scikit_build_core/program_search.py b/src/scikit_build_core/program_search.py
index 8cc1803..8208b24 100644
--- a/src/scikit_build_core/program_search.py
+++ b/src/scikit_build_core/program_search.py
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, NamedTuple
 
 from packaging.version import InvalidVersion, Version
 
-from ._logging import logger
+from ._logging import logger, rich_print
 from ._shutil import Run
 
 if TYPE_CHECKING:
@@ -149,3 +149,20 @@ def best_program(
             return program
 
     return None
+
+
+def info_print(*, color: str = "") -> None:
+    """
+    Print information about the program search.
+    """
+    rich_print(f"[bold {color}]Detected CMake and Ninja[/bold] (all versions):")
+    for n, prog in enumerate(get_cmake_programs()):
+        s = " " if n else "*"
+        rich_print(f"{s} [bold {color}]CMake:[/bold] {prog.path} {prog.version!r}")
+    for n, prog in enumerate(get_ninja_programs()):
+        s = " " if n else "*"
+        rich_print(f"{s} [bold {color}]Ninja:[/bold] {prog.path} {prog.version!r}")
+
+
+if __name__ == "__main__":
+    info_print()


Test patch:
diff --git a/tests/test_printouts.py b/tests/test_printouts.py
new file mode 100644
index 0000000..cac8e5c
--- /dev/null
+++ b/tests/test_printouts.py
@@ -0,0 +1,7 @@
+from scikit_build_core.builder.__main__ import main
+
+
+def test_builder_printout(capsys):
+    main()
+    out, err = capsys.readouterr()
+    assert "Detected Python Library" in out