question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix environment-dependent git pre-commit hooks

See original GitHub issue

This is a follow up to #9948 and vscode#90178. After looking at the problem of environment-dependent pre-commit hooks from both the extension’s and the editor’s side, it seems to me the best solution would be for the Python extension to make sure that whatever environment the user has selected in the status bar is also active during the commit process (using VS Code’s source control panel).

I think this would be the expected behavior by most users if you asked them. At least it took me by surprise that my active environment doesn’t apply during the commit process even though it’s indicated in the status bar. Hence why it took me a while to figure out this is the reason my pre-commit hooks aren’t working.

One way to activate the status bar environment in the spawned git process might be as @joaomoreno mentioned to have a git wrapper that’s local to the source control panel (i.e. doesn’t affect git anywhere else) and simply activates the environment before handing over to real git.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:118
  • Comments:35 (9 by maintainers)

github_iconTop GitHub Comments

38reactions
chris1248commented, May 13, 2021

Just make the git commit hooks respect the python environment selected in the bottom status bar. Why are we sitting here 3 months later arguing about this?

8reactions
LudwigStumppcommented, Aug 16, 2021

One way to activate the status bar environment in the spawned git process might be as @joaomoreno mentioned to have a git wrapper that’s local to the source control panel (i.e. doesn’t affect git anywhere else) and simply activates the environment before handing over to real git.

Here is how I managed to get it working:

Create file test.sh that first activates the environment virtual_environment and then runs the test using pytest:

#!/bin/bash
source ~/miniconda3/etc/profile.d/conda.sh
conda activate virtual_environment
pytest

And call it from within .pre-commit-config.yaml

- repo: local
  hooks:
    - id: pytest-check
      name: pytest-check
      entry: bash test.sh
      language: system
Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-commit
We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks...
Read more >
githooks Documentation - Git
All the git commit hooks are invoked with the environment variable GIT_EDITOR=: if the command will not bring up an editor to modify...
Read more >
pre-commit hooks | master | Documentation - Poetry
pre -commit hooks pre-commit is a framework for building and running git hooks. See the official documentation for more information: pre-commit.com This ...
Read more >
Implement your own Python Pre-commit Hooks
Pre -commit-hooks are a subset of Git-hooks. ... ensuring any changes we make to our virtual environment dependency tree are reflected in our ......
Read more >
Git Hooks | Atlassian Git Tutorial
This is just one example of the pre-commit hook. It happens to use existing Git commands to run tests on the changes introduced...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found