hauntsaninja / pyp

Easily run Python at the shell! Magical, but never mysterious.
MIT License
1.41k stars 39 forks source link

Use actual pyp interpreter in shebang by default #29

Open Bobronium opened 2 years ago

Bobronium commented 2 years ago

Current version:

~
$ pyp "'pyp is running on ' + sys.executable" --explain > explained.py

~
$ perl explained.py
Traceback (most recent call last):
  File "/Users/bobronium/explained.py", line 3, in <module>
    from pyp import pypprint
ModuleNotFoundError: No module named 'pyp'

~
$ cat explained.py
#!/usr/bin/env python3
import sys
from pyp import pypprint
assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
output = 'pyp is running on ' + sys.executable
if output is not None:
    pypprint(output)

With these changes:

~
$ pyp "'pyp is running on ' + sys.executable" --explain > explained.py

~
$ perl explained.py
pyp is running on /Users/bobronium/.local/pipx/venvs/pypyp/bin/python

~
$ cat explained.py
#!/Users/bobronium/.local/pipx/venvs/pypyp/bin/python
import sys
from pyp import pypprint
assert sys.stdin.isatty() or not sys.stdin.read(), "The command doesn't process input, but input is present"
output = 'pyp is running on ' + sys.executable
if output is not None:
    pypprint(output)
Bobronium commented 2 years ago

Sorry, I've been too lazy to clone it and test it properly. Just patched my installation to check that it's working as intended.

I'll update the tests soon and will request review when it'll be ready for one, in the meanwhile this should be a draft really.