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

Support running local scripts with pipenv run #2921

Closed
multimeric opened this issue Oct 5, 2018 · 3 comments
Closed

Support running local scripts with pipenv run #2921

multimeric opened this issue Oct 5, 2018 · 3 comments
Labels
Status: Requires PEEP This issue requires an accompanying enhancement proposal

Comments

@multimeric
Copy link

Currently pipenv run will run either:

  • An executable in the $PATH
  • A script listed in Pipfile's [scripts]

However, it is quite a common occurrence that users will want to run a local script, e.g. ./app.py. Currently there are a few ways to do this, but each has their downsides

  • Add it to the [scripts] section - this works but assumes the user knows beforehand which scripts they may want to execute. Not good for ad-hoc running of scripts
  • pipenv run python app.py - this forces the user to specify the interpreter. This means the shebang line is ignored, and requires the user to know which interpreter they want (if it's a shell script it shouldn't be run with python). Unix philosophy dictates that we leave the choice of interpreter up to the script itself (hence the existance of the shebang)
  • Start a pipenv shell, and then run ./app.py. This is (imo) too much of a heavyweight solution. Starting a new shell shouldn't be required to run a single script.

Thus, could we implement the ability for pipenv run to execute arbitrary local scripts? Or is there some philosophical reason why we aren't allowing this?

@multimeric multimeric changed the title Support running local files with pipenv run Support running local scripts with pipenv run Oct 5, 2018
@uranusjr
Copy link
Member

uranusjr commented Oct 5, 2018

I was thinking about this for a while (in a more general sense). Maybe we can add a fallback that when the first argument looks like a path, or starts with - (a dash), send the command line to python, so you can do

pipenv run -m foo   # Runs the foo module, like python -m foo
pipenv run ./foo.py  # Like python ./foo.py

(The path case has python preprended because it makes generalisation easier, and also works better for Windows.)

This would, however, requires a PEEP, and I just don’t currently have the time and capacity to draft it. I would be interested in assisting if you are interested in submitting a PEEP request.

https://github.com/pypa/pipenv/blob/master/peeps/PEEP-000.md

@uranusjr uranusjr closed this as completed Oct 5, 2018
@uranusjr uranusjr added the Status: Requires PEEP This issue requires an accompanying enhancement proposal label Oct 5, 2018
@multimeric
Copy link
Author

multimeric commented Oct 5, 2018

Maybe we can add a fallback that when the first argument looks like a path, or starts with - (a dash), send the command line to python

I don't think we should assume that the script is a python script. For example, what if someone make a bash script that uses the pipenv python, but itself runs using the bash interpreter? If someone wants to run a local python script I think adding a shebang line #!/usr/bin/env python (admittedly this is Unix/Linux only, I'm not sure how Windows does this) or simply running pipenv run python foo.py would be sufficient.

This would, however, requires a PEEP, and I just don’t currently have the time and capacity to draft it.

I'd be happy to do this. Do I just PR a markdown document into the peep folder? What else should I add on top of what I have already written?

@uranusjr
Copy link
Member

uranusjr commented Oct 5, 2018

Personally I feel it is more productive to assume python, since pipenv run bash ./foo is always available, and the goal of pipenv run is never to duplicate shell parsing. This kind of discussion is exactly why a PEEP is needed though. Another possibility is to implement a shebang parser (it’s not that hard).

Yes, just send a PR to add a Markdown document to the peeps directory. The PEEP would need to summarise discussions around the particular topic, why certain ideas are rejected, and why a certain one is chosen. You don’t need to write all that immediately though. Start with copy-pasting your original post into it to kick off discussion, and gradually add things as they are discussed/resolved/rejected.

See #2819 for an example of discussions for PEEP-002. Also you might be interested in reasing some of Python’s PEP to get a feeling how this kind of documents can be structured. PEP 517 is a good example IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Requires PEEP This issue requires an accompanying enhancement proposal
Projects
None yet
Development

No branches or pull requests

2 participants