rules_zapp/zapp/support/manifest.py

39 lines
667 B
Python
Raw Normal View History

2021-08-09 15:26:06 +00:00
"""The Zapp runtime manifest API."""
import json
2021-08-09 15:26:06 +00:00
from copy import deepcopy
from importlib.resources import open_text
def once(f):
singleton = object()
state = singleton
def helper(*args, **kwargs):
nonlocal state
if state is singleton:
state = f(*args, **kwargs)
return state
return helper
def copied(f):
def helper(*args, **kwargs):
val = f(*args, **kwargs)
return deepcopy(val)
return helper
2021-08-09 15:26:06 +00:00
@copied
@once
2021-08-09 15:26:06 +00:00
def manifest():
"""Return (a copy) of the runtime manifest."""
with open_text("zapp", "manifest.json") as fp:
return json.load(fp)
2021-08-09 15:26:06 +00:00
__all__ = ["manifest"]