-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conda installed pre-commit causes problems with graphical git front-ends #9
Comments
I tried to propose a pull request to the maintainer of pre-commit, but he considers it a bug of conda that conda installed python executables do not work out of the box: The following pull request records the conda environment used for calling It would be possible to propose a much simpler change if the conda environment is not recorded on |
And I agree, this is mostly a conda issue, where environments need to be activated in order to be used properly. With Python virtual environments, this is never really needed, you can call Also, this is not something specific to To work around this, we use https://github.com/gqmelo/exec-wrappers (with https://github.com/conda-forge/conda-wrappers-feedstock), which basically solves the issue universally: just install the We also use the same cc @gqmelo |
In general always expect anything installed using conda to work only in an activated environment. This is the reason why I created the exec-wrappers and conda-wrappers mentioned by nicoddemus. It creates wrappers that mimic the conda activation before running the real executable. In the case of pre-commit, I think you have some options: Use git from conda-forge + wrappersInstall git from conda-forge, create the wrappers and use the git wrapper instead of the git installed in your system: conda install git
conda install conda-wrappers You should find a git wrapper in Create wrappers for your current git installationIf you don't want to install git from conda-forge, you can wrap your current git with something like:
Then use the git wrappers from Change generated pre-commit files to use
|
Thank you so much for the great hints and the well structured explanation! The conda-wrappers package is actually pretty close to what I would see as an alternative to the conda activate system. The problem of conda activate is that it needs to hack the calling shell. I would put a pre-computed conda activate (mostly just environment variable settings) in some place of the environment on every conda install action and then have wrapper executables for all entry points that apply those before executing their real body. If they are binary injected versions of the real executables or of they include a hack changing sys.executable, conda activation would not be needed on programmatic calls. A quick try of git.bat did not work out of the box.
I am missing the activate.d directory mentioned in runin.bat:
@gqmelo, did you consider using Calling Lib/venv/scripts/nt/activate.bat in a modified runin.bat also does not work. |
Not sure I have a similar issue (the same error message though) but when I call the precommit executable directly (full path) without activating the conda environment on Windows, it's also causing failing builds. If I get this right, stand-alone executables should not be installed with conda because they are not ultimately standalone and depend on activated envs. This sounds like bad news to me. Hard for me to investigate now, but it seems it works when there is only one conda environment because that's probably activated by default. When installing into another env, the |
@QuantCo-mr-T I solved my problem with |
@gqmelo
|
In case anyone else comes across this issue, there appears to be an even simpler fix: If using windows, activate your conda env in the terminal and then activate your editor from the terminal as well: |
This should be resolved by using the latest Python 3.9 and 3.10 Python builds. No need for workarounds anymore. |
I'm facing this issue using vscode, Conda with Python 3.10.6 and pre-commit 2.20.0 |
@master117 Please post a traceback or other supporting information. |
If I'm stating vscode from a prompt with activate conda environemnt it works. |
Can you please also post a |
Of course.
This was run inside a powershell at the root folder of the project, using the base or no environment. |
This issue here is that the Python is your base environment probably doesn't have the necessary bugfix. As reported by |
@xhochy That actually worked, thank you very much.
Maybe this should be rephrased to this works with the latest Python builds FROM conda forge |
Issue:
Pre-commit stores the python executable used for
pre-commit install
in the generated git hooks. However, a python installed by conda can only be reliably executed when the respective environment is activated (Especially when using Windows). Thus, when using pre-commit installed by this conda-forge package, the respective environment needs to be activated whenevergit commit
is called. However, when using a git front-end from an IDE that supports the choice between different conda installed python environments, git will not be called with the correct environment activated.Pre-commit hook:
Resulting problem reproduced in Windows cmd (activate environment pre-commit; pre-commit install; git commit -> OK; deactivate environment; git commit -> FAIL):
Environment (
conda list
):Details about
conda
and system (conda info
):The text was updated successfully, but these errors were encountered: