Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP: drop dependency on rich (replaced by atomic dependencies termcolor + tqdm) #375

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading