Clean accidental output in notebook, remove ProgressPrinter (obsolete)

This commit is contained in:
Maximilian Schmeller 2022-09-15 15:26:32 +02:00
parent 8bc3a5f69e
commit 7d3e957ed9
2 changed files with 261 additions and 7398 deletions

View file

@ -1,15 +1,11 @@
import base64
import glob
import hashlib import hashlib
import json import json
import math
import os import os
import pickle import pickle
import time
from typing import List from typing import List
from IPython.core.magic import (register_cell_magic, needs_local_scope)
from IPython import get_ipython from IPython import get_ipython
from IPython.core.magic import (register_cell_magic, needs_local_scope)
@register_cell_magic @register_cell_magic
@ -26,33 +22,6 @@ def left_abbreviate(string, limit=120):
return string if len(string) <= limit else f"...{string[:limit - 3]}" return string if len(string) <= limit else f"...{string[:limit - 3]}"
class ProgressPrinter:
def __init__(self, verb, n) -> None:
self.verb = verb
self.n = n
self.i = 0
self.fmt_len = math.ceil(math.log10(n if n > 0 else 1))
def step(self, msg):
self.i += 1
print(f"({self.i:>{self.fmt_len}d}/{self.n}) {self.verb} {left_abbreviate(msg):<120}", end="\r")
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
self.i -= 1
if exc_value:
self.step("error.")
print()
print(exc_value)
return
self.step("done.")
print()
def stable_hash(obj): def stable_hash(obj):
return hashlib.md5(json.dumps(obj).encode("utf-8")).hexdigest()[:10] return hashlib.md5(json.dumps(obj).encode("utf-8")).hexdigest()[:10]
@ -65,6 +34,7 @@ def parse_as(type, string):
return type(val) return type(val)
raise ValueError(f"Unknown type {type.__name__}") raise ValueError(f"Unknown type {type.__name__}")
def cached(name, function, file_deps: List[str]): def cached(name, function, file_deps: List[str]):
if not os.path.isdir("cache"): if not os.path.isdir("cache"):
os.makedirs("cache", exist_ok=True) os.makedirs("cache", exist_ok=True)

File diff suppressed because it is too large Load diff