jayaspjacob Claude Opus 4.8 (1M context) commited on
Commit ·
f3cc6d3
1
Parent(s): 57f0925
Resolve fish-speech root via __path__ (namespace package)
Browse filesfish_speech is a PEP 420 namespace package on the Space, so __file__ is
None and the previous fallback raised TypeError. Locate the package dir
via __path__[0] (or by walking up setup_root's caller path) and use its
parent as the project root.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- tts/engine.py +27 -2
tts/engine.py
CHANGED
|
@@ -88,11 +88,36 @@ def _patch_pyrootutils() -> None:
|
|
| 88 |
try:
|
| 89 |
return _orig_setup_root(*args, **kwargs)
|
| 90 |
except FileNotFoundError:
|
| 91 |
-
import fish_speech
|
| 92 |
import sys
|
| 93 |
from pathlib import Path
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if kwargs.get("pythonpath", False) and str(root) not in sys.path:
|
| 97 |
sys.path.insert(0, str(root))
|
| 98 |
if kwargs.get("project_root_env_var", True):
|
|
|
|
| 88 |
try:
|
| 89 |
return _orig_setup_root(*args, **kwargs)
|
| 90 |
except FileNotFoundError:
|
|
|
|
| 91 |
import sys
|
| 92 |
from pathlib import Path
|
| 93 |
|
| 94 |
+
# fish_speech is a PEP 420 namespace package here, so __file__ is None;
|
| 95 |
+
# locate its directory via __path__, falling back to the calling module's
|
| 96 |
+
# path (setup_root's first arg). The project root is the dir *containing*
|
| 97 |
+
# the fish_speech package, mirroring the repo's .project-root location.
|
| 98 |
+
pkg_dir = None
|
| 99 |
+
try:
|
| 100 |
+
import fish_speech
|
| 101 |
+
|
| 102 |
+
paths = list(getattr(fish_speech, "__path__", []) or [])
|
| 103 |
+
if paths:
|
| 104 |
+
pkg_dir = Path(paths[0]).resolve()
|
| 105 |
+
elif getattr(fish_speech, "__file__", None):
|
| 106 |
+
pkg_dir = Path(fish_speech.__file__).resolve().parent
|
| 107 |
+
except Exception:
|
| 108 |
+
pkg_dir = None
|
| 109 |
+
|
| 110 |
+
if pkg_dir is None and args:
|
| 111 |
+
sf = Path(str(args[0])).resolve()
|
| 112 |
+
for p in [sf, *sf.parents]:
|
| 113 |
+
if p.name == "fish_speech":
|
| 114 |
+
pkg_dir = p
|
| 115 |
+
break
|
| 116 |
+
|
| 117 |
+
if pkg_dir is None:
|
| 118 |
+
raise # nothing to fall back to — re-raise the original error
|
| 119 |
+
|
| 120 |
+
root = pkg_dir.parent
|
| 121 |
if kwargs.get("pythonpath", False) and str(root) not in sys.path:
|
| 122 |
sys.path.insert(0, str(root))
|
| 123 |
if kwargs.get("project_root_env_var", True):
|