Skip to content

Commit

Permalink
collect e.g. weak deps from project even if it is not a package (#3852)
Browse files Browse the repository at this point in the history
* collect e.g. weak deps from project even if it is not a package

(cherry picked from commit 9c6356f)
  • Loading branch information
KristofferC authored and KristofferC committed Oct 30, 2024
1 parent 35358a4 commit 691510b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,16 @@ function reset_all_compat!(proj::Project)
return nothing
end

function collect_project(pkg::PackageSpec, path::String)
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String)
deps = PackageSpec[]
weakdeps = Set{UUID}()
project_file = projectfile_path(path; strict=true)
if project_file === nothing
pkgerror("could not find project file for package $(err_rep(pkg)) at `$path`")
end
project = read_package(project_file)
project = project_file === nothing ? Project() : read_project(project_file)
#=
# TODO, this should either error or be quiet
julia_compat = get_compat(project, "julia")
if julia_compat !== nothing && !(VERSION in julia_compat)
println(io, "julia version requirement for package $(err_rep(pkg)) not satisfied")
println(io, "julia version requirement for package at `$path`"")
end
=#
for (name, uuid) in project.deps
Expand All @@ -264,11 +261,13 @@ function collect_project(pkg::PackageSpec, path::String)
push!(deps, PackageSpec(name, uuid, vspec))
push!(weakdeps, uuid)
end
if project.version !== nothing
pkg.version = project.version
else
# @warn("project file for $(pkg.name) is missing a `version` entry")
pkg.version = VersionNumber(0)
if pkg !== nothing
if project.version !== nothing
pkg.version = project.version
else
# @warn("project file for $(pkg.name) is missing a `version` entry")
pkg.version = VersionNumber(0)
end
end
return deps, weakdeps
end
Expand Down Expand Up @@ -306,13 +305,13 @@ end
function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UUID, String})
deps_map = Dict{UUID,Vector{PackageSpec}}()
weak_map = Dict{UUID,Set{UUID}}()
if env.pkg !== nothing
pkg = env.pkg
deps, weakdeps = collect_project(pkg, dirname(env.project_file))
deps_map[pkg.uuid] = deps
weak_map[pkg.uuid] = weakdeps
names[pkg.uuid] = pkg.name
end

uuid = Types.project_uuid(env)
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file))
deps_map[uuid] = deps
weak_map[uuid] = weakdeps
names[uuid] = env.pkg === nothing ? "project" : env.pkg.name

for pkg in pkgs
path = project_rel_path(env, source_path(env.manifest_file, pkg))
if !isdir(path)
Expand All @@ -337,7 +336,8 @@ function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UU
idx = findfirst(pkg -> pkg.uuid == uuid, pkgs)
fix_pkg = pkgs[idx]
end
fixed[uuid] = Resolve.Fixed(fix_pkg.version, q, weak_map[uuid])
fixpkgversion = fix_pkg === nothing ? v"0.0.0" : fix_pkg.version
fixed[uuid] = Resolve.Fixed(fixpkgversion, q, weak_map[uuid])
end
return fixed
end
Expand Down
2 changes: 1 addition & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Base.@kwdef mutable struct Context
julia_version::Union{VersionNumber,Nothing} = VERSION
end

project_uuid(env::EnvCache) = env.pkg === nothing ? nothing : env.pkg.uuid
project_uuid(env::EnvCache) = env.pkg === nothing ? Base.dummy_uuid(env.project_file) : env.pkg.uuid
collides_with_project(env::EnvCache, pkg::PackageSpec) =
is_project_name(env, pkg.name) || is_project_uuid(env, pkg.uuid)
is_project(env::EnvCache, pkg::PackageSpec) = is_project_uuid(env, pkg.uuid)
Expand Down
12 changes: 12 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using .Utils
using Test
using UUIDs

@testset "weak deps" begin
he_root = joinpath(@__DIR__, "test_packages", "ExtensionExamples", "HasExtensions.jl")
Expand Down Expand Up @@ -78,4 +79,15 @@ using Test
@test occursin("HasExtensions", out)
@test occursin("HasDepWithExtensions", out)
end

isolate(loaded_depot=false) do
mktempdir() do dir
Pkg.Registry.add("General")
path = joinpath(@__DIR__, "test_packages", "TestWeakDepProject")
cp(path, joinpath(dir, "TestWeakDepProject"))
Pkg.activate(joinpath(dir, "TestWeakDepProject"))
Pkg.resolve()
@test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26"
end
end
end
9 changes: 9 additions & 0 deletions test/test_packages/TestWeakDepProject/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

[weakdeps]
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"

[compat]
ForwardDiff = "=0.10.36"
LogExpFunctions = "=0.3.26"

0 comments on commit 691510b

Please sign in to comment.