Skip to content

Commit 36f0a97

Browse files
Merge pull request #221 from simvue-io/215-colorama-formatting-of-log-messages-makes-performance-drop
Switch from `colorama` to `click`
2 parents 0767f62 + 61cd446 commit 36f0a97

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

poetry.lock

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ torch = {version = "^2.1.2", python = "<3.12", optional = true}
2121
numpy = {version = "^1.26.3", optional = true}
2222
matplotlib = {version = "^3.8.2", optional = true}
2323
toml = "^0.10.2"
24-
colorama = "^0.4.6"
24+
click = "^8.1.7"
2525

2626
[tool.poetry.extras]
2727
dataset = ["pandas", "numpy"]

simvue/run.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
import typing
1414
import uuid
1515

16+
import click
1617
from pydantic import ValidationError
1718

1819
from .executor import Executor
1920
from .factory import Simvue
2021
from .models import RunInput
2122
from .serialization import Serializer
22-
from .utilities import get_auth, get_expiry, print_nice
23+
from .utilities import get_auth, get_expiry
2324
from .worker import Worker
2425

2526
INIT_MISSING = "initialize a run using init() first"
@@ -379,9 +380,11 @@ def init(
379380
self._start()
380381

381382
if self._mode == "online":
382-
print_nice(f"Run {self._name} created")
383-
print_nice(
384-
f"Monitor in the UI at {self._url}/dashboard/runs/run/{self._id}"
383+
click.secho(f"[simvue] Run {self._name} created", bold=True, fg="green")
384+
click.secho(
385+
f"[simvue] Monitor in the UI at {self._url}/dashboard/runs/run/{self._id}",
386+
bold=True,
387+
fg="green",
385388
)
386389

387390
return True
@@ -781,7 +784,11 @@ def save(
781784
data["checksum"] = calculate_sha256(filename, is_file)
782785

783786
if data["size"] == 0:
784-
print("WARNING: saving zero-sized files not currently supported")
787+
click.secho(
788+
"WARNING: saving zero-sized files not currently supported",
789+
bold=True,
790+
fg="yellow",
791+
)
785792
return True
786793

787794
# Determine mimetype

simvue/utilities.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import typing
55

66
import jwt
7-
from colorama import Fore, Style, init
87

98
logger = logging.getLogger(__name__)
109

@@ -182,12 +181,3 @@ def prepare_for_api(data_in, all=True):
182181
if "pickledFile" in data and all:
183182
del data["pickledFile"]
184183
return data
185-
186-
187-
def print_nice(message):
188-
"""
189-
Log message in a way which hopefully can be distiguished from the user's application
190-
"""
191-
init(autoreset=True)
192-
print(Fore.GREEN + Style.BRIGHT + f"[simvue] {message}")
193-
return

tests/refactor/test_scenarios.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
import simvue
3+
import time
4+
import contextlib
5+
6+
@pytest.mark.scenario
7+
def test_time_multi_run_create_threshold() -> None:
8+
start = time.time()
9+
for i in range(20):
10+
with simvue.Run() as run:
11+
run.init(f"test run {i}", tags=["test_benchmarking"], folder="/simvue_benchmark_testing")
12+
print(f"Run {i}")
13+
end = time.time()
14+
client = simvue.Client()
15+
with contextlib.suppress(RuntimeError):
16+
client.delete_runs("/simvue_benchmark_testing")
17+
client.delete_folder("/simvue_benchmark_testing", remove_runs=False, allow_missing=True, recursive=True)
18+
assert start - end < 60.

0 commit comments

Comments
 (0)