Skip to content

Commit

Permalink
Merge pull request #375 from neutrinoceros/dep/drop_rich
Browse files Browse the repository at this point in the history
DEP: drop dependency on `rich` (replaced by atomic dependencies `termcolor` + `tqdm`)
  • Loading branch information
neutrinoceros authored Dec 16, 2024
2 parents 4690ca6 + 9bdbb59 commit 026e270
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
36 changes: 22 additions & 14 deletions nonos/logging.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
import sys
import unicodedata
from typing import Union

from loguru import logger
from rich import print as rprint
from rich.logging import RichHandler
from termcolor import cprint

_BONE_EMOJI = unicodedata.lookup("BONE")


def configure_logger(level: Union[int, str] = 30, **kwargs) -> None:
logger.remove() # remove pre-existing handler
logger.add(
RichHandler(
log_time_format="[%X] nonos",
omit_repeated_times=False,
),
format="{message}",
sink=sys.stdout,
format="[{time:HH:mm:ss}] nonos <level>{level:<8}</level> {message}",
level=level,
**kwargs,
)


def print_warn(message) -> None:
"""
adapted from idefix_cli (cmt robert)
https://github.com/neutrinoceros/idefix_cli
Pretty-print a warning.
"""
rprint(f":bone: [bold red]Warning[/] {message}", file=sys.stderr)
print(_BONE_EMOJI, end=" ", file=sys.stderr)
cprint("Warning", color="red", attrs=["bold"], end=" ", file=sys.stderr)
print(message, file=sys.stderr)


def print_err(message) -> None:
"""
adapted from idefix_cli (cmt robert)
https://github.com/neutrinoceros/idefix_cli
Pretty-print an error message.
"""
rprint(f":bone: [bold white on red]Error[/] {message}", file=sys.stderr)
print(_BONE_EMOJI, end=" ", file=sys.stderr)
cprint(
"Error",
color="white",
on_color="on_red",
attrs=["bold"],
end=" ",
file=sys.stderr,
)
print(message, file=sys.stderr)


def parse_verbose_level(verbose: int) -> str:
Expand All @@ -41,4 +49,4 @@ def parse_verbose_level(verbose: int) -> str:
return level


configure_logger(level=30)
configure_logger(level="WARNING")
14 changes: 5 additions & 9 deletions nonos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import importlib.resources as importlib_resources
import os
import re
import sys
import time
from collections import ChainMap
from importlib import import_module
Expand All @@ -21,6 +22,7 @@
import inifix
import numpy as np
from packaging.version import Version
from tqdm import tqdm

from nonos.api import GasDataSet
from nonos.api._angle_parsing import _parse_planet_file
Expand Down Expand Up @@ -588,17 +590,11 @@ def main(argv: Optional[list[str]] = None) -> int:
log_level=level,
)

if args["progressBar"]:
from rich.progress import track
else:
# replace rich.progress.track with a no-op dummy
def track(it, *_args, **_kwargs): # type: ignore [misc]
return it

progress = functools.partial(
track,
description="Processing snapshots",
tqdm if args["progressBar"] else lambda it, *_arg, **_kwargs: it,
desc="Processing snapshots",
total=len(args["on"]),
file=sys.stdout,
)

logger.info("Starting main loop")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ dependencies = [
"matplotlib>=3.5.0",
"numpy>=1.19.3",
"packaging>=20.0",
"rich>=10.13.0",
"scipy>=1.6.1",
"termcolor>=2.1.0",
"tqdm>=4.64.1",
"typing_extensions >= 4.4.0 ; python_version < '3.12'",
]

Expand Down

0 comments on commit 026e270

Please sign in to comment.