Skip to content

Commit b674c21

Browse files
committed
use resources
1 parent 5ef96af commit b674c21

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
1-
"""
2-
Lua scripts for distributed semaphore operations.
3-
4-
This module loads and manages Redis Lua scripts for atomic semaphore operations.
5-
The scripts are stored in individual .lua files in the lua/ subfolder.
6-
"""
7-
8-
import pathlib
1+
from importlib import resources
92
from typing import Final
103

11-
# Path to the lua scripts directory
12-
_LUA_DIR = pathlib.Path(__file__).parent / "lua"
13-
144

155
def _load_script(script_name: str) -> str:
16-
"""Load a Lua script from the lua/ directory."""
17-
script_file = _LUA_DIR / f"{script_name}.lua"
18-
if not script_file.exists():
19-
msg = f"Lua script file not found: {script_file}"
20-
raise FileNotFoundError(msg)
21-
return script_file.read_text(encoding="utf-8").strip()
6+
with resources.path("servicelib", f"redis.lua.{script_name}ga") as script_file:
7+
return script_file.read_text(encoding="utf-8").strip()
228

239

24-
# Load individual scripts
2510
ACQUIRE_SEMAPHORE_SCRIPT: Final[str] = _load_script("acquire_semaphore")
2611
RELEASE_SEMAPHORE_SCRIPT: Final[str] = _load_script("release_semaphore")
2712
RENEW_SEMAPHORE_SCRIPT: Final[str] = _load_script("renew_semaphore")
2813
COUNT_SEMAPHORE_SCRIPT: Final[str] = _load_script("count_semaphore")
29-
30-
__all__ = [
31-
"ACQUIRE_SEMAPHORE_SCRIPT",
32-
"COUNT_SEMAPHORE_SCRIPT",
33-
"RELEASE_SEMAPHORE_SCRIPT",
34-
"RENEW_SEMAPHORE_SCRIPT",
35-
]

0 commit comments

Comments
 (0)