Skip to content

[Fix] Fall back to ~/.cache/tilus when git is not installed - #166

Merged
yaoyaoding merged 2 commits into
NVIDIA:mainfrom
v0ropaev:fix/cache-dir-without-git
Oct 23, 2026
Merged

yaoyaoding merged 2 commits into
NVIDIA:mainfrom
v0ropaev:fix/cache-dir-without-git

Conversation

@v0ropaev

Copy link
Copy Markdown
Contributor

_get_default_cache_dir() in python/tilus/option.py runs git rev-parse --is-inside-work-tree when the module is imported, and falls back to ~/.cache/tilus on subprocess.CalledProcessError. If git is not installed at all, subprocess.run raises FileNotFoundError instead, which is not caught. So import tilus fails in a container or environment that has no git binary. With PATH pointed at a nonexistent directory I get

  File ".../python/tilus/option.py", line 39, in _get_default_cache_dir
    subprocess.run(
  ...
FileNotFoundError: [Errno 2] No such file or directory: 'git'

The except clause now catches OSError as well, so a missing git binary takes the same fallback as a failing git command. OSError rather than only FileNotFoundError also covers a git that exists but cannot be executed, which should not break the import either. I also added tests/test_option.py, which patches subprocess.run to raise either error and checks that the result is ~/.cache/tilus under a patched home directory.

I tested on macOS without a GPU, so cuda.bindings was replaced by a stub module on PYTHONPATH outside the repo. With PATH set to a nonexistent directory, python -c 'import tilus' raises the error above on main. With this change the import succeeds and get_option("cache_dir") returns ~/.cache/tilus. The new test fails on the FileNotFoundError case without the fix and passes with it. pytest tests/test_option.py tests/test_multiprocess.py tests/drivers/test_cache.py tests/test_compiler_fingerprint.py gives 21 passed, and pre-commit run on the changed files passes.

tilus.option computes the default cache directory at import time by
running "git rev-parse" next to the package. A failing git command was
already handled and sends the cache to ~/.cache/tilus, but when there
is no git binary on PATH subprocess.run raises FileNotFoundError
instead of CalledProcessError. That escaped the except clause, so
"import tilus" failed outright in slim containers and other
environments without git.

Catch OSError together with CalledProcessError so a missing git takes
the same fallback as a failing one, and add a test that covers both
cases.

Signed-off-by: Dmitry Voropaev <dy.voropaev@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

When tilus is installed into a site-packages directory that happens to live
inside another git work tree (e.g. a virtualenv inside a project repo),
'git rev-parse --is-inside-work-tree' succeeds and the default cache dir
ended up at site-packages/../.cache. Compare 'git rev-parse --show-toplevel'
with the tilus repository root instead, and fall back to ~/.cache/tilus
otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaoyaoding

Copy link
Copy Markdown
Member

/ok to test 2e3ba71

@yaoyaoding
yaoyaoding merged commit 2047456 into NVIDIA:main Oct 23, 2026
9 of 10 checks passed
@yaoyaoding

Copy link
Copy Markdown
Member

thanks @v0ropaev !

github-actions Bot added a commit that referenced this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants