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

Fix activating [sources] with relative paths #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/julia-1.11/activate_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions test/activate_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/sources/DependentEnv/Project.toml
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions test/sources/DependentEnv/src/DependentEnv.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module DependentEnv
using JSON

foo() = 40

end
16 changes: 16 additions & 0 deletions test/sources/MainEnv/Project.toml
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions test/sources/MainEnv/src/MainEnv.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MainEnv
using DependentEnv

bar() = DependentEnv.foo() + 2

end
4 changes: 4 additions & 0 deletions test/sources/MainEnv/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using MainEnv
using Test

@test MainEnv.bar() == 42
Loading