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

RFE: support running via #!env bashbang #2137

Closed
glensc opened this issue May 4, 2018 · 6 comments
Closed

RFE: support running via #!env bashbang #2137

glensc opened this issue May 4, 2018 · 6 comments

Comments

@glensc
Copy link

glensc commented May 4, 2018

Would be super usable to support shebang:

$ head ./registry_mirror.py
#!/usr/bin/env pipenv run

but due the way hashbang is parsed by linux kernel and to be most portable for other OSes, this would only work if the /usr/bin/env argument is single word.

$ ./registry_mirror.py
/usr/bin/env: ‘pipenv run’: No such file or directory

so, i propose you install pipenv-run command as well, or modify pipenv behavior so that is able to detect such invocation scenario and behave as if pipenv run /path/to/program.py was invoked.

@erinxocon
Copy link
Contributor

Hi @glensc! Thanks for using pipenv! Can you make a bigger use case for this? We really don't want to be adding much to the API right now. Adding that command for a small use case isn't plausible at this point in time.

@glensc
Copy link
Author

glensc commented May 7, 2018

what you mean bigger usecase? that's the only usecase.

without shebang, typical use would be python interpreter:

$ head ./registry_mirror.py
#!/usr/bin/env python3

but even the script executes, it will fail if dependent libraries not installed.

so it would be better to distribute scripts as:

$ head ./registry_mirror.py
#!/usr/bin/env pipenv run

@techalchemy
Copy link
Member

@glensc I think I’d be curious what the implementation looks like. It sounds like s neat feature but at the end of the day how meaningful is it? It’s only useful if you’re already in an interactive shell, so not for automation. Otherwise you would need to always run as the same user on the same system with the same environment variables.

@sfx2k
Copy link

sfx2k commented Jul 27, 2018

I have the following pyhton base-environments on my machine:

c:\python2\python.exe
c:\python3\python.exe

Furthermore I have a project ("myproject") with a pipenv-environment:
C:\Users\xxx\Documents\Programmeinstellungen\Home.virtualenvs\myproject-sdhjkf309274...

When I run myproject with the following shebang line
#! /usr/bin/env python

it will be run with the base python environment c:\python3\python.exe and not with the pipenv-environment within my homedirectory!

Of course I can edit the shebang to
#! /usr/bin/env C:/Users/xxx\Documents/Programmeinstellungen/Home/.virtualenvs/myproject-sdhjkf309274/.../python.exe

But on another machine, the hash (sdhjkf309274) will not be the same!

Therefore it would be nice to have sth. like #!/usr/bin/env pipenv run
where the pipenv application itself looks for the correct environment.

@uranusjr
Copy link
Member

uranusjr commented Jul 27, 2018

Err, unfortunately that is not how shebang works, and Pipenv can not magically work around POSIX restrictions. You might want to read the discussion here: https://stackoverflow.com/questions/4303128

(edit: this thread might be more succinct if you only want a simple explanation https://unix.stackexchange.com/questions/63979)

We don’t object to supporting this use case, but shebang pipenv run is simply not possible.

@costela
Copy link

costela commented Dec 6, 2018

See my comment on #2238 for a workaround.

It sounds like s neat feature but at the end of the day how meaningful is it? It’s only useful if you’re already in an interactive shell, so not for automation.

@techalchemy this would make it more comfortable to write ad-hoc scripts, for instance jenkins jobs: if you want the script definition to exist on the jenkins side, saved as a "Execute shell" step, then you'd be able to just use pipenv in the shebang (or through the workaround mentioned above).
So yes, it's not a huge use-case, but it feels like a valid usability improvement, IMHO. (Note that I wouldn't necessarily endorse the proposed addition of a pipenv-run shortcut, in particular)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants