Skip to content

PR: Change logic to detect conda-based installers and micromamba on them #20827

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

Merged
merged 17 commits into from
Apr 28, 2023

Conversation

mrclary
Copy link
Contributor

@mrclary mrclary commented Apr 15, 2023

Description of Changes

  • Replaced pcregrep with pcre2grep in Github workflow since pcre2grep is already included in macOS runner image
  • Distinction between conda-based installation and traditional installation of Spyder, for all platforms, is determined by the existence of spyder-menu.json in the environment.
  • Renamed running_in_mac_app -> is_conda_based_app, which now determines whether the Spyder instance is a conda-based installation for any platform. is_pyinst is obsolete and removed.
  • Spyder's conda executable is no longer micromamba since the conda-based installer includes a standalone conda executable as well as mamba; accommodations are made accordingly.
  • For conda-based installations, Spyder's runtime environment and its root environment are excluded from the list of conda environments.
  • spyder-kernels is now run using conda's run command rather than external shell scripts.

@mrclary mrclary self-assigned this Apr 15, 2023
@mrclary mrclary requested review from dalthviz and ccordoba12 April 15, 2023 16:53
@mrclary mrclary mentioned this pull request Apr 16, 2023
16 tasks
@mrclary mrclary marked this pull request as draft April 17, 2023 04:46
@ccordoba12
Copy link
Member

@mrclary, please rebase with master to get the fixes to our tests. Also, quick review from your message above:

The standalone conda executable is included in the conda-based installer and is no longer micromamba and accommodations are made accordingly.

I think we should keep micromamba in the installers because we could use it for Spyder-env-manager, right @dalthviz?

@mrclary
Copy link
Contributor Author

mrclary commented Apr 17, 2023

The standalone conda executable is included in the conda-based installer and is no longer micromamba and accommodations are made accordingly.

I think we should keep micromamba in the installers because we could use it for Spyder-env-manager, right @dalthviz?

