From 2c7025443b68647bb4bef7bdedd76ffe1cbdce0b Mon Sep 17 00:00:00 2001 From: AndrewXu Date: Tue, 26 Apr 2022 18:27:41 +0800 Subject: [PATCH] Update autodiscovery function for windows --- src/en/guide/how-to/autodiscovery.md | 4 +++- src/ja/guide/how-to/autodiscovery.md | 4 +++- src/zh/guide/how-to/autodiscovery.md | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/en/guide/how-to/autodiscovery.md b/src/en/guide/how-to/autodiscovery.md index 4cf319357b..1b09b07658 100644 --- a/src/en/guide/how-to/autodiscovery.md +++ b/src/en/guide/how-to/autodiscovery.md @@ -52,6 +52,7 @@ from inspect import getmembers from pathlib import Path from types import ModuleType from typing import Union +import os from sanic.blueprints import Blueprint @@ -82,7 +83,8 @@ def autodiscover( if path not in _imported: name = "module" if "__init__" in path: - *_, name, __ = path.split("/") + sep = "\\" if os.name == 'nt' else "/" + *_, name, __ = path.split(sep) spec = util.spec_from_file_location(name, path) specmod = util.module_from_spec(spec) _imported.add(path) diff --git a/src/ja/guide/how-to/autodiscovery.md b/src/ja/guide/how-to/autodiscovery.md index 74663a4228..3004cbaf63 100644 --- a/src/ja/guide/how-to/autodiscovery.md +++ b/src/ja/guide/how-to/autodiscovery.md @@ -52,6 +52,7 @@ from inspect import getmembers from pathlib import Path from types import ModuleType from typing import Union +import os from sanic.blueprints import Blueprint @@ -82,7 +83,8 @@ def autodiscover( if path not in _imported: name = "module" if "__init__" in path: - *_, name, __ = path.split("/") + sep = "\\" if os.name == 'nt' else "/" + *_, name, __ = path.split(sep) spec = util.spec_from_file_location(name, path) specmod = util.module_from_spec(spec) _imported.add(path) diff --git a/src/zh/guide/how-to/autodiscovery.md b/src/zh/guide/how-to/autodiscovery.md index 050b5bf492..fd7acc8568 100644 --- a/src/zh/guide/how-to/autodiscovery.md +++ b/src/zh/guide/how-to/autodiscovery.md @@ -58,6 +58,7 @@ from inspect import getmembers from pathlib import Path from types import ModuleType from typing import Union +import os from sanic.blueprints import Blueprint @@ -88,7 +89,8 @@ def autodiscover( if path not in _imported: name = "module" if "__init__" in path: - *_, name, __ = path.split("/") + sep = "\\" if os.name == 'nt' else "/" + *_, name, __ = path.split(sep) spec = util.spec_from_file_location(name, path) specmod = util.module_from_spec(spec) _imported.add(path)