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

Introduce CONDA_JL_CONDA_EXE environment variable #216

Merged
merged 12 commits into from
Feb 8, 2022

Conversation

mkitti
Copy link
Member

@mkitti mkitti commented Jan 15, 2022

Here we introduce a new environment variable, CONDA_JL_CONDA_EXE which determines the location of the conda executable at build time. This in turn is saved in deps.jl as the constant CONDA_EXE. This in turn defines the constant Conda.conda. If CONDA_EXE does not exist due to an old deps.jl file, Conda.conda is defined in manner prior to this PR.

The default CONDA_EXE is defined by the following code based on ROOTENV.

        const CONDA_EXE = if Sys.iswindows()
            p = joinpath(ROOTENV, "Script")
            conda_bat = joinpath(p, "conda.bat")
            isfile(conda_bat) ? conda_bat : joinpath(p, "conda.exe")
        else
            joinpath(ROOTENV, "bin", "conda")
        end

Conda.jl also has a method _install_conda which installs conda if the executable is not present. To determine the PREFIX for this installation the following code is used: CONDA_EXE_PREFIX = conda |> dirname |> dirname.

@mkitti mkitti mentioned this pull request Jan 15, 2022
else
joinpath(bin_dir(ROOTENV), "conda")
if ! @isdefined(CONDA_EXE)
# We have an oudated deps.jl file that does not define CONDA_EXE
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is impossible. If there's an outdated deps.jl that means there was a update of Conda.jl which means the package has to be built first.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's possible in a few situations such as using multiple Julia installations with the same JULIA_DEPOT_PATH and/or a modified JULIA_LOAD_PATH. Julia will only force a rebuild if it is aware that the version changed.

For example, I did this to myself in the course of testing the package by using pkg"dev Conda". In this case, the Conda package was checked out in ~/.julia/dev/Conda and the deps file at ~/.julia/dev/Conda/deps/deps.jlwas carried over between several versions as I moved between branches or I changed environments.

While we could just throw and error if we detect this condition, encouraging the user to rebuild, just doing the former calculation seems friendlier since we can just follow the old behavior here.

We see this issue with an outdated deps.jl file quite commonly with GR.jl and users will appear in support channels complaining that plotting is broken. The issues were reduced once we just started fixing the issues automatically.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can remove it now, but my recommendation is to keep it for the moment and then remove it at a later time to smooth over the migration process.

@mkitti
Copy link
Member Author

mkitti commented Jan 15, 2022

Could we run the CI to see if there are any current issues?

test/runtests.jl Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2022

Codecov Report

Merging #216 (84c662c) into master (f169018) will decrease coverage by 2.38%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
- Coverage   91.83%   89.44%   -2.39%     
==========================================
  Files           1        1              
  Lines         196      199       +3     
==========================================
- Hits          180      178       -2     
- Misses         16       21       +5     
Impacted Files Coverage Δ
src/Conda.jl 89.44% <100.00%> (-2.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f169018...84c662c. Read the comment docs.

src/Conda.jl Outdated
Comment on lines 192 to 195
# This assumes that the conda executable will in some directory under
# CONDA_EXE_PREFIX.
# Ex: If CONDA_EXE="$HOME/miniforge3/bin/conda", then CONDA_EXE_PREFIX="$HOME/miniforge3"
CONDA_EXE_PREFIX = conda |> dirname |> dirname
Copy link
Member

Choose a reason for hiding this comment

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

I think this assumption is too strong. It's possible that people use a shim script or symlink. Can you use something like conda info --json or conda run python -c 'import sys; print(sys.executable)'?

Nitpicks: It's strange that a local variable is all caps. I also notice that src/Conda.jl does not use |> for unary function application. I have nothing against |> per se, but, I think it's good to follow the style of surrounding code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mkitti, why do we need a CONDA_EXE_PREFIX when PREFIX should work just as fine?

Copy link
Member Author

@mkitti mkitti Jan 15, 2022

Choose a reason for hiding this comment

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

PREFIX is determined by ROOTENV. We cannot use this because we can no longer assume that CONDA_EXE is in ROOTENV.

const PREFIX = prefix(ROOTENV)

We reach this line of code when the conda executable does not exist at Conda.conda.
Thus, the objective here is to install the conda executable at the location specified by CONDA_JL_CONDA_EXE / CONDA_EXE / Conda.conda.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You mean when the user sets CONDA_JL_CONDA_EXE env variable to a non-existent conda executable? In that case, we should just error in deps.jl.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can add a check at build time. What should we do at runtime when _install_conda is invoked?

Copy link
Collaborator

@isuruf isuruf Jan 15, 2022

Choose a reason for hiding this comment

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

We can add a check at build time.

Thanks

What should we do at runtime when _install_conda is invoked?

Nothing. We just use PREFIX since the if condition above is invoked only if CONDA_JL_CONDA_EXE is not set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it only invoked if CONDA_JL_CONDA_EXE is not set? It might also be invoked if CONDA_EXE gets deleted between build time and run time.

Copy link
Member

Choose a reason for hiding this comment

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

I forgot to mention another point: does Conda.jl still use PREFIX? If not, it's better to remove it or at least deprecate it.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's an internal constant called PREFIX, but it does not use an environmental variable called PREFIX.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it only invoked if CONDA_JL_CONDA_EXE is not set? It might also be invoked if CONDA_EXE gets deleted between build time and run time.

True. I'm not sure how to handle it. If CONDA_EXE gets deleted between build time and run time, I'm not sure if we should install it there.

test/runtests.jl Outdated Show resolved Hide resolved
Copy link
Member

@tkf tkf left a comment

Choose a reason for hiding this comment

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

LGTM! I think it's ready to merge after CONDA_JL_CONDA_EXE is documented in README and @stevengj looked at it.

@mkitti
Copy link
Member Author

mkitti commented Jan 16, 2022

Great. Thanks for the help. It looks like this can also be used to use mamba in place of conda.

$ CONDA_JL_CONDA_EXE=~/mambaforge/bin/mamba julia

(@v1.7) pkg> build Conda
    Building Conda → `~/.julia/dev/Conda/deps/build.log`
Precompiling project...
  1 dependency successfully precompiled in 1 seconds (16 already precompiled)

julia> Conda.conda
"/home/mkitti/mambaforge/bin/mamba"

julia> Conda.list()
[ Info: Running `conda list` in root environment
# packages in environment at /home/mkitti/.julia/conda/3:

@mkitti
Copy link
Member Author

mkitti commented Jan 21, 2022

@stevengj , would you like to review before we merge this?

@mkitti
Copy link
Member Author

mkitti commented Jan 24, 2022

Would anyone object to merging by the end of this week if we do not hearing anything else?

deps/build.jl Outdated
if haskey(ENV, "CONDA_JL_CONDA_EXE")
# Check to see if CONDA_EXE is an executable file
if isfile(CONDA_EXE)
if uperm(CONDA_EXE) & 0x01 > 0
Copy link
Member

Choose a reason for hiding this comment

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

Sys.isexecutable(CONDA_EXE)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I made this change in 84c662c

@mkitti
Copy link
Member Author

mkitti commented Feb 7, 2022

Thank you for the reviews. Can we merge this?

@mkitti
Copy link
Member Author

mkitti commented Feb 8, 2022

Thanks again for studying this pull request. I would like to merge this tomorrow if I there are no further concerns.

@isuruf isuruf merged commit 8f71332 into JuliaPy:master Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants