Skip to content

Commit 87f2a99

Browse files
authored
avoid dynamically loading the backend in init since it breaks precompilation (#175)
* avoid dynamically loading the backend in init since it breaks precompilation * update changelog * avoid loading MicroMamba or pixi_jll if definitely not needed --------- Co-authored-by: Christopher Doris <github.com/cjdoris>
1 parent 1f3c7f9 commit 87f2a99

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
* Bug fix: remove lazy loading for backends, which is incompatible with precompilation.
5+
36
## 0.2.27 (2025-04-06)
47
* When `add`ing or `rm`ing a dependency, if resolving fails then CondaPkg.toml is now reverted.
58
* Bug fixes.

src/CondaPkg.jl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,12 @@ using Pkg: Pkg
1616
using Scratch: @get_scratch!
1717
using TOML: TOML
1818

19-
# these are loaded lazily to avoid downloading the JLLs unless they are needed
20-
const MICROMAMBA_MODULE = Ref{Module}()
21-
const PIXI_JLL_MODULE = Ref{Module}()
22-
23-
const MICROMAMBA_PKGID =
24-
Base.PkgId(Base.UUID("0b3b1443-0f03-428d-bdfb-f27f9c1191ea"), "MicroMamba")
25-
const PIXI_JLL_PKGID =
26-
Base.PkgId(Base.UUID("4d7b5844-a134-5dcd-ac86-c8f19cd51bed"), "pixi_jll")
27-
28-
function micromamba_module()
29-
if !isassigned(MICROMAMBA_MODULE)
30-
MICROMAMBA_MODULE[] = Base.require(MICROMAMBA_PKGID)
31-
end
32-
MICROMAMBA_MODULE[]
19+
# avoid loading backends which are definitely not used
20+
if @load_preference("backend", "MicroMamba") == "MicroMamba"
21+
using MicroMamba: MicroMamba
3322
end
34-
35-
function pixi_jll_module()
36-
if !isassigned(PIXI_JLL_MODULE)
37-
PIXI_JLL_MODULE[] = Base.require(PIXI_JLL_PKGID)
38-
end
39-
PIXI_JLL_MODULE[]
23+
if @load_preference("backend", "Pixi") == "Pixi"
24+
using pixi_jll: pixi_jll
4025
end
4126

4227
let toml = TOML.parsefile(joinpath(@__DIR__, "..", "Project.toml"))

src/backend.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function backend()
1414
env = getpref_env()
1515
if backend == ""
1616
if exe == ""
17-
if env == "" && invokelatest(pixi_jll_module().is_available)::Bool
17+
if env == "" && pixi_jll.is_available()
1818
# cannot currently use pixi backend if env preference is set
1919
# (see resolve())
2020
backend = "Pixi"
21-
elseif invokelatest(micromamba_module().available)::Bool
21+
elseif MicroMamba.available()
2222
backend = "MicroMamba"
2323
else
2424
error(
@@ -79,7 +79,7 @@ end
7979
function conda_cmd(args = ``; io::IO = stderr)
8080
b = backend()
8181
if b == :MicroMamba
82-
invokelatest(micromamba_module().cmd, args, io = io)::Cmd
82+
MicroMamba.cmd(args, io = io)
8383
elseif b in CONDA_BACKENDS
8484
STATE.condaexe == "" && error("this is a bug")
8585
`$(STATE.condaexe) $args`
@@ -93,7 +93,7 @@ default_pixi_cache_dir() = @get_scratch!("pixi_cache")
9393
function pixi_cmd(args = ``; io::IO = stderr)
9494
b = backend()
9595
if b == :Pixi
96-
pixiexe = invokelatest(pixi_jll_module().pixi)::Cmd
96+
pixiexe = pixi_jll.pixi()
9797
if !haskey(ENV, "PIXI_CACHE_DIR") && !haskey(ENV, "RATTLER_CACHE_DIR")
9898
# if the cache dirs are not set, use a scratch dir
9999
pixi_cache_dir = default_pixi_cache_dir()

src/env.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function activate!(e)
1515
path_sep = Sys.iswindows() ? ';' : ':'
1616
new_path = join(bindirs(), path_sep)
1717
if backend() == :MicroMamba
18-
e["MAMBA_ROOT_PREFIX"] = invokelatest(micromamba_module().root_dir)::String
19-
new_path = "$(new_path)$(path_sep)$(dirname(invokelatest(micromamba_module().executable)::String))"
18+
e["MAMBA_ROOT_PREFIX"] = MicroMamba.root_dir()
19+
new_path = "$(new_path)$(path_sep)$(dirname(MicroMamba.executable())))"
2020
end
2121
if old_path != ""
2222
new_path = "$(new_path)$(path_sep)$(old_path)"

0 commit comments

Comments
 (0)