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

Add py --activate command #114881

Open
zooba opened this issue Feb 1, 2024 · 0 comments
Open

Add py --activate command #114881

zooba opened this issue Feb 1, 2024 · 0 comments
Assignees
Labels
OS-windows type-feature A feature request or enhancement

Comments

@zooba
Copy link
Member

zooba commented Feb 1, 2024

Feature or enhancement

For a per-user install of the launcher (the current default), we have a user-writable directory on PATH. We could use this in combination with the launcher to support an "activate" command that reliably puts a selected version of Python on PATH for you without adding the actual install directory.

For example (note that this is hypothetical and fake right now):

C:\> dir C:\Users\USERNAME\AppData\Local\Programs\Python\Launcher

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         12/7/2023  10:20 PM         765208 py.exe
-a----         12/7/2023  10:21 PM          50968 pyshellext.amd64.dll
-a----         12/7/2023  10:20 PM         763672 pyw.exe

C:\> py -V:PythonCore/3.12 --activate
Activated Python 3.12 (Store)

C:\> dir C:\Users\USERNAME\AppData\Local\Programs\Python\Launcher

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         12/7/2023  10:20 PM         765208 py.exe
-a----          2/1/2024   9:32 PM             61 py.ini
-a----         12/7/2023  10:21 PM          50968 pyshellext.amd64.dll
-a----         12/7/2023  10:20 PM         765208 python.exe
-a----         12/7/2023  10:20 PM         765208 python3.exe
-a----         12/7/2023  10:20 PM         763672 pythonw.exe
-a----         12/7/2023  10:20 PM         763672 pythonw3.exe
-a----         12/7/2023  10:20 PM         763672 pyw.exe

My thinking here is that we add a new section to py.ini that converts the launcher argv[0] into a Company/Tag value (equivalent of passing -V:). We need a new section to avoid conflicting with existing shebang commands, but should be able to write it from the launcher call easily enough. We'd get to decide whether to use this new mapping to override shebang lines and environment variables (gut feel is to ignore shebangs but honour env vars).

An alternative to the py.ini section would be a python.exe.ini adjacent to the executable and specific to it, so we create a few more files, but have a much simpler time handling them.

We should also have a py --deactivate option to remove the files. py --activate would activate the interpreter that is launched for just py (that is, with --activate we do the normal search but instead of launching it, we write it into a config file and ensure the global names exist).

Per-machine installs would require admin privileges to do this, as they're in a per-machine directory. I think that's okay - we can have a helpful error message.

Linked PRs

@zooba zooba added type-feature A feature request or enhancement OS-windows labels Feb 1, 2024
zooba added a commit to zooba/cpython that referenced this issue Feb 14, 2024
…uncher.

These will create additional aliases alongside the launcher for a particular Python install.
zooba added a commit to zooba/cpython that referenced this issue Feb 26, 2024
zooba added a commit to zooba/cpython that referenced this issue Feb 26, 2024
zooba added a commit to zooba/cpython that referenced this issue Feb 28, 2024
zooba added a commit to zooba/cpython that referenced this issue Mar 20, 2024
@zooba zooba self-assigned this Apr 3, 2024
zooba added a commit to zooba/cpython that referenced this issue Aug 27, 2024
zooba added a commit to zooba/cpython that referenced this issue Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant