Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uvx offline fallback mode? #10380

Open
alexjbuck opened this issue Jan 7, 2025 · 1 comment
Open

uvx offline fallback mode? #10380

alexjbuck opened this issue Jan 7, 2025 · 1 comment
Labels
cache Caching of packages and metadata enhancement New feature or improvement to existing functionality

Comments

@alexjbuck
Copy link

alexjbuck commented Jan 7, 2025

I do a lot of work in offline environments with an alternate package index. That index goes down sometimes (much more often than the public pypi repo would).

A lot of routine uv/uvx tasks will check against network locations before running unless the --offline flag is passed. When the index goes offline I can continue working with the --offline flag and uv/uvx will use its local cache. This is great!

The issue is when I start having scripts or other tooling that invoke uvx. When the index is up, I don't want to run in --offline mode, because I want uvx to work normally. So I can write those scripts to not use --offline. However, when the index goes down, now I need to be running in --offline mode because a network failure doesn't automatically fallback to the local cache. That means I have to go edit all the callsites to use uvx --offline for that time period.

Example:

uvx ruff check fails when the package repo goes down and must be changed to uvx --offline ruff check to use the locally cached version of ruff. You have to have already run uvx ruff ... at least once with access to a package index to get it loaded into the cache for this to work but that's not something uv can fix 😆.

There are plenty of workarounds (such as maintaining a parallel set of scripts or accepting an "--offline" flag into the scripts) but this does seem like it could be behavior that uv/uvx could subsume.

I think this comes down to the fact that there's only two modes right now:

  • Online: Default, uvx always tries to reach out to the package registry. e.g. uv ruff format
  • Offline: --offline passed, uvx will never reach out to the package registry. e.g. uv --offline ruff format

I'm finding in my circumstances it would be great to have a third mode:

  • Online with Fallback: Act like the default however, if a network request fails, fall back to --offline type behavior for that dependency and check if it exists in the local cache. If it doesn't, then fail just like how uvx --offline <package not in cache> would fail. e.g. uv --offline-fallback ruff format.

While my circumstances are probably fairly niche, the general idea is to let uvx have a "best effort" in case it can't reach the package index and not just fail when there's a valid local cached version.

I'm not sure if there are any pitfalls you could end up in with what could be a mixed online/offline dependency resolution. You can think of some weird cases where a specific dependency has a git source defined and that's accessible but transitive dependencies aren't online because the package index is offline so they fallback to previously local cached versions. My first though is so long as the versions can be resolved satisfactorily it wouldn't be any different.

@alexjbuck alexjbuck changed the title uvx partial offline mode uvx offline fallback mode Jan 7, 2025
@alexjbuck alexjbuck changed the title uvx offline fallback mode uvx offline fallback mode? Jan 7, 2025
@zanieb
Copy link
Member

zanieb commented Jan 8, 2025

This seems reasonable to me. I think the problem might be that we can't respect the registry's cache options? I'm not sure though, @charliermarsh would know better.

@zanieb zanieb added enhancement New feature or improvement to existing functionality cache Caching of packages and metadata labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cache Caching of packages and metadata enhancement New feature or improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants