Detect Hugging Face hub cache from HF_HOME/HF_HUB_CACHE - #6
Merged
Conversation
The model search path defaulted to a hardcoded ~/.cache/huggingface/hub, so models stored in a hub cache relocated via the standard Hugging Face environment variables were never discovered. Resolve the default the same way the huggingface_hub Python library does: HF_HUB_CACHE first, then HF_HOME with /hub appended, then the per-user fallback. Existing installations that never customized the path have the legacy default persisted; re-resolve it against the environment on decode so they pick up the configured location without manual intervention. Adds a hostless NativTests target covering path resolution and the legacy default migration. Regenerate Nativ.xcodeproj with xcodegen after checkout to get the test target (the tracked project file is left untouched to avoid xcodegen version churn).
GUI apps on macOS inherit launchd's environment, so HF_HOME exported from shell startup files (.zshrc, .zprofile, ...) is invisible to the app and the previous commit alone could not help GUI-launched installs. When the process environment does not configure the hub cache, probe the user's login + interactive shell once at startup (async, with a timeout), the same approach VS Code and JetBrains IDEs use. NUL-separated env output behind a marker segment keeps shell-startup noise out of the parsed values. A discovered HF_HOME/HF_HUB_CACHE only migrates the legacy default search path; user-customized paths are preserved. Views already re-scan reactively when the search path changes. Adds ShellEnvironment tests covering parsing (marker handling, junk segments, values with '=' and newlines) and process execution (output capture, timeout, missing executable), plus isConfigured tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5
Summary
huggingface_hubPython library:HF_HUB_CACHE→$HF_HOME/hub→~/.cache/huggingface/hub.HF_HOME/HF_HUB_CACHE. Parsing isNUL-separated behind a marker segment, so noisy rc files (prompts, banners) can't corrupt values.
Testing
NativTestsXCTest target (the repo had none): 21 tests covering path-resolution precedence, legacy-default migration,isConfigured, env-output parsing (marker, junk segments, values with=/newlines), and process execution (output capture, timeout, missing executable).xcodebuild -scheme Nativ -configuration Debug test— all pass.HF_HOMEonly in~/.zshrc, launching viaopen(i.e. launchd environment):~/.cache/huggingface/hubcontents to theHF_HOMEcache within ~1–3s, and the migrated path persists across relaunches;HF_HOMEexported: detected instantly, probe skipped.Notes for reviewers
xcodegen generateafter checkout to get the test target; the trackedNativ.xcodeprojis intentionally unchanged to avoid xcodegen-version churn (CI regenerates it).Note: this fix was generated by AI, verified by me.