conda-forge / miniforge_console_shortcut-feedstock

A conda-smithy repository for miniforge_console_shortcut.
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

PowerShell start menu entry #4

Open stallam-unb opened 2 years ago

stallam-unb commented 2 years ago

Comment:

The latest installer currently provides a CMD (.bat) activation script to work with environments, and I was wondering if there are plans to provide a powershell activation scripts as well. On Windows 11, PowerShell now integrates with Windows Terminal and provides all manner of useful features (autocomplete, better shell functionality, history scrolling, fancy colour support, etc.). On Anaconda/Miniconda, there is a PowerShell activation script in addition to CMD activation script via .ps1 scripts. I am assuming that since this is possible for miniconda, it should be possible for miniforge with mamba as well.

jakirkham commented 2 years ago

Maybe take a look at this?

stallam-unb commented 2 years ago

Maybe take a look at this?

@jakirkham Thanks for the link - I am aware of the init powershell functionality - however, that solution is a bit more "permanent". What I am looking for is the Start Menu shortcut that lets me lauch PowerShell with the requisite environment variables set.

To explain further - sometimes I have to run the "system" Python interpreter (for various reasons such as precommit, testing, etc.) and I have the system interpreter configured to be the "default" one. The star menu shortcut method allows me to explicitly launch a mamba/conda managed Python that I know overrides the default Python interpreter when I intend it to be the case. When I don't want that, I just launch PowerShell and the default one is on my $PATH. It would be nice to have the start menu shortcut to mirror that of Anaconda.

hmaarrfk commented 2 years ago

I guess this is a reasonable request, but the "decentralized" nature of conda(-forge) makes this not the right place to ask.

We merely aggregate functionality from the conda(-forge) ecosystem in an installer.

The cmd functionality is provided by the package

Derived from

I think you may want to make this same case there. To that end. I'm am transferring this issue here.

You may be able to make a PR acheiving the functionality you want.

stallam-unb commented 2 years ago

I can't quite seem to figure out the Anaconda recipe - all I see are standard references to cmd.exe and activate.bat across the repository and nothing to PowerShell and the conda-hook.ps1 script. And yet, if I install Miniconda, I can clearly see the PowerShell entry. Maybe I don't understand enough about the build or installation process - is the PowerShell shortcut created by the installer?

In the mean time, for anyone else coming in, I found two possible alternatives:

hmaarrfk commented 2 years ago

Your first suggestion is what the following is trying to acheive, but for the cmd shell: https://github.com/conda-forge/miniforge_console_shortcut-feedstock/blob/main/recipe/console_shortcut.json#L7

stallam-unb commented 2 years ago

Your first suggestion is what the following is trying to acheive, but for the cmd shell: https://github.com/conda-forge/miniforge_console_shortcut-feedstock/blob/main/recipe/console_shortcut.json#L7

I think I didn't phrase my comment right - I understand that is exactly what it is trying to achieve. What I was surprised by was that there was no PowerShell entry below it in the Anaconda recipe. I thought it might be a quick PR if I copied over the JSON from Anaconda over here, but I was surprised that in the Anaconda JSON, I see:

{
    "menu_name": "Anaconda${PY_VER} ${PLATFORM}",
    "menu_items":
    [
        {
            "name": "Anaconda Prompt",
            "system": "%windir%\\System32\\cmd.exe",
            "scriptarguments": ["/K", "${ROOT_PREFIX}\\Scripts\\activate.bat", "${PREFIX}"],
            "icon": "${MENU_DIR}/Iconleak-Atrous-Console.ico"
        }
    ]
}

What I expected to see was something like :

{
   ...

    "menu_items":
    [
        {
            "name": "Anaconda Prompt",
            ...
        },
       {
            "name": "Anaconda PowerShell Prompt",
            "system": %windir%\System32\WindowsPowerShell\v1.0\powershell.exe",
            "scriptarguments": ["-ExecutionPolicy", "ByPass", "-NoExit","-Command", "'& ${ROOT_PREFIX}\shell\condabin\conda-hook.ps1; conda activate ${PREFIX}'"],
            "icon": "${MENU_DIR}/Iconleak-Atrous-Console.ico"
        }
    ]
}

In other words, in the Anaconda JSON, there is no PowerShell entry. I guess it doesn't matter - it appears that all I have to do is add an extra entry to the menu_items list to create a new shortcut. I will send in a PR in a bit.