diff --git a/src/linktools/__main__.py b/src/linktools/__main__.py index e2d059d8..9cec009b 100644 --- a/src/linktools/__main__.py +++ b/src/linktools/__main__.py @@ -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) diff --git a/src/linktools/_environ.py b/src/linktools/_environ.py index 23c30b06..6e0ec691 100644 --- a/src/linktools/_environ.py +++ b/src/linktools/_environ.py @@ -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): @@ -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): """ 获取数据目录下的子路径 @@ -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: """ 加载配置文件目录,按照扩展名来匹配相应的加载规则 """ @@ -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): # 初始化下载相关参数 diff --git a/src/linktools/cli/_command.py b/src/linktools/cli/_command.py index 88e8a8a9..a23900c0 100644 --- a/src/linktools/cli/_command.py +++ b/src/linktools/cli/_command.py @@ -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 @@ -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")