From b5519b056a3a4c32d23f3e876844804ab4828623 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 17 Dec 2024 18:54:43 +1300 Subject: [PATCH 1/2] Fix activating [sources] with relative paths --- src/julia-1.11/activate_set.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/julia-1.11/activate_set.jl b/src/julia-1.11/activate_set.jl index 20cc47f..b485070 100644 --- a/src/julia-1.11/activate_set.jl +++ b/src/julia-1.11/activate_set.jl @@ -54,6 +54,18 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true) temp_ctx = Context() temp_ctx.env.project.deps[pkgspec.name] = pkgspec.uuid + # A hack to get [sources] with relative paths working. We just dive into the project + # context and replace all the relative '{path = ".."}' instances with the corresponding + # absolute paths. `pkgspec.path` is assumed to be relative to the Project.toml file + # that we are activating and has the relative paths. + for source in values(temp_ctx.env.project.sources) + isa(source, Dict) || continue + haskey(source, "path") || continue + if !isabspath(source["path"]) + source["path"] = joinpath(pkgspec.path, source["path"]) + end + end + try Pkg.resolve(temp_ctx; io=devnull) @debug "Using _parent_ dep graph" From 5aeb4b4bdb6e46ba4e75eba6c18e0b1a4bba412d Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 17 Dec 2024 19:07:51 +1300 Subject: [PATCH 2/2] add tests --- test/activate_set.jl | 20 +++++++++++++++++++ test/sources/DependentEnv/Project.toml | 12 +++++++++++ test/sources/DependentEnv/src/DependentEnv.jl | 6 ++++++ test/sources/MainEnv/Project.toml | 16 +++++++++++++++ test/sources/MainEnv/src/MainEnv.jl | 6 ++++++ test/sources/MainEnv/test/runtests.jl | 4 ++++ 6 files changed, 64 insertions(+) create mode 100644 test/sources/DependentEnv/Project.toml create mode 100644 test/sources/DependentEnv/src/DependentEnv.jl create mode 100644 test/sources/MainEnv/Project.toml create mode 100644 test/sources/MainEnv/src/MainEnv.jl create mode 100644 test/sources/MainEnv/test/runtests.jl diff --git a/test/activate_set.jl b/test/activate_set.jl index 3794ab3..c6d4e00 100644 --- a/test/activate_set.jl +++ b/test/activate_set.jl @@ -86,4 +86,24 @@ @test isdefined(TestEnv, :isfixed) end end + + if VERSION >= v"1.11" + @testset "activate with [sources]" begin + orig_project_toml_path = Base.active_project() + push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing + orig_load_path = Base.LOAD_PATH + try + Pkg.activate(joinpath(@__DIR__, "sources", "MainEnv")) + TestEnv.activate() + new_project_toml_path = Base.active_project() + @test new_project_toml_path != orig_project_toml_path + @test orig_load_path == Base.LOAD_PATH + @eval using MainEnv + @test isdefined(@__MODULE__, :MainEnv) + @test MainEnv.bar() == 42 + finally + Pkg.activate(orig_project_toml_path) + end + end + end end diff --git a/test/sources/DependentEnv/Project.toml b/test/sources/DependentEnv/Project.toml new file mode 100644 index 0000000..27809d3 --- /dev/null +++ b/test/sources/DependentEnv/Project.toml @@ -0,0 +1,12 @@ +name = "DependentEnv" +uuid = "c9261501-a1a4-4a21-a37c-0c7025a0fef8" +version = "0.0.0" + +[deps] +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/sources/DependentEnv/src/DependentEnv.jl b/test/sources/DependentEnv/src/DependentEnv.jl new file mode 100644 index 0000000..263d273 --- /dev/null +++ b/test/sources/DependentEnv/src/DependentEnv.jl @@ -0,0 +1,6 @@ +module DependentEnv +using JSON + +foo() = 40 + +end diff --git a/test/sources/MainEnv/Project.toml b/test/sources/MainEnv/Project.toml new file mode 100644 index 0000000..f433cc5 --- /dev/null +++ b/test/sources/MainEnv/Project.toml @@ -0,0 +1,16 @@ +name = "MainEnv" +uuid = "1b324c26-e66a-4bf4-9aeb-d8ecf06e8e93" +version = "0.0.0" + +[deps] +DependentEnv = "c9261501-a1a4-4a21-a37c-0c7025a0fef8" +TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" + +[sources] +DependentEnv = {path = "../DependentEnv"} + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/sources/MainEnv/src/MainEnv.jl b/test/sources/MainEnv/src/MainEnv.jl new file mode 100644 index 0000000..58f39f7 --- /dev/null +++ b/test/sources/MainEnv/src/MainEnv.jl @@ -0,0 +1,6 @@ +module MainEnv +using DependentEnv + +bar() = DependentEnv.foo() + 2 + +end diff --git a/test/sources/MainEnv/test/runtests.jl b/test/sources/MainEnv/test/runtests.jl new file mode 100644 index 0000000..a6fa9ae --- /dev/null +++ b/test/sources/MainEnv/test/runtests.jl @@ -0,0 +1,4 @@ +using MainEnv +using Test + +@test MainEnv.bar() == 42