mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-03-01 11:44:09 +08:00
16 lines
419 B
Python
16 lines
419 B
Python
|
from pathlib import Path
|
||
|
|
||
|
|
||
|
def path_to_module_name(path: Path) -> str:
|
||
|
"""
|
||
|
转换路径为模块名
|
||
|
Args:
|
||
|
path: 路径a/b/c/d -> a.b.c.d
|
||
|
Returns:
|
||
|
str: 模块名
|
||
|
"""
|
||
|
rel_path = path.resolve().relative_to(Path.cwd().resolve())
|
||
|
if rel_path.stem == "__init__":
|
||
|
return ".".join(rel_path.parts[:-1])
|
||
|
else:
|
||
|
return ".".join(rel_path.parts[:-1] + (rel_path.stem,))
|