Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed May 29, 2024
1 parent b6c9582 commit ab08964
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cacholote/extra_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ def _filesystem_is_local(fs: fsspec.AbstractFileSystem) -> bool:
return isinstance(fs, fsspec.get_filesystem_class("file"))


def _kwargs_to_str(**kwargs: Any) -> str:
return " ".join([f"{k}={v}" for k, v in kwargs.items()])


@contextlib.contextmanager
def _logging_timer(event: str, **kwargs: Any) -> Generator[float, None, None]:
logger = config.get().logger
context = config.get().context
logger.info(f"start {event}", **kwargs)
if event == "upload" and context is not None:
suffix = " ".join([f"{k}: {v}" for k, v in kwargs.items()])
context.upload_log(f"start {event}. {suffix}")
context.upload_log(f"start {event}. {_kwargs_to_str(**kwargs)}")

tic = time.perf_counter()
yield tic
Expand All @@ -127,8 +130,7 @@ def _logging_timer(event: str, **kwargs: Any) -> Generator[float, None, None]:
kwargs["_".join(event.split() + ["time"])] = toc - tic # elapsed time
logger.info(f"end {event}", **kwargs)
if event == "upload" and context is not None:
suffix = " ".join([f"{k}: {v}" for k, v in kwargs.items()])
context.upload_log(f"end {event}. {suffix}")
context.upload_log(f"end {event}. {_kwargs_to_str(**kwargs)}")


class FileInfoModel(pydantic.BaseModel):
Expand Down

0 comments on commit ab08964

Please sign in to comment.