Skip to content
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

Pipenv mode is broken by the --split-string (-S) argument of env in the shebang #42

Closed
jflbr opened this issue Dec 6, 2019 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@jflbr
Copy link

jflbr commented Dec 6, 2019

Hi,

I found myself stuck for an hour trying to make the pipenv mode work. This made me take a look at the pre-commit script managed by autohooks.

I noticed that the --split-string (-S) argument of env (coreutils) is used in the shebang. But it doesn't seem to be available in every version of /usr/bin/env and using it breaks pipenv mode for me.

The change was brought by this commit.

My platform information

lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.3 LTS
Release:	18.04
Codename:	bionic

My env version

/usr/bin/env --version
env (GNU coreutils) 8.28
Copyright © 2017 Free Software Foundation, Inc.
License GPLv3+ : GNU GPL version 3 ou ultérieure
<http://gnu.org/licenses/gpl.html>
Ceci est un logiciel libre. Vous êtes libre de le modifier et de le redistribuer.
Ce logiciel n'est accompagné d'ABSOLUMENT AUCUNE GARANTIE, dans les limites
permises par la loi.

Écrit par Richard Mlynarik et David MacKenzie.

The error I get

From a pipenv virtualenv:

$ autohooks activate --force  --mode pipenv
$ git commit -m "foo"
/usr/bin/env : option invalide -- 'S'
Saisissez « /usr/bin/env --help » pour plus d'informations.

This is because the shebang used in the pre-commit script managed by autohooks is
#!/usr/bin/env -S pipenv run python3.

The whole script content is:

#!/usr/bin/env -S pipenv run python3
# meta = { version = 1 }

import sys

try:
    from autohooks.precommit import run
    sys.exit(run())
except ImportError:
    print(
        "Error: autohooks is not installed. To force creating a commit without "
        "verification via autohooks run 'git commit --no-verify'.",
        file=sys.stderr,
    )
    sys.exit(1)

Workaround

The only way for me to make it work for now is to force the pythonpath mode which rewrites the shebang of the previous script to #!/usr/bin/env python3

Questions/Recommandations

What are your recommandation for this problem?
I assume that upgrading my /usr/bin/env version should solve everything but maybe a minimum requirement should be explicitly mentioned in the install doc.
I found this interesting issue about pipenv shebang and it seems like -S is not available on Ubuntu. Is it a choice to make pipenv mode unavailable on Ubuntu?

@bjoernricks
Copy link
Contributor

Not sure which Ubuntu version you are using. At least Ubuntu 19.04 and 19.10 have a sufficient env version. Because I did use these versions for development.

> /usr/bin/env --version
env (GNU coreutils) 8.30

Personally I wasn't aware that the -S option was added in one of the last versions :-/

I guess a workaround for you would be to change the shebang line to use pipenv directly.

@bjoernricks bjoernricks self-assigned this Dec 6, 2019
@bjoernricks bjoernricks added the bug Something isn't working label Dec 6, 2019
@bjoernricks
Copy link
Contributor

The -S param got introduced with coreutils 8.30 (2018-07-01) https://github.com/coreutils/coreutils/blob/master/NEWS#L241

@awtrimpe
Copy link

awtrimpe commented Dec 19, 2019

Not sure which Ubuntu version you are using. At least Ubuntu 19.04 and 19.10 have a sufficient env version. Because I did use these versions for development.

I am also running into this issue on Ubuntu 18.04 in WSL on Windows.

> /usr/bin/env --version
env (GNU coreutils) 8.28

I have replaced:
#!/usr/bin/env -S pipenv run python3
with Pipenv's location
#!/home/atrimpe/.local/share/virtualenvs/backend-WS4Vegoo/bin/python

I still run into the following issues:

  1. It always tells me that the autohooks mode is "unknown", even when pyproject.toml contains
[tool.autohooks]
mode = "pipenv"
pre-commit = ["autohooks.plugins.autopep8"]

or even when I manually run
pipenv run autohooks activate --mode pipenv --force

  1. It cannot find the autopep8 plugin, even though I have added that to the Pipfile just as the instructions say: pipenv install --dev autohooks-plugin-autopep8

Console Output:

> git commit -m "TEST"
autohooks mode "unknown" in pre-commit hook differs from mode "pipenv" in pyproject.toml file.                                                                                                                               [ warning ]
autohooks => pre-commit
    Running autohooks.plugins.autopep8
        Running autopep8 pre-commit hook
        An error occurred while running pre-commit hook autohooks.plugins.autopep8. [Errno 20] Not a directory: 'autopep8'.                                                                                                    [ error ]

@bjoernricks
Copy link
Contributor

Yes the mode is unknown because the shebang line is used to determine the current mode of the hook

@bjoernricks
Copy link
Contributor

Regarding the autopep8 plugin please create an issue in the plugin repo because I am not the author of this plugin.

@awtrimpe
Copy link

Have you considered a solution like pipenv-shebang? Using it as a replacement worked for me. The only downside is that it must be installed globally on the system, something I am not always in favor of.

@bjoernricks
Copy link
Contributor

This whole mode thing is for avoiding global installation of python modules.

My intention was to only install a minimal git hook. With the first version of autohooks the user had to handle the dependencies by himself. But this didn't work out. Therefore version 2 got different modes to handle dependencies loading but I wasn't aware that env -S only got introduced lately 😒

Currently I am thinking of installing a bootstrap python module besides hook to solve the different loading modes. This module may contain something like pipenv-shebang then.

@cfi-gb
Copy link
Member

cfi-gb commented Dec 7, 2020

@bjoernricks @y0urself As #89 has been merged as a fix i guess this issue can be closed now?

@y0urself
Copy link
Member

y0urself commented Dec 7, 2020

@bjoernricks @y0urself As #89 has been merged as a fix i guess this issue can be closed now?

Yes. Thanks!

@y0urself y0urself closed this as completed Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants