-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
Support for offline/disconnected operations? #824
Comments
In theory as long as your If all of the repositories are set up, pre-commit will not access the network. At lyft we do this via docker images where we essentially bake by doing (not exactly since we use source-to-image, but you can imagine): WORKDIR /code
COPY .pre-commit-config.yaml .
RUN : \
&& git init . \
&& git add --all :/ \
&& pre-commit install-hooks
# ...
COPY . . We then later run this image with In general though, the contents of Note also that |
But yeah to answer your question, if the host and remote machines are running at the same path you can essentially do: export XDG_CACHE_DIR="/constant/path/to/cache" # or if your user has the same name
pre-commit install-hooks
zip -r cache.zip "$XDG_CACHE_DIR"
# scp / rsync / whatever to remote machine
unzip ... But anyway, yeah I don't have any interest implementing something like this in core, especially given how special cased and error prone it is. |
I'll give that approach a try. I don't think I'll hurt too much by moving I think I'll also look further into the git I agree with your thoughts around the |
ah yeah Even if you don't set / change If setting So some full solution ideas: redirect
|
closing this for now -- @lowell80 if there's anything additional please comment and I can reopen! thanks again for the issue 🎉 |
Note for who come here via search:
Make sure the two python versions that contain |
Has anyone given thought to using 'pre-commit' on a system without Internet connectivity? I haven't been able to find anything on the topic thus far, so I figured posting a question here was the next logical step.
The use case
I'm working with a client who has content managed in git. Content changes are made both within the client environment and externally by my consulting group. The internal and external repos are kept in sync using the
git bundle
feature and file copies. It's awkward, but it works.I'm using pre-commit to run a handful of standard hooks and a few custom ones (in my own public repo) when I'm on the external side, but my goal is to run the same hooks on the internal side as well. The technical challenge is that without internet access public repos can't be fetched.
I'm only using 2 hook repos (using
language: python
only) and they don't change that often. So I'm looking at ways to cache the repos offline or prebuild the virtual environment.Current workaround
I actually came up with a workaround myself and considered writing it up as a blog post or contributing it to the docs somewhere, but the approach is a bit klugy and tedious. I suspect that a few minor changes to the core code base would make the process more practical (or at least less painful.)
Setup:
repo
(URL). For the offline version, these point to the local (cached) git bundle file. For this to work, the.pre-commit-config.yaml
file is replaced with a symlink (and blacklisted with gitignore). So I keep two files in git:.pre-commit-config.yaml-bundle
and.pre-commit-config-online
, symlink to one of them, and try to keep them in sync.Initial installation:
pip download
to capture all the requirements for installing pre-commit as well as any external requirements of any of the hook repositories.git bundle
file.pip --find-links=/tmp/mydownloads --no-index pre-commit
PIP_FIND_LINKS=file:///tmp/mydownloads
andPIP_NO_INDEX=1
and runningpre-commit install --hooks
so that all necessary hooks repos are setup immediately (because those environmental variables may not be set later.)Updates are more or less the same as the installation.
Points of frustration:
.pre-commit-config.yaml
files is error prone.pip
command line args.Alternatives
The above approach may be as good as it gets without modifying some part of
pre-commit
.But given that it's open source, here's two alternate approaches I've considered.
~/.cache/pre-commit/repoXXXXX
directory structure and ship it off to another machine. The import process on the disconnected machine would extract and create the necessary entry in thedb.db
tracking system. There is certainly some potential for compatibility issues between machines, but that's already true in general and a fairly acceptable risk.Another option that just occurred to me as I'm writing this is possibly using git's
url.<base>.insteadOf
config trick to handle the URL rewrite. Essentially implementing option #1 listed above without any changes to pre-commit.... Hmm, need to test that out, but seems promising. But in any case, I'd like to get feedback from others more knowledgeable than me.I know this is outside of the typical use case, but it is possible to make this work. Any comments, suggestions, or ideas are welcome. I'm willing to code some stuff if need be, but wanted to check in with the community first.
Thanks so much for your time and consideration. Pre-commit has been so helpful to me in the relatively short time I've used it so far!
The text was updated successfully, but these errors were encountered: