You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to determine how to use pre-existing virtualenv for a hook #266
Sorry, I'm not sure if an issue is the right place to put this, but considering I've spent some time reading source and docs and haven't found the answer it seems fair to consider this a documentation bug.
My use case is this: I have many Python projects I work on. Each one has its own virtualenv where I install the dependencies. I'd like to use pre-commit to run pylint. Pylint needs to run out of the same virtualenv as the project so that it can import the dependencies for its static analysis. When running the pylint hook from https://github.com/pre-commit/mirrors-pylint it appears that the command that is actually run is:
Looking at the source and the docs I can't find a way to indicate to the hook that it should use my virtualenv for the project rather than the virtualenv at /Users/eliribble/.pre-commit/repoq_elftwa/py_env-default. Is there a way to do that?
Yeah, that will work, though I changed it a bit since we already had a bash script which hands across the correct settings file to pylint. Looks like this, for anyone who hits the same thing:
- repo: local
hooks:
- id: system
name: PyLint
entry: ./pylint.sh
language: system
files: \.py$
Activity
chriskuehl commentedon Sep 29, 2015
One option is to add a hook to
.pre-commit-config.yamllike:(stolen from https://github.com/Yelp/pgctl)
Does that work for you? If so, it's probably worth documenting somewhere.
I don't think there's support for running Python-type hooks in the current environment.
asottile commentedon Sep 29, 2015
Yeah we're still missing proper documentation from #226
We'll track that work here: pre-commit/pre-commit.com#50
@EliRibble do local hooks satisfy your requirements?
EliRibble commentedon Sep 29, 2015
Yeah, that will work, though I changed it a bit since we already had a bash script which hands across the correct settings file to pylint. Looks like this, for anyone who hits the same thing:
Thanks for the fast response.
asottile commentedon Sep 30, 2015
No problem! Hopefully I find some time to get those docs updated :)
asottile commentedon May 4, 2016
local hooks are now documented here: http://pre-commit.com/#repository-local-hooks
EliRibble commentedon May 4, 2016
Looks really good, thanks
webknjaz commentedon Jun 23, 2018
To whom it may concern,
here's config for pylint I ended up having
asottile commentedon Jun 23, 2018
that seems a bit excessive -- why not configure
pylintas a local hook like the documentation suggests?webknjaz commentedon Jun 23, 2018
Does it imply installing it manually?
asottile commentedon Jun 23, 2018
it does, yes but you're also building a virtualenv manually for pylint's sake too
asottile commentedon Jun 23, 2018
and again, pylint is a bit of a special snowflake here -- it does both static analysis and dynamic analysis (which needs to actually import your code)
webknjaz commentedon Jun 24, 2018
Yeah, I just didn't want to mutate existing app's env.
Merge pull request pre-commit#266 from pre-commit/fix_no_commit_to_br…