Skip to content

Commit 1fca497

Browse files
authored
fix: drop rich logging/error (#330)
Pip doesn't allow rich to see the terminal, and because of this, the very narrow formatting makes the logs quite hard to read. Let's drop the option for now - if it's fixed in Pip, we can revisit. Signed-off-by: Henry Schreiner <[email protected]>
1 parent 87b0d46 commit 1fca497

File tree

9 files changed

+24
-55
lines changed

9 files changed

+24
-55
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ version = "0.0.1"
8484
```
8585

8686
You can (and should) specify the rest of the entries in `project`, but these are
87-
the minimum to get started. You can also add the `rich` (more colorful
88-
printouts) or `pyproject` (pre-load some dependencies) extras if you want.
87+
the minimum to get started. You can also `scikit-build-core[pyproject]` to
88+
pre-load some dependencies if you want; in some cases this might be marginally
89+
faster.
8990

9091
An example `CMakeLists.txt`:
9192

noxfile.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def tests(session: nox.Session) -> None:
5959
"""
6060
Run the unit and regular tests. Includes coverage if --cov passed.
6161
"""
62-
_run_tests(
63-
session, install_args=["hatch-fancy-pypi-readme", "rich", "setuptools-scm"]
64-
)
62+
_run_tests(session, install_args=["hatch-fancy-pypi-readme", "setuptools-scm"])
6563

6664

6765
@nox.session

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ pyproject = [
4848
"pyproject-metadata >=0.5",
4949
"pathspec >=0.10.1",
5050
]
51-
rich = [
52-
"rich",
53-
]
5451
test = [
5552
"build[virtualenv]",
5653
"cattrs >=22.2.0",

src/scikit_build_core/_logging.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import re
77
import sys
8-
import typing
98
from typing import Any
109

1110
__all__ = ["logger", "raw_logger", "ScikitBuildLogger", "rich_print"]
@@ -125,17 +124,8 @@ def _process_rich(msg: object) -> str:
125124
)
126125

127126

128-
def fake_rich_print(*args: object, **kwargs: object) -> None:
127+
def rich_print(*args: object, **kwargs: object) -> None:
129128
args_2 = tuple(_process_rich(arg) for arg in args)
130129
if args != args_2:
131130
args_2 = (*args_2[:-1], args_2[-1] + colors()["reset"])
132131
print(*args_2, **kwargs) # type: ignore[call-overload] # noqa: T201
133-
134-
135-
if typing.TYPE_CHECKING:
136-
rich_print = fake_rich_print
137-
else:
138-
try:
139-
from rich import print as rich_print
140-
except ModuleNotFoundError:
141-
rich_print = fake_rich_print

src/scikit_build_core/build/_init.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,12 @@ def setup_logging(log_level: str) -> None:
2323
"NOTSET": logging.NOTSET,
2424
}[log_level]
2525

26-
try:
27-
import rich.logging
28-
import rich.traceback
29-
except ModuleNotFoundError:
30-
ch = logging.StreamHandler()
31-
ch.setLevel(level_value)
32-
# create formatter and add it to the handlers
33-
formatter = logging.Formatter(
34-
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
35-
)
36-
ch.setFormatter(formatter)
37-
# add the handlers to the logger
38-
logger.addHandler(ch)
39-
return
40-
41-
FORMAT = "%(message)s"
42-
logging.basicConfig(
43-
level=level_value,
44-
format=FORMAT,
45-
datefmt="[%X]",
46-
handlers=[rich.logging.RichHandler(level=log_level)],
26+
ch = logging.StreamHandler()
27+
ch.setLevel(level_value)
28+
# create formatter and add it to the handlers
29+
formatter = logging.Formatter(
30+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
4731
)
48-
49-
rich.traceback.install(suppress=["pep517", "pip"])
32+
ch.setFormatter(formatter)
33+
# add the handlers to the logger
34+
logger.addHandler(ch)

tests/conftest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path:
4848
"hatchling",
4949
"pip>=23",
5050
"pybind11",
51-
"rich",
5251
"setuptools",
5352
"virtualenv",
5453
"wheel",
@@ -223,10 +222,10 @@ def package_simple_pyproject_ext(
223222
) -> PackageInfo:
224223
package = PackageInfo(
225224
"simple_pyproject_ext",
226-
"920c8475bf53c67231dbe3a08c1b533306e89f79dfbd09c1fe2ec55ec6c8fe0c",
227-
"617737581c2e6f42137539c46c0bf904ea43a7b653925dbbcf8dce88e4a835a8",
228-
"b41badc7999eddd2f4a59aa244baa04b9498d699888c2ced33655396108616a4",
229-
"2fb6482b83f624d1fe83e30579f9507167e1db9e5256bc0f47a907abb9ae98ec",
225+
"cbf3102cf86f709dfd3f244b69e5ee3faff9e3c94c53ef85f146d9bad96660b3",
226+
"538a8221e10c5029c78127e4169d2df622b9a88dfce12a8b63eeaaa98cda8a09",
227+
"0dab37b48497f95c044781204b7d49c752739b32a0ef7a7a02ec987b5c4a210b",
228+
"feeedcb0070a211d93b967fe083aa31e448842eb9b93d5e428807348e40e44e8",
230229
)
231230
process_package(package, tmp_path, monkeypatch)
232231
return package
@@ -306,7 +305,6 @@ def pytest_report_header() -> str:
306305
"pip",
307306
"pybind11",
308307
"pyproject_metadata",
309-
"rich",
310308
"scikit_build_core",
311309
"setuptools",
312310
"virtualenv",

tests/packages/simple_pyproject_ext/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"scikit_build_core[rich]",
3+
"scikit_build_core[pyproject]",
44
"pybind11",
55
]
66
build-backend = "scikit_build_core.build"

tests/packages/simple_pyproject_source_dir/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"scikit_build_core[rich]",
3+
"scikit_build_core[pyproject]",
44
"pybind11",
55
]
66
build-backend = "scikit_build_core.build"

tests/test_logging.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from scikit_build_core._logging import fake_rich_print
1+
from scikit_build_core._logging import rich_print
22

33

4-
def test_fake_rich_print_nocolor(capsys, monkeypatch):
4+
def test_rich_print_nocolor(capsys, monkeypatch):
55
monkeypatch.setenv("NO_COLOR", "1")
6-
fake_rich_print("[red]hello[/red] world", end="")
6+
rich_print("[red]hello[/red] world", end="")
77
assert capsys.readouterr().out == "hello world"
88

99

10-
def test_fake_rich_print_forcecolor(capsys, monkeypatch):
10+
def test_rich_print_forcecolor(capsys, monkeypatch):
1111
monkeypatch.setenv("FORCE_COLOR", "1")
12-
fake_rich_print("[red bold]hello[/bold] world", end="")
12+
rich_print("[red bold]hello[/bold] world", end="")
1313
assert capsys.readouterr().out == "\33[91m\33[1mhello\33[22m world\33[0m"

0 commit comments

Comments
 (0)