Minor fix on path to make it work in Windows (#2494)

This commit is contained in:
Tianze 2024-02-01 02:00:41 +08:00 committed by GitHub
parent 84a2bb9671
commit a14575009c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -703,7 +703,8 @@ class PyiGenerator:
current_module: Any = {}
def _write_pyi_file(self, module_path: Path, source: str):
relpath = _relative_to_pwd(module_path)
relpath = str(_relative_to_pwd(module_path)).replace("\\", "/")
print(f"Writing {relpath}")
pyi_content = [
f'"""Stub file for {relpath}"""',
"# ------------------- DO NOT EDIT ----------------------",
@ -731,9 +732,12 @@ class PyiGenerator:
logger.info(f"Wrote {relpath}")
def _scan_file(self, module_path: Path):
# module_import = str(module_path.with_suffix("")).replace("/", ".")
module_import = (
_relative_to_pwd(module_path).with_suffix("").as_posix().replace("/", ".")
_relative_to_pwd(module_path)
.with_suffix("")
.as_posix()
.replace("/", ".")
.replace("\\", ".")
)
module = importlib.import_module(module_import)
logger.debug(f"Read {module_path}")