Skip to content

Commit

Permalink
fix bug when load configs
Browse files Browse the repository at this point in the history
  • Loading branch information
胡霁 authored and ice-black-tea committed Apr 12, 2023
1 parent d939f98 commit 3237d83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
13 changes: 10 additions & 3 deletions src/linktools/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@

class _Loader(abc.ABC):

@abc.abstractmethod
def load(self, env: BaseEnviron, key: any):
try:
return self._load(env, key)
except Exception as e:
env.logger.error(f"Load config \"{key}\" error", exc_info=e)
raise e

@abc.abstractmethod
def _load(self, env: BaseEnviron, key: any):
pass


Expand All @@ -68,7 +75,7 @@ def __init__(
self.type = type
self.trim = trim

def load(self, env: BaseEnviron, key: any):
def _load(self, env: BaseEnviron, key: any):
if issubclass(self.type, str):
prompt = Prompt
elif issubclass(self.type, int):
Expand Down Expand Up @@ -133,7 +140,7 @@ class _Lazy(_Loader):
def __init__(self, func: Callable[[BaseEnviron], Any]):
self.func = func

def load(self, env: BaseEnviron, key: any):
def _load(self, env: BaseEnviron, key: any):
return self.func(env)


Expand Down
8 changes: 4 additions & 4 deletions src/linktools/_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ def data_path(self):
"""
存放文件目录
"""
path = self.get_config("DATA_PATH")
path = self.get_config("DATA_PATH", type=str)
if not path:
path = os.path.join(self.get_config("STORAGE_PATH"), "data")
path = os.path.join(self.get_config("STORAGE_PATH", type=str), "data")
return path

@cached_property
def temp_path(self):
"""
存放临时文件目录
"""
path = self.get_config("TEMP_PATH")
path = self.get_config("TEMP_PATH", type=str)
if not path:
path = os.path.join(self.get_config("STORAGE_PATH"), "temp")
path = os.path.join(self.get_config("STORAGE_PATH", type=str), "temp")
return path

@classmethod
Expand Down
21 changes: 4 additions & 17 deletions src/linktools/utils/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,18 @@ def _get_current_object(self):

@property
def __dict__(self):
try:
return self._get_current_object().__dict__
except RuntimeError: # pragma: no cover
raise AttributeError('__dict__')
return self._get_current_object().__dict__

def __repr__(self):
try:
obj = self._get_current_object()
except RuntimeError: # pragma: no cover
return '<{0} unbound>'.format(self.__class__.__name__)
return repr(obj)
return repr(self._get_current_object())

def __bool__(self):
try:
return bool(self._get_current_object())
except RuntimeError: # pragma: no cover
return False
return bool(self._get_current_object())

__nonzero__ = __bool__ # Py2

def __dir__(self):
try:
return dir(self._get_current_object())
except RuntimeError: # pragma: no cover
return []
return dir(self._get_current_object())

def __getattr__(self, name):
if name == '__members__':
Expand Down

0 comments on commit 3237d83

Please sign in to comment.