Upload edit\Qwen3-TTS-test\.venv\Lib\site-packages\__editable___qwen_tts_0_1_1_finder.py with huggingface_hub
Browse files
edit//Qwen3-TTS-test//.venv//Lib//site-packages//__editable___qwen_tts_0_1_1_finder.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
import sys
|
| 3 |
+
from importlib.machinery import ModuleSpec, PathFinder
|
| 4 |
+
from importlib.machinery import all_suffixes as module_suffixes
|
| 5 |
+
from importlib.util import spec_from_file_location
|
| 6 |
+
from itertools import chain
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
MAPPING: dict[str, str] = {'qwen_tts': 'D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts'}
|
| 10 |
+
NAMESPACES: dict[str, list[str]] = {'qwen_tts.cli': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\cli'], 'qwen_tts.inference': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\inference'], 'qwen_tts.core.tokenizer_12hz': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\core\\tokenizer_12hz'], 'qwen_tts.core.tokenizer_25hz': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\core\\tokenizer_25hz'], 'qwen_tts.core.tokenizer_25hz.vq': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\core\\tokenizer_25hz\\vq'], 'qwen_tts.core.tokenizer_25hz.vq.assets': ['D:\\Prompt Engineer48\\In-Progress\\P01-Glassmorphic\\Qwen3-TTS-test\\qwen_tts\\core\\tokenizer_25hz\\vq\\assets']}
|
| 11 |
+
PATH_PLACEHOLDER = '__editable__.qwen_tts-0.1.1.finder' + ".__path_hook__"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _EditableFinder: # MetaPathFinder
|
| 15 |
+
@classmethod
|
| 16 |
+
def find_spec(cls, fullname: str, path=None, target=None) -> ModuleSpec | None: # type: ignore
|
| 17 |
+
# Top-level packages and modules (we know these exist in the FS)
|
| 18 |
+
if fullname in MAPPING:
|
| 19 |
+
pkg_path = MAPPING[fullname]
|
| 20 |
+
return cls._find_spec(fullname, Path(pkg_path))
|
| 21 |
+
|
| 22 |
+
# Handle immediate children modules (required for namespaces to work)
|
| 23 |
+
# To avoid problems with case sensitivity in the file system we delegate
|
| 24 |
+
# to the importlib.machinery implementation.
|
| 25 |
+
parent, _, child = fullname.rpartition(".")
|
| 26 |
+
if parent and parent in MAPPING:
|
| 27 |
+
return PathFinder.find_spec(fullname, path=[MAPPING[parent]])
|
| 28 |
+
|
| 29 |
+
# Other levels of nesting should be handled automatically by importlib
|
| 30 |
+
# using the parent path.
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
@classmethod
|
| 34 |
+
def _find_spec(cls, fullname: str, candidate_path: Path) -> ModuleSpec | None:
|
| 35 |
+
init = candidate_path / "__init__.py"
|
| 36 |
+
candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
|
| 37 |
+
for candidate in chain([init], candidates):
|
| 38 |
+
if candidate.exists():
|
| 39 |
+
return spec_from_file_location(fullname, candidate)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class _EditableNamespaceFinder: # PathEntryFinder
|
| 44 |
+
@classmethod
|
| 45 |
+
def _path_hook(cls, path) -> type[_EditableNamespaceFinder]:
|
| 46 |
+
if path == PATH_PLACEHOLDER:
|
| 47 |
+
return cls
|
| 48 |
+
raise ImportError
|
| 49 |
+
|
| 50 |
+
@classmethod
|
| 51 |
+
def _paths(cls, fullname: str) -> list[str]:
|
| 52 |
+
paths = NAMESPACES[fullname]
|
| 53 |
+
if not paths and fullname in MAPPING:
|
| 54 |
+
paths = [MAPPING[fullname]]
|
| 55 |
+
# Always add placeholder, for 2 reasons:
|
| 56 |
+
# 1. __path__ cannot be empty for the spec to be considered namespace.
|
| 57 |
+
# 2. In the case of nested namespaces, we need to force
|
| 58 |
+
# import machinery to query _EditableNamespaceFinder again.
|
| 59 |
+
return [*paths, PATH_PLACEHOLDER]
|
| 60 |
+
|
| 61 |
+
@classmethod
|
| 62 |
+
def find_spec(cls, fullname: str, target=None) -> ModuleSpec | None: # type: ignore
|
| 63 |
+
if fullname in NAMESPACES:
|
| 64 |
+
spec = ModuleSpec(fullname, None, is_package=True)
|
| 65 |
+
spec.submodule_search_locations = cls._paths(fullname)
|
| 66 |
+
return spec
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
@classmethod
|
| 70 |
+
def find_module(cls, _fullname) -> None:
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def install():
|
| 75 |
+
if not any(finder == _EditableFinder for finder in sys.meta_path):
|
| 76 |
+
sys.meta_path.append(_EditableFinder)
|
| 77 |
+
|
| 78 |
+
if not NAMESPACES:
|
| 79 |
+
return
|
| 80 |
+
|
| 81 |
+
if not any(hook == _EditableNamespaceFinder._path_hook for hook in sys.path_hooks):
|
| 82 |
+
# PathEntryFinder is needed to create NamespaceSpec without private APIS
|
| 83 |
+
sys.path_hooks.append(_EditableNamespaceFinder._path_hook)
|
| 84 |
+
if PATH_PLACEHOLDER not in sys.path:
|
| 85 |
+
sys.path.append(PATH_PLACEHOLDER) # Used just to trigger the path hook
|