Skip to content

Support Preferences in TestEnv: Copy the preferences into the TestEnv. #97

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/julia-1.9/activate_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
# This needs to be first as `gen_target_project` fixes `pkgspec.path` if it is nothing
sandbox_project_override = maybe_gen_project_override!(ctx, pkgspec)

sandbox_path = joinpath(pkgspec.path::String, "test")
source_path = pkgspec.path::String
sandbox_path = joinpath(source_path, "test")
sandbox_project = projectfile_path(sandbox_path)
sandbox_preferences = nothing
if isfile(sandbox_project)
with_load_path([sandbox_path, Base.LOAD_PATH...]) do
sandbox_preferences = Base.get_preferences()
end
else
with_load_path([something(projectfile_path(source_path)), Base.LOAD_PATH...]) do
sandbox_preferences = Base.get_preferences()
end
end

tmp = mktempdir()
tmp_project = projectfile_path(tmp)
tmp_manifest = manifestfile_path(tmp)
tmp_preferences = joinpath(tmp, first(Base.preferences_names))

# Copy env info over to temp env
if sandbox_project_override !== nothing
Expand Down Expand Up @@ -48,6 +60,13 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
end

Types.write_manifest(working_manifest, tmp_manifest)
# Copy over preferences
if sandbox_preferences !== nothing
open(tmp_preferences, "w") do io
# TODO: should we separately import TOML?
Pkg.TOML.print(io, sandbox_preferences::Dict{String, Any})
end
end

Base.ACTIVE_PROJECT[] = tmp_project

Expand All @@ -73,3 +92,14 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)

return Base.active_project()
end

with_load_path(f::Function, new_load_path::String) = with_load_path(f, [new_load_path])
function with_load_path(f::Function, new_load_path::Vector{String})
old_load_path = copy(Base.LOAD_PATH)
copy!(Base.LOAD_PATH, new_load_path)
try
f()
finally
copy!(LOAD_PATH, old_load_path)
end
end
Loading