Skip to content

Commit

Permalink
3.1.2 - Add 'reminder' option to log_time
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Feb 5, 2024
1 parent ef49b98 commit f84efee
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=vcorelib version=3.1.1
repo=vcorelib version=3.1.2
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=7ab5d1d2a66be7d073b2e54867f1a00b
hash=0a5055e578605ab71fde102b8a09f678
=====================================
-->

# vcorelib ([3.1.1](https://pypi.org/project/vcorelib/))
# vcorelib ([3.1.2](https://pypi.org/project/vcorelib/))

[![python](https://img.shields.io/pypi/pyversions/vcorelib.svg)](https://pypi.org/project/vcorelib/)
![Build Status](https://github.com/vkottler/vcorelib/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
major: 3
minor: 1
patch: 1
patch: 2
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "vcorelib"
version = "3.1.1"
version = "3.1.2"
description = "A collection of core Python utilities."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion tests/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class LoggerMixinTest(
inst = LoggerMixinTest()
inst.logger.info("This is a test, %d %d %d.", 1, 2, 3)

with inst.log_time("Hello, %s! %d", "world", 5):
with inst.log_time("Hello, %s! %d", "world", 5, reminder=True):
for _ in range(100):
pass
4 changes: 2 additions & 2 deletions vcorelib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=80882171e67a9c4110c185bc462e89bf
# hash=b823edee2e3d551b72d4f1a97a0bba32
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A collection of core Python utilities."
PKG_NAME = "vcorelib"
VERSION = "3.1.1"
VERSION = "3.1.2"

# vcorelib-specific content.
DEFAULT_INDENT = 2
Expand Down
8 changes: 5 additions & 3 deletions vcorelib/io/arbiter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ def decode(
# external code to treat data files as templates.
result = self.decode_stream(
get_file_ext(path, maxsplit=maxsplit),
preprocessor(path_fd)
if preprocessor is not None
else path_fd,
(
preprocessor(path_fd)
if preprocessor is not None
else path_fd
),
logger,
**kwargs,
)
Expand Down
11 changes: 10 additions & 1 deletion vcorelib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ def log_time(
message: str,
*args,
level: int = _INFO,
reminder: bool = False,
**kwargs,
) -> _Iterator[None]:
"""A simple wrapper."""
with log_time(self.logger, message, *args, level=level, **kwargs):

with log_time(
self.logger,
message,
*args,
level=level,
reminder=reminder,
**kwargs,
):
yield
5 changes: 4 additions & 1 deletion vcorelib/logging/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ def log_time(
message: str,
*args,
level: int = _INFO,
reminder: bool = False,
**kwargs,
) -> _Iterator[None]:
"""
A simple context manager for conveniently logging time taken for a task.
"""
with TIMER.log(log, message, *args, level=level, **kwargs):
with TIMER.log(
log, message, *args, level=level, reminder=reminder, **kwargs
):
yield
4 changes: 4 additions & 0 deletions vcorelib/math/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ def log(
message: str,
*args,
level: int = _INFO,
reminder: bool = False,
**kwargs,
) -> _Iterator[None]:
"""Log how long the caller's context took to execute."""

if reminder:
log.log(level, message + " is executing.", *args, **kwargs)

with self.measure_ns() as token:
yield
result = self.result(token)
Expand Down

0 comments on commit f84efee

Please sign in to comment.