Skip to content

Commit

Permalink
3.2.5 - changes for pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed May 15, 2024
1 parent 6bcaef4 commit 8171cb3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 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.2.4
repo=vcorelib version=3.2.5
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=bc0b27e02d365bc98f792016fb5c40a1
hash=80fddc32b8f7fd652a35b06893040c4f
=====================================
-->

# vcorelib ([3.2.4](https://pypi.org/project/vcorelib/))
# vcorelib ([3.2.5](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: 2
patch: 4
patch: 5
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.2.4"
version = "3.2.5"
description = "A collection of core Python utilities."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
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=72f33cb7eb34d1a8b0e94f5741c13762
# hash=113ebb11de1d2d1e27480859c3aa1bfa
# =====================================

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

DESCRIPTION = "A collection of core Python utilities."
PKG_NAME = "vcorelib"
VERSION = "3.2.4"
VERSION = "3.2.5"

# vcorelib-specific content.
DEFAULT_INDENT = 2
Expand Down
16 changes: 10 additions & 6 deletions vcorelib/io/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

# built-in
from contextlib import contextmanager
from contextlib import ExitStack, contextmanager
from enum import Enum, auto
from io import StringIO
import os
Expand Down Expand Up @@ -124,11 +124,15 @@ def temporary(
) -> Iterator["IndentedFileWriter"]:
"""Create an instance from a temporary file as a managed context."""

with tempfile() as tmp:
with IndentedFileWriter.from_path(
tmp, space=space, per_indent=per_indent, **kwargs
) as writer:
yield writer
with ExitStack() as stack:
yield stack.enter_context(
IndentedFileWriter.from_path(
stack.enter_context(tempfile()),
space=space,
per_indent=per_indent,
**kwargs,
)
)

def write(self, data: str) -> int:
"""
Expand Down
36 changes: 26 additions & 10 deletions vcorelib/paths/info_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

# built-in
from contextlib import ExitStack as _ExitStack
from contextlib import contextmanager as _contextmanager
import logging as _logging
from pathlib import Path as _Path
Expand All @@ -15,6 +16,7 @@

# internal
from vcorelib.dict.cache import FileCache
from vcorelib.io.types import JsonObject as _JsonObject
from vcorelib.math.time import LoggerType
from vcorelib.paths import Pathlike as _Pathlike
from vcorelib.paths import normalize as _normalize
Expand Down Expand Up @@ -201,6 +203,24 @@ def poll_file(
self._handle_info(norm, info)


@_contextmanager
def file_info_manager(
data: _JsonObject, poll_cb: FileChangedCallback, **kwargs
) -> _Iterator[FileInfoManager]:
"""Create a file-info manager as a managed context."""

manager = FileInfoManager(
poll_cb, FileInfo.from_json(data, force=True), **kwargs
)
try:
yield manager
finally:
# Update dictionary data with the current cache contents.
data.clear()
for info in manager.infos.values():
info.to_json(data)


@_contextmanager
def file_info_cache(
cache_path: _Pathlike,
Expand All @@ -213,17 +233,13 @@ def file_info_cache(

path = _normalize(cache_path)
assert not path.is_dir(), f"'{path}' is a directory!"
with FileCache(path).loaded() as data:
manager = FileInfoManager(

with _ExitStack() as stack:
with file_info_manager(
stack.enter_context(FileCache(path).loaded()),
poll_cb,
FileInfo.from_json(data, force=True),
logger=logger,
level=level,
check_contents=check_contents,
)
yield manager

# Update dictionary data with the current cache contents.
data.clear()
for info in manager.infos.values():
info.to_json(data)
) as manager:
yield manager

0 comments on commit 8171cb3

Please sign in to comment.