for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
"""
Temporary caching of search results as they progress.
from pathlib import Path
from typing import Iterator, Sequence
import orjson
from suretime import Suretime
from mandos import logger
class SearchCache:
def __init__(self, path: Path, compounds: Sequence[str]):
self._path = path
if self._meta_path.exists():
self._data = orjson.loads(self._meta_path.read_text(encoding="utf8"))
logger.caution(f"Resuming {path} with {self.at} completed compounds")
else:
self._data = dict(
start=Suretime.tagged.now_utc_sys().iso, last=None, path=self.path, done=set()
)
logger.debug(f"Starting fresh cache for {path}")
self._queue: Iterator[str] = iter([c for c in compounds if c not in self._data["done"]])
def next(self) -> str:
return next(self._queue)
def save(self, *compounds: str) -> None:
for c in compounds:
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.
self._data["done"].add(c)
data = orjson.dumps(self._data).decode(encoding="utf8")
self._meta_path.write_text(data)
logger.debug(f"Saved to {self._meta_path}")
@property
def path(self) -> Path:
return self._path
def at(self) -> int:
return len(self._data["done"])
def _meta_path(self) -> Path:
return self._path.parent / (self._path.name + ".meta.json.tmp")
def kill(self) -> None:
self._data = None
self._meta_path.unlink()
logger.debug(f"Destroyed search cache {self._meta_path}")
__all__ = ["SearchCache"]