okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0f1e5e4cb
main
1"""tools/_paths.py - where the tools find a GGUF library. 2 3The preparation tools use Strata's own reader/writer and quantizers (tools/strata_gguf.py, tools/strata_quants.py): gguf_lib() returns it. 4$STRATA_GGUF_PY (a folder that holds llama.cpp's `gguf` package) still selects that package instead, for two releases (the byte-identical 5A/B of the pack tools runs both); llama.cpp's HF converter (NVFP4-local) imports gguf-py itself and always uses the vendored copy. 6 7Where gguf-py is looked for (gguf_py(), add_gguf_py()), in order: $STRATA_GGUF_PY (a folder that holds the `gguf` package, e.g. <llama.cpp>/gguf-py), then the vendored copy 8<engine>/third_party/strata-gguf-py (frozen at the pinned llama.cpp commit, no download), then the development tree's 9../../.ref/llama.cpp/gguf-py, then (#3269) the install folders: in the Control package setup.py's per-user install folder 10($STRATA_INSTALL_DIR, else the app's folder, the Terminal's remembered installs), so a tool run by hand from the package finds it there. 11""" 12from __future__import annotations 13 14import os 15import sys 16from pathlib import Path 17 18ENGINE = Path (__file__ ).resolve ().parents [1 ] 19VENDORED = ENGINE / "third_party" / "strata-gguf-py" # holds gguf/ (the package) and converter/ (llama.cpp's HF converter) 20 21 22def _install_dirs ()-> list [Path ]: 23"""The per-user install folders a Control-mode setup.py works in. Best effort: never raises.""" 24out :list [Path ]= [] 25raw = os .environ .get ("STRATA_INSTALL_DIR" ) 26if raw : 27out .append (Path (raw ).expanduser ()) 28try : 29if str (ENGINE )not in sys .path : 30sys .path .append (str (ENGINE )) 31from strata_control import discovery 32out .append (discovery .app_install_dir ()) 33out += [pl .path for pl in discovery .places (here = ENGINE )] 34except Exception : 35pass 36return out 37 38 39def gguf_py ()-> str : 40cands = [os .environ .get ("STRATA_GGUF_PY" ),ENGINE / "third_party" / "strata-gguf-py" , 41ENGINE .parents [min (1 ,len (ENGINE .parents )- 1 )]/ ".ref" / "llama.cpp" / "gguf-py" ]# the dev tree; a shallow install (G:\Strata) has no grandparent 42cands += [d / "third_party" / "strata-gguf-py" for d in _install_dirs ()] 43for c in cands : 44if c and (Path (c )/ "gguf" ).is_dir (): 45return str (c ) 46sys .exit ("gguf-py was not found. It ships with Strata in third_party/strata-gguf-py; set STRATA_GGUF_PY to the folder that holds the " 47"`gguf` package (for example <llama.cpp>/gguf-py) to use another copy" ) 48 49 50def gguf_lib (): 51"""The GGUF library the preparation tools use, with gguf-py's names (GGMLQuantizationType, GGUFReader, GGUFWriter, GGUFValueType, quants): 52llama.cpp's gguf-py when STRATA_GGUF_PY names a folder that holds it (kept for two releases), else tools/strata_gguf.py.""" 53own = os .environ .get ("STRATA_GGUF_PY" ) 54if own : 55if not (Path (own )/ "gguf" ).is_dir (): 56sys .exit ("STRATA_GGUF_PY=%s does not hold a `gguf` package" % own ) 57if own not in sys .path : 58sys .path .insert (0 ,own ) 59import gguf 60return gguf 61here = str (Path (__file__ ).resolve ().parent ) 62if here not in sys .path : 63sys .path .insert (0 ,here ) 64import strata_gguf 65return strata_gguf 66 67 68def add_gguf_py ()-> None : 69p = gguf_py () 70if p not in sys .path : 71sys .path .insert (0 ,p ) 72 73 74def converter_dir ()-> str : 75"""llama.cpp's Hugging Face converter (convert_hf_to_gguf.py and conversion/), vendored beside gguf-py (the NVFP4-local preparation).""" 76for c in (ENGINE / "third_party" / "strata-gguf-py" / "converter" ,* [d / "third_party" / "strata-gguf-py" / "converter" for d in _install_dirs ()]): 77if (c / "convert_hf_to_gguf.py" ).is_file (): 78return str (c ) 79sys .exit ("llama.cpp's converter was not found (third_party/strata-gguf-py/converter)" )