Skip to content

Commit

Permalink
Only read config file once. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
GDWR authored Jan 22, 2022
1 parent 6247857 commit 071c132
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions classy_config/classy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class ClassyConfig:
instance: Optional["ClassyConfig"] = None
_raw_config: Optional[dict] = None

def __new__(cls, *args, **kwargs):
if cls.instance is not None:
Expand All @@ -19,8 +20,11 @@ def __init__(self, config_file: Union[str, PathLike]):
self.config_file = config_file

def _get_raw_config_file(self) -> dict:
with open(self.config_file, "r") as f:
return json.load(f)
if self._raw_config is None:
with open(self.config_file, "r") as f:
self._raw_config = json.load(f)

return self._raw_config

@property
def raw_config(self) -> dict:
Expand Down

0 comments on commit 071c132

Please sign in to comment.