Pre-commit: Issues with running under another virtualenv + fish shell and a workaround

Created on 2 Apr 2016  路  5Comments  路  Source: pre-commit/pre-commit

I am using fish shell + project virtualenv.

Whenever I activate my project's virtualenv, running pre-commit would fail, with strange errors like `basename: command not found'.

sh /Users/ustun/.pre-commit/repoUMoyOJ/py_env-default/bin/activate: line 61: basename: command not found bash: xargs: command not found

However, after deactivating the virtualenv, pre-commit would run properly.

It turns out one of the reasons is the usage of bash -c.

fish sets path as space delimited values: /usr/bin /usr/local/bin as opposed to /usr/bin:/usr/local/bin.

When we run bash -c 'echo $PATH' for example, it still receives the $PATH of fish, not $bash.

I went ahead and replaced in my local pre-commit scripts everything that refers to bash with fish, and changes &&'s to ;

This fixed it for me. Just documenting in case it helps another person.

I'm still not sure why deactivating the project virtualenv helped, I guess there's some incompatibility by running activate.fish (fish specific script for venv) and then activate (bash specific script for venv).

I also tried bash -l -c to get a clean bash environment, but that didn't help.

bug

All 5 comments

Upon further inspection, it is the deactivate nondestructive line under activate that activates a bogus fish specific path inside bash shell.

  if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
        PATH="$_OLD_VIRTUAL_PATH"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi

Before this runs, $PATH is colon separated
When deactivate runs, $OLD_VIRTUAL_PATH is space delimited here, so $PATH will now be space delimited within bash.

Removing the deactivate line fixes the problem.

Fortunately, I'm currently factoring out bash and activate scripts entirely in my latest pull request so this should just magically fix itself!

I believe this is fixed via #355

@ustun can you try the latest version pip install git+git://github.com/pre-commit/pre-commit and see if it fixes this issue for you?

Can confirm fixed:

asottile@work /t/foo> source venv/bin/activate.fish 
(venv) asottile@work /t/foo> pip install pre-commit==0.7.6
...
Installing collected packages: pyyaml, aspy.yaml, virtualenv, functools32, jsonschema, cached-property, nodeenv, ordereddict, pre-commit
Successfully installed aspy.yaml-0.2.2 cached-property-1.3.0 functools32-3.2.3.post2 jsonschema-2.5.1 nodeenv-0.13.6 ordereddict-1.1 pre-commit-0.7.6 pyyaml-3.11 virtualenv-15.0.1
(venv) asottile@work /t/foo> pre-commit run --all-files
Check Yaml...............................................................Failed
hookid: check-yaml

/home/asottile/.pre-commit/repoMVYdJO/py_env-default/bin/activate: line 61: basename: command not found
bash: xargs: command not found

(venv) asottile@work /t/foo> pip install pre-commit==0.8.0
...
Successfully installed pre-commit-0.8.0 pyterminalsize-0.1.0
(venv) asottile@work /t/foo> pre-commit run --all-files
Check Yaml...............................................................Passed

Great, thank you very much!

Was this page helpful?
0 / 5 - 0 ratings