-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
pre-commit doesn't keep current project/virtualenv in sys.path #178
Comments
This is actually by design. The hooks run in their own isolated environments. A workaround is to use the |
I'm sorry, I'm not sure I understand what you mean by
Can you explain this in a little more detail? I appreciate your help. |
In hooks.yaml you can create a hook which is of the langauge An example file might look like this:
|
Oh, I see. Yes, I think that could work. I'll give it a try, thanks! |
If that doesn't work let me know! We unfortunately haven't had many usecases with those type of hooks so there's potential that they're completely broken for anything beyond the trivial case that is tested: https://github.com/pre-commit/pre-commit/blob/master/testing/resources/system_hook_with_spaces_repo/hooks.yaml |
Update on this: looks like prospector can only accept one file/directory at a time as input, so I set my - id: prospector
name: prospector
entry: -n 1 prospector
language: system
files: \.py$ Without the |
@guykisel Actually prospector only accepting one file/directory at a time is a bug in prospector (or rather, 'lack of feature'). It's something that comes as a consequences of using setoptconf that I haven't looked into yet. Perhaps a better fix for all this is fixing prospector's behaviour? |
@asottile Does isolating the environment work in general? I have found with prospector that without the complete path, most tools fail at inferring types and a lot of checks are somewhat worthless. I'm mostly talking about pylint here though. |
@carlio For pylint in particular, using an isolated version is really only useful for the syntax checks it does and not the import / type checks. Which has some nonzero benefit, but yeah isn't really ideal :/ @guykisel I like the |
@asottile you could add another field in It could also be interesting to try to run xargs in parallel to speed up processing of lots of files. |
@asottile this is the config I have
when I run it, I see the path of
But, when I see |
Can you |
@asottile yes... |
your |
@asottile the reason I added "which" is because |
right -- I was mostly explaining why in your screenshot above you see a different For an aside, one thing I noticed about the screenshot above is the |
@asottile keeping |
|
I didn't try with my shell before clearing the |
the hash cache only affects the shell and has nothing to do with pre-commit here, I'd suggest reading the manual for your particular shell (for instance bash or zsh) describing the shell builtins and how they function -- the shell is a program like any other and the hash cache is stored in that program's memory. pre-commit does not have access to that. |
@asottile I have gone through |
there's no point to doing that in |
Just in case: I had next hook: - repo: local
hooks:
- id: pytest
name: pytest
entry: poetry run pytest --
language: python
types: [python]
files: ^tests\/.*test_.*\.py$
pass_filenames: false # or use with: require_serial I use Base on comment @asottile , I changed |
Another tool that is affected by this problem is mypy, it really needs stuff from the project's venv to work properly unless one pretty much completely ignores errors resulting from imports. I think the Maybe a So it would be great if pre-commit would offer some more assistance in coping with these scenarios. Don't know what exactly would that be. Maybe e.g. some option that would "record" the currently active virtualenv settings at hook install time and use them later to construct the same environment when running the installed hook, dunno. |
I'm trying to get Prospector ( https://github.com/landscapeio/prospector ) to run as a pre-commit hook. By default, Prospector will run pylint, including pylint's import checker.
I was getting confused, because I kept getting output that looks like:
Even though directly running Prospector in the project (as opposed to via pre-commit) doesn't raise these errors.
When I print
sys.path
from inside a Python script run by pre-commit as a hook, I get:Note that this doesn't appear to include my project directory or my virtualenv path. I think this is why pylint (within Prospector) is unable to successfully run those import statements.
Is this behavior intentional? Am I doing something incorrectly? Is there a way I can get pre-commit to preserve my
sys.path
when running Python hooks?For reference, see https://github.com/guykisel/prospector-mirror
The text was updated successfully, but these errors were encountered: