Skip to content

Commit

Permalink
add root_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-black-tea committed Apr 16, 2023
1 parent 17c8ce2 commit 28f780d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/linktools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def run(self, args: [str]) -> Optional[int]:
node.add(f"👉 {command.category.prefix}[bold red]{command.name}[/bold red]: {command.description}")

console = get_console()
if environ.description:
if environ.description != NotImplemented:
console.print(environ.description, highlight=False)
console.print(tree, highlight=False)

Expand Down
22 changes: 19 additions & 3 deletions src/linktools/_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,21 @@ def version(self) -> str:
"""
模块版本号
"""
return ""
return NotImplemented

@property
def description(self) -> str:
"""
模块描述
"""
return ""
return NotImplemented

@property
def root_path(self):
"""
模块路径
"""
raise NotImplemented

@cached_property
def data_path(self):
Expand Down Expand Up @@ -278,6 +285,14 @@ def _get_path(cls, root_path: str, *paths: [str], create: bool = False, create_p
os.makedirs(dir_path)
return target_path

def get_path(self, *paths: str):
"""
获取模块目录下的子路径
"""
if self.root_path == NotImplemented:
raise RuntimeError("root_path not implemented")
return self._get_path(self.root_path, *paths)

def get_data_path(self, *paths: str, create_parent: bool = False):
"""
获取数据目录下的子路径
Expand Down Expand Up @@ -435,7 +450,7 @@ def update_config_from_file(self, path: str) -> bool:
self.logger.debug(f"Unsupported config file: {path}")
return False

def update_config_from_directory(self, path: str, recursion: bool = False) -> bool:
def update_config_from_dir(self, path: str, recursion: bool = False) -> bool:
"""
加载配置文件目录,按照扩展名来匹配相应的加载规则
"""
Expand Down Expand Up @@ -572,6 +587,7 @@ class Environ(BaseEnviron):
name = __module_name__
version = __module_version__
description = __module_description__
root_path = root_path

def _init_config(self, config: Config):
# 初始化下载相关参数
Expand Down
4 changes: 2 additions & 2 deletions src/linktools/cli/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def parse_known_args(self, args: List[str] = None) -> Tuple[Namespace, List[str]
@cached_property
def _argument_parser(self) -> ArgumentParser:
description = self.description.strip()
if description and self.environ.description:
if description and self.environ.description != NotImplemented:
description += os.linesep + os.linesep
description += self.environ.description

Expand Down Expand Up @@ -137,7 +137,7 @@ def __call__(self, parser, namespace, values, option_string=None):
if option_string in self.option_strings:
command_self.environ.show_log_level = not option_string.startswith("--no-")

if self.environ.version:
if self.environ.version != NotImplemented:
parser.add_argument("--version", action="version", version=self.environ.version)

group = parser.add_argument_group(title="log arguments")
Expand Down

0 comments on commit 28f780d

Please sign in to comment.