提交 ce342854 编写于 作者: W wuzewu

Add get_py_requirments in module

上级 6a34a538
......@@ -57,12 +57,13 @@ def serving(func: Callable) -> Callable:
class Module(object):
def __new__(cls, name: str = None, directory: str = None, version: str = None, **kwargs):
if cls.__name__ == 'Module':
# This branch come from hub.Module(name='xxx')
if name:
module = cls.init_with_name(name=name, version=version, **kwargs)
elif directory:
module = cls.init_with_directory(directory=directory, **kwargs)
else:
raise RuntimeError()
module = object.__new__(cls)
module.directory = directory
return module
......@@ -105,6 +106,15 @@ class Module(object):
user_module_cls = cls.load(directory)
return user_module_cls(**kwargs)
@classmethod
def get_py_requirments(cls):
req_file = os.path.join(cls.directory, 'requirements.txt')
if not os.path.exists(req_file):
return []
with open(req_file, 'r') as file:
return file.read().split('\n')
class RunModule(object):
def __init__(self, *args, **kwargs):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册