It seems to me that micromamba would be redundant. The standalone executable also uses the libmamba library (@jaimergp, correct me if I'm wrong) and performs the same role in the conda-based implementation as micromamba does for our existing standalone applications.

@jaimergp
Copy link

Not right now, since the installation code doesn't require a solver at all. Also conda-standalone has a really bad startup time (needs to self-extract), so not really useful for anything else than bootstrapping an install.

@jaimergp
Copy link

You can add 'conda' to the base environment though, since Spyder needs a Python interpreter anyway.

@mrclary
Copy link
Contributor Author

mrclary commented Apr 17, 2023

Not right now, since the installation code doesn't require a solver at all.

Just to be clear, conda.exe uses the standard conda solver, but does not use libmamba, correct? Because I haven't seen any issues creating environments with conda.exe.

Also conda-standalone has a really bad startup time (needs to self-extract), so not really useful for anything else than bootstrapping an install.

Interesting...
Is there a reason, then, that menuinst uses <base>/conda.exe instead of <base>/bin/activate when specifying "activate": True? or is <base>/bin/activate only introduced by conda/mamba?

Also, I haven't noticed any performance issues using conda.exe. If there is any "unpacking" time, I don't notice it in the following:

`$ time command info -e`
>> time mamba info -e
# conda environments:
#
                         /Users/rclary/Library/spyder-5.4.4.dev1473
                         /Users/rclary/Library/spyder-5.4.4.dev1473/envs/spyder-5.4.4.dev1473
base                     /Users/rclary/opt/mambaforge
bokeh                    /Users/rclary/opt/mambaforge/envs/bokeh
bokeh_apps               /Users/rclary/opt/mambaforge/envs/bokeh_apps
bokeh_py310              /Users/rclary/opt/mambaforge/envs/bokeh_py310
c2w                      /Users/rclary/opt/mambaforge/envs/c2w
c2w_310                  /Users/rclary/opt/mambaforge/envs/c2w_310
spy-dev                  /Users/rclary/opt/mambaforge/envs/spy-dev
spy-inst                 /Users/rclary/opt/mambaforge/envs/spy-inst
test                     /Users/rclary/opt/mambaforge/envs/test


real	0m0.966s
user	0m0.434s
sys	0m0.209s
>> time ~/Library/spyder-5.4.4.dev1473/conda.exe info -e
# conda environments:
#
                         /Users/rclary/Library/spyder-5.4.4.dev1473
                         /Users/rclary/Library/spyder-5.4.4.dev1473/envs/spyder-5.4.4.dev1473
                         /Users/rclary/opt/mambaforge
                         /Users/rclary/opt/mambaforge/envs/bokeh
                         /Users/rclary/opt/mambaforge/envs/bokeh_apps
                         /Users/rclary/opt/mambaforge/envs/bokeh_py310
                         /Users/rclary/opt/mambaforge/envs/c2w
                         /Users/rclary/opt/mambaforge/envs/c2w_310
                         /Users/rclary/opt/mambaforge/envs/spy-dev
                         /Users/rclary/opt/mambaforge/envs/spy-inst
                         /Users/rclary/opt/mambaforge/envs/test
base                     /var/folders/5v/28jqvwxs2cd5fj93gvwnykdrqc926z/T/_MEIsjVFap


real	0m0.766s
user	0m0.465s
sys	0m0.192s
>> time ~/Library/spyder-5.4.4.dev1473/bin/mamba info -e
# conda environments:
#
base                     /Users/rclary/Library/spyder-5.4.4.dev1473
spyder-5.4.4.dev1473     /Users/rclary/Library/spyder-5.4.4.dev1473/envs/spyder-5.4.4.dev1473
                         /Users/rclary/opt/mambaforge
                         /Users/rclary/opt/mambaforge/envs/bokeh
                         /Users/rclary/opt/mambaforge/envs/bokeh_apps
                         /Users/rclary/opt/mambaforge/envs/bokeh_py310
                         /Users/rclary/opt/mambaforge/envs/c2w
                         /Users/rclary/opt/mambaforge/envs/c2w_310
                         /Users/rclary/opt/mambaforge/envs/spy-dev
                         /Users/rclary/opt/mambaforge/envs/spy-inst
                         /Users/rclary/opt/mambaforge/envs/test


real	0m0.772s
user	0m0.326s
sys	0m0.140s

You can add 'conda' to the base environment though, since Spyder needs a Python interpreter anyway.

We currently add python, conda, mamba, and pip to the base environment of the installation. Perhaps this is why we have <base>/bin/activate...

Nevertheless, if there are any concerns about conda.exe, we can just change our find_conda command in this PR to grab <base>/bin/mamba instead of <base>/conda.exe.

@mrclary mrclary force-pushed the cbi-updates branch 4 times, most recently from e487732 to e57da03 Compare April 17, 2023 20:36
@dalthviz
Copy link
Member

I think we should keep micromamba in the installers because we could use it for Spyder-env-manager, right @dalthviz?

Well, to give some context, the plugin is using some of the spyder functions to define what 'conda-like' executable should be used. That is done at https://github.com/spyder-ide/spyder-env-manager/blob/37f2837a077bd5dabd2b123c015c5f071826e8b9/spyder_env_manager/spyder/config.py#L24-L36

After a quick check to the changes done here, seems like that will need an update, but we are using already there the find_conda function so I guess it should not be much of a problem. The plugin at the end can work with micromamba or conda without issue 👍 that's why we test the envs-manager with conda and micromamba: https://github.com/spyder-ide/envs-manager/actions/runs/4189392934

@mrclary
Copy link
Contributor Author

mrclary commented Apr 18, 2023

Well, to give some context, the plugin is using some of the spyder functions to define what 'conda-like' executable should be used. That is done at https://github.com/spyder-ide/spyder-env-manager/blob/37f2837a077bd5dabd2b123c015c5f071826e8b9/spyder_env_manager/spyder/config.py#L24-L36

After a quick check to the changes done here, seems like that will need an update, but we are using already there the find_conda function so I guess it should not be much of a problem. The plugin at the end can work with micromamba or conda without issue 👍 that's why we test the envs-manager with conda and micromamba: https://github.com/spyder-ide/envs-manager/actions/runs/4189392934

Yes, get_spyder_umamba_path is removed and find_conda preferentially returns Spyder's runtime conda executable, falling back to CONDA_EXE or MAMBA_EXE environment variables, and finally resorting to find_program.

@mrclary mrclary marked this pull request as ready for review April 18, 2023 00:15
@jaimergp
Copy link

Interesting...
Is there a reason, then, that menuinst uses /conda.exe instead of /bin/activate when specifying "activate": True? or is /bin/activate only introduced by conda/mamba?

conda.exe is guaranteed to exist, while bin/activate requires conda on your base environment, and that's an assumption we didn't want to make or force on users (like having python... this is being worked on). We can probably add some logic to use other (faster) activation providers and fallback to conda.exe if nothing else was found, but well... menuinst 2 is still an alpha project.

Also, I haven't noticed any performance issues using conda.exe. If there is any "unpacking" time, I don't notice it in the following.

Usually it takes a few seconds to return, but maybe you have it cached already. I think pyinstaller extracts to a random, but predictable location? Not sure.

@mrclary
Copy link
Contributor Author

mrclary commented Apr 18, 2023

conda.exe is guaranteed to exist, while bin/activate requires conda on your base environment, and that's an assumption we didn't want to make or force on users (like having python... this is being worked on). We can probably add some logic to use other (faster) activation providers and fallback to conda.exe if nothing else was found, but well... menuinst 2 is still an alpha project.

Ahh, okay, understood.

Usually it takes a few seconds to return, but maybe you have it cached already. I think pyinstaller extracts to a random, but predictable location? Not sure.

I did notice that conda.exe required writing to a temp directory; now I know why.

@ccordoba12 ccordoba12 changed the title PR: Updated logic for running_in_mac_app and micromamba for conda-based installer PR: Change logic to detect conda-based installers and micromamba on them Apr 19, 2023
@ccordoba12 ccordoba12 added this to the v6.0alpha1 milestone Apr 19, 2023
@mrclary mrclary marked this pull request as draft April 19, 2023 04:47
@mrclary
Copy link
Contributor Author

mrclary commented Apr 19, 2023

@ccordoba12, Thank you for all your feedback and taking the time to review the PR. I've marked it as draft until we investigate further some the review comments. Perhaps we can discuss some of the points at the next developer meeting.

@mrclary
Copy link
Contributor Author

mrclary commented Apr 25, 2023

I changed where conda-based environments were filtered: instead of in spyder.utils.conda.get_list_conda_env, now it is in spyder.plugins.maininterpreter.confpage.
This means that get_list_conda_env will still list all environments on the system without prejudice, but the custom interpreters still do not reveal conda-based runtime environment or its base.

Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrclary ! Left a couple of comments, but other than that, this LGTM 👍

@mrclary mrclary force-pushed the cbi-updates branch 2 times, most recently from df9ea36 to 2d0589b Compare April 26, 2023 21:54
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrclary for addressing our reviews! One last suggestion for you, then this should be ready.

mrclary and others added 17 commits April 27, 2023 14:18
… effect of reporting these values when running from conda-based installers, otherwise no effect.
is_conda_based_app checks if Spyder is from a conda-based installer.
Conda-based installer is determined by existence of spyder-menu.json file in environment instead of SPYDER_APP environment variable.
… Spyder's mamba executable (from conda-based installers).

When testing for standalone conda executable, use endswith in order to capture '_conda.exe' as well as 'conda.exe'
Non-standalone conda executables are in the same directory as activate; no need to back out two directory levels and go back in.
Enforce correct CONDA_EXE environment variable for conda-based installers.
… thereof, from custom interpreter list.

Note that sys.executable may be a symlink for conda-based runtime environments.
Windows requires USERPROFILE environment variable to find all conda environments.
…s conda-activate.[sh|bat] and get_conda_activation_script.
Flow control in projects plugin does not need to distinguish conda-based Spyder from other installations. CLI works for macOS, Linux, and Windows.
Corrected syntax to the Windows command allows for commandline arguments passed to the batch file.
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrclary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants