[go: nahoru, domu]

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

feature:py launcher semantics #152

Open
thejcannon opened this issue Sep 2, 2020 · 9 comments
Open

feature:py launcher semantics #152

thejcannon opened this issue Sep 2, 2020 · 9 comments
Assignees
Labels
feature New feature request help wanted Extra attention is needed
Projects

Comments

@thejcannon
Copy link

People like the Windows py launcher for it's shebang and program-registration semantics (.py files are registered as being run by py, so I can just double-click the file).

I'd love to see py play nicely with pyenv-win (A bit of a stretch as that'd likely involve a PEP of some kind), pyenv-win somehow plug into py without py changes, or a similar utility which is fully pyenv-win aware.

For reference, py source is here: https://github.com/python/cpython/blob/master/PC/launcher.c

@kirankotari
Copy link
Member

@thejcannon did you got any change with play around with pyenv shell <version> and python command. I don't say it same as py, but it's good to plan or investigate how this can be implemented.

@thejcannon
Copy link
Author

@kirankotari Yeah. Some background here, I <3 pyenv and am trying to advocate for it's usage at our company. As someone pointed out, our current processes tell Windows users to install py launcher along with Python a specific version of Python.

When we "switch" to pure-pyenv solution, they'll lose the "I can just run this Python script like any other program, by double-clicking it or running foo.py directly". Not a showstopper, but I thought it'd be reeeeeealy cool if some utility registered pyenv as the "runner" for python files like the py launcher does (or py launcher is pyenv aware).

For the time being, we'll just educate people on how pyenv works, and tell them they'll need to python <script_name>.py

@kirankotari
Copy link
Member

@thejcannon got it. I will look into it.

@thejcannon
Copy link
Author

I know it's been several months, were you able to make any headway?

@thejcannon
Copy link
Author
thejcannon commented Jan 5, 2021

I actually decided to spend a little time looking into this. I think the double-click launcher semantics might be trivial!

First, a simple batch file to add the right registry keys tells Windows to associate .py files with the shim (and add an icon)

reg add "HKCR\.py" /t REG_SZ /d Python.Pyenv
reg add "HKCR\Python.Pyenv" /t REG_SZ /d "Python Source File"
reg add "HKCR\Python.Pyenv\shell\open\command" /t REG_SZ /d "\"%USERPROFILE%\\.pyenv\\pyenv-win\\shims\\python.bat\" \"%%1\""
reg add "HKCR\Python.Pyenv\DefaultIcon" /t REG_SZ /d "<path-to-ico>"

And then double-clicking or calling .py files on the cmd-line should "just work".
(the only missing piece of parity is py on the cmd-line, but that's captured in #164)

... I might make a PR if you don't mind shepherding it along.

@thejcannon
Copy link
Author

(Oh and you might need to refresh the icon cache: https://www.winhelponline.com/blog/refresh-icon-cache-windows-7-quickly/)

@thejcannon
Copy link
Author

#198 led me to PEP 514, which py supports. How would you feel if pyenv-win:

  • Set all the registry keys on each pyenv install for the specific installation (seems very doable)
  • Also came with a pre-built py (with permission from the PSF).
  • The registry entry for file association uses py (the PR associated with this bug, but pointing to py instead of python)

Then we'd have all the following:

  • Full py cmd-line support, including specifying versions (E.g. py -3.6 would use the pyenv 3.6 installation if it existed)
  • File association support (mostly from this PR, but still)
  • Shebang handling as well

I honestly think if we had that pyenv-win would be the one true way to install/manage python versions on windows.

@thejcannon
Copy link
Author

I sniffed around py's code this weekend (link) and it only looks at the PythonCore registry entries. So if we wanted it to work we'd have to fork it, tell it to look at pyenv's registry entries, and then ship the compiled code.

I don't think that's an awful idea (aside from requiring a compiler).

@kirankotari kirankotari self-assigned this Mar 18, 2021
@kirankotari kirankotari added enhancement New feature or request good first issue Good for newcomers labels Mar 18, 2021
@kirankotari kirankotari added this to To do in pyenv-win via automation Mar 18, 2021
@kirankotari kirankotari added help wanted Extra attention is needed feature New feature request and removed enhancement New feature or request good first issue Good for newcomers labels Apr 18, 2021
@chrisdjali-wrld3d
Copy link

What needs doing here beyond just extending the registry checks to a few extra keys and ensuring someone/CI actually builds the modified py.exe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request help wanted Extra attention is needed
Projects
No open projects
pyenv-win
  
To do
Development

No branches or pull requests

3 participants