-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
force_latest_compatible_version
keyword argument to Pkg.test
- Loading branch information
1 parent
8b0045d
commit 8d4a250
Showing
23 changed files
with
293 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# const Types = Pkg.Types | ||
# const load_direct_deps = Pkg.Operations.load_direct_deps | ||
# const load_manifest_deps = Pkg.Operations.load_manifest_deps | ||
# const stdlibs = Pkg.Types.stdlibs | ||
|
||
# activate ../Foo | ||
# ctx = Types.Context() | ||
|
||
function _force_latest_compatible_version(ctx::Types.Context; target_name = nothing) | ||
direct_deps = load_direct_deps(ctx.env) | ||
direct_deps_uuids = getproperty.(direct_deps, Ref(:uuid)) | ||
nonstdlib_direct_deps_uuids = filter(x -> x ∉ keys(stdlibs()), direct_deps_uuids) | ||
return _force_latest_compatible_version(ctx, nonstdlib_direct_deps_uuids; target_name) | ||
end | ||
|
||
function _force_latest_compatible_version(ctx::Types.Context, uuid_list::AbstractVector{Base.UUID}; | ||
target_name = nothing) | ||
isempty(uuid_list) && return true | ||
results = _force_latest_compatible_version.(Ref(ctx), uuid_list; target_name) | ||
return all(results) | ||
end | ||
|
||
function _force_latest_compatible_version(ctx::Types.Context, uuid::Base.UUID; | ||
target_name= nothing) | ||
manifest_deps = load_manifest_deps(ctx.env.manifest) | ||
manifest_deps_uuids = getproperty.(manifest_deps, Ref(:uuid)) | ||
idx = only(findall(manifest_deps_uuids .== uuid)) | ||
dep = manifest_deps[idx] | ||
name = dep.name | ||
active_version = dep.version | ||
if haskey(ctx.env.project.compat, name) | ||
compat_entry_string = ctx.env.project.compat[name] | ||
latest_compatible_version = _get_latest_compatible_version(ctx, uuid, compat_entry_string) | ||
else | ||
if name != target_name | ||
@warn( | ||
"Package does not have a [compat] entry", | ||
name, uuid, active_version, | ||
) | ||
end | ||
return true | ||
end | ||
result = active_version == latest_compatible_version | ||
if !result | ||
@error( | ||
"Package is not at the latest compatible version", | ||
name, uuid, active_version, | ||
latest_compatible_version, compat_entry_string, | ||
) | ||
end | ||
return result | ||
end | ||
|
||
function _get_latest_compatible_version(ctx::Types.Context, uuid::Base.UUID, | ||
compat_entry_string::AbstractString) | ||
all_registered_versions = _get_all_registered_versions(ctx, uuid) | ||
compat_spec = Pkg.Types.semver_spec(compat_entry_string) | ||
compatible_versions = filter(x -> x in compat_spec, all_registered_versions) | ||
latest_compatible_version = maximum(compatible_versions) | ||
return latest_compatible_version | ||
end | ||
|
||
function _get_all_registered_versions(ctx::Types.Context, uuid::Base.UUID) | ||
versions = Base.VersionNumber[] | ||
for reg in ctx.registries | ||
pkg = get(reg, uuid, nothing) | ||
pkg == nothing && continue | ||
info = Registry.registry_info(pkg) | ||
append!(versions, keys(info.version_info)) | ||
end | ||
unique!(versions) | ||
sort!(versions) | ||
return versions | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
module ForceLatestCompatibleVersionTests | ||
|
||
import ..Pkg # ensure we are using the correct Pkg | ||
import ..Utils | ||
using Test | ||
|
||
@testset "force_latest_compatible_version" begin | ||
@testset "`force_latest_compatible_version` kwarg to `Pkg.test`" begin | ||
parent_dir = joinpath(@__DIR__, "test_packages", "force_latest_compatible_version") | ||
|
||
@testset "OldOnly1: `SomePkg = \"=0.1.0\"`" begin | ||
mktempdir() do tmp_dir | ||
test_package = joinpath(tmp_dir, "OldOnly1") | ||
cp(joinpath(parent_dir, "OldOnly1"), test_package; force = true) | ||
Utils.isolate() do | ||
Pkg.activate(test_package) | ||
Pkg.instantiate() | ||
Pkg.build() | ||
@test Pkg.test(; force_latest_compatible_version = false) == nothing | ||
@test Pkg.test(; force_latest_compatible_version = true) == nothing | ||
end | ||
end | ||
end | ||
|
||
@testset "OldOnly2: `SomePkg = \"0.1\"`" begin | ||
mktempdir() do tmp_dir | ||
test_package = joinpath(tmp_dir, "OldOnly2") | ||
cp(joinpath(parent_dir, "OldOnly2"), test_package; force = true) | ||
Utils.isolate() do | ||
Pkg.activate(test_package) | ||
Pkg.instantiate() | ||
Pkg.build() | ||
@test Pkg.test(; force_latest_compatible_version = false) == nothing | ||
@test_throws Pkg.Types.PkgError Pkg.test(; force_latest_compatible_version = true) | ||
end | ||
end | ||
end | ||
|
||
@testset "BothOldAndNew: `SomePkg = \"0.1, 0.2\"`" begin | ||
mktempdir() do tmp_dir | ||
test_package = joinpath(tmp_dir, "BothOldAndNew") | ||
cp(joinpath(parent_dir, "BothOldAndNew"), test_package; force = true) | ||
Utils.isolate() do | ||
Pkg.activate(test_package) | ||
Pkg.instantiate() | ||
Pkg.build() | ||
@test Pkg.test(; force_latest_compatible_version = false) == nothing | ||
@test_throws Pkg.Types.PkgError Pkg.test(; force_latest_compatible_version = true) | ||
end | ||
end | ||
end | ||
|
||
@testset "NewOnly: `SomePkg = \"0.2\"`" begin | ||
mktempdir() do tmp_dir | ||
test_package = joinpath(tmp_dir, "NewOnly") | ||
cp(joinpath(parent_dir, "NewOnly"), test_package; force = true) | ||
Utils.isolate() do | ||
Pkg.activate(test_package) | ||
Pkg.instantiate() | ||
Pkg.build() | ||
@test_throws Pkg.Resolve.ResolverError Pkg.test(; force_latest_compatible_version = false) | ||
@test_throws Pkg.Resolve.ResolverError Pkg.test(; force_latest_compatible_version = true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end # module |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/test_packages/force_latest_compatible_version/BothOldAndNew/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Manifest.toml |
18 changes: 18 additions & 0 deletions
18
test/test_packages/force_latest_compatible_version/BothOldAndNew/Project.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = "BothOldAndNew" | ||
uuid = "ebb7d249-15d2-4389-abff-d529bd2cf37c" | ||
authors = ["Dilum Aluthge <dilum@aluthge.com>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea" | ||
|
||
[compat] | ||
MLJModelInterface = "0.1, 0.2" | ||
ScientificTypes = "0.6" | ||
|
||
[extras] | ||
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["ScientificTypes", "Test"] |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/BothOldAndNew/src/BothOldAndNew.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module BothOldAndNew | ||
|
||
import MLJModelInterface | ||
|
||
f(x) = x + x | ||
|
||
end # module |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/BothOldAndNew/test/runtests.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import BothOldAndNew | ||
import ScientificTypes | ||
import Test | ||
|
||
Test.@testset "BothOldAndNew.jl" begin | ||
Test.@test BothOldAndNew.f(1) == 2 | ||
end |
1 change: 1 addition & 0 deletions
1
test/test_packages/force_latest_compatible_version/NewOnly/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Manifest.toml |
18 changes: 18 additions & 0 deletions
18
test/test_packages/force_latest_compatible_version/NewOnly/Project.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = "NewOnly" | ||
uuid = "2c7b3c3b-62b6-437a-a36e-3d5963db0b1f" | ||
authors = ["Dilum Aluthge <dilum@aluthge.com>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea" | ||
|
||
[compat] | ||
MLJModelInterface = "0.2" | ||
ScientificTypes = "0.6" | ||
|
||
[extras] | ||
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["ScientificTypes", "Test"] |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/NewOnly/src/NewOnly.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module NewOnly | ||
|
||
import MLJModelInterface | ||
|
||
f(x) = x + x | ||
|
||
end # module |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/NewOnly/test/runtests.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import NewOnly | ||
import ScientificTypes | ||
import Test | ||
|
||
Test.@testset "NewOnly.jl" begin | ||
Test.@test NewOnly.f(1) == 2 | ||
end |
1 change: 1 addition & 0 deletions
1
test/test_packages/force_latest_compatible_version/OldOnly1/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Manifest.toml |
18 changes: 18 additions & 0 deletions
18
test/test_packages/force_latest_compatible_version/OldOnly1/Project.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = "OldOnly1" | ||
uuid = "abc047b9-6ad4-4533-a374-d50ae908e3e9" | ||
authors = ["Dilum Aluthge <dilum@aluthge.com>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea" | ||
|
||
[compat] | ||
MLJModelInterface = "=0.1.0" | ||
ScientificTypes = "0.6" | ||
|
||
[extras] | ||
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["ScientificTypes", "Test"] |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/OldOnly1/src/OldOnly1.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module OldOnly1 | ||
|
||
import MLJModelInterface | ||
|
||
f(x) = x + x | ||
|
||
end # module |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/OldOnly1/test/runtests.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import OldOnly1 | ||
import ScientificTypes | ||
import Test | ||
|
||
Test.@testset "OldOnly1.jl" begin | ||
Test.@test OldOnly1.f(1) == 2 | ||
end |
1 change: 1 addition & 0 deletions
1
test/test_packages/force_latest_compatible_version/OldOnly2/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Manifest.toml |
18 changes: 18 additions & 0 deletions
18
test/test_packages/force_latest_compatible_version/OldOnly2/Project.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = "OldOnly2" | ||
uuid = "abc047b9-6ad4-4533-a374-d50ae908e3e9" | ||
authors = ["Dilum Aluthge <dilum@aluthge.com>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea" | ||
|
||
[compat] | ||
MLJModelInterface = "0.1" | ||
ScientificTypes = "0.6" | ||
|
||
[extras] | ||
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["ScientificTypes", "Test"] |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/OldOnly2/src/OldOnly2.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module OldOnly2 | ||
|
||
import MLJModelInterface | ||
|
||
f(x) = x + x | ||
|
||
end # module |
7 changes: 7 additions & 0 deletions
7
test/test_packages/force_latest_compatible_version/OldOnly2/test/runtests.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import OldOnly2 | ||
import ScientificTypes | ||
import Test | ||
|
||
Test.@testset "OldOnly2.jl" begin | ||
Test.@test OldOnly2.f(1) == 2 | ||
end |