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

collect e.g. weak deps from project even if it is not a package #3852

Merged
merged 9 commits into from
Mar 22, 2024
Merged
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
38 changes: 19 additions & 19 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,14 @@ 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)
julia_compat = get_compat(project, "julia")
if !isnothing(julia_compat) && !(VERSION in julia_compat)
pkgerror("julia version requirement from Project.toml's compat section not satisfied for package $(err_rep(pkg)) at `$path`")
pkgerror("julia version requirement from Project.toml's compat section not satisfied for package at `$path`")
end
for (name, uuid) in project.deps
path, repo = get_path_repo(project, name)
Expand All @@ -267,11 +264,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 @@ -309,13 +308,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
# add repo package if necessary
if (pkg.repo.rev !== nothing || pkg.repo.source !== nothing) && pkg.tree_hash === nothing
Expand Down Expand Up @@ -345,7 +344,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 @@ -417,7 +417,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 @@ -93,4 +94,15 @@ using Test
@test proj.extras == Dict{String, Base.UUID}("Example" => Base.UUID("7876af07-990d-54b4-ab0e-23690620f79a"))
end
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"
Loading