Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .gitignore

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies = [
"pandas>=2.0",
"pyyaml>=6.0",
"tenacity>=8.2",
"filelock>=3.12",
]

[project.optional-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions src/alphaevo/data/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from __future__ import annotations

import contextlib
import fcntl
import logging
import time
from collections.abc import Iterator
Expand All @@ -20,6 +19,7 @@
from pathlib import Path

import pandas as pd # type: ignore[import-untyped]
from filelock import FileLock

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -162,19 +162,15 @@ def put(self, symbol: str, start: date, end: date, df: pd.DataFrame) -> None:
@staticmethod
@contextmanager
def _file_lock(target: Path) -> Iterator[None]:
"""Acquire an exclusive file lock adjacent to *target*."""
"""Acquire an exclusive file lock adjacent to *target* (cross-platform)."""
lock_path = target.with_suffix(target.suffix + ".lock")
lock_path.parent.mkdir(parents=True, exist_ok=True)
fd = lock_path.open("w")
try:
fcntl.flock(fd, fcntl.LOCK_EX)
lock = FileLock(str(lock_path))
with lock:
yield
finally:
fcntl.flock(fd, fcntl.LOCK_UN)
fd.close()
# Best-effort cleanup; race with other processes is harmless
with contextlib.suppress(OSError):
lock_path.unlink()
# Best-effort cleanup; race with other processes is harmless
with contextlib.suppress(OSError):
lock_path.unlink()

def invalidate(self, symbol: str | None = None) -> int:
"""Clear cached data.
Expand Down