Skip to content

Commit bd136fc

Browse files
committed
Clean-up release 1.4 branch
1 parent 53390df commit bd136fc

8 files changed

+98
-300
lines changed

Project.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
77

88
[compat]
99
ChainRulesCore = "=1.0.2"
10+
MCMCDiagnosticTools = "=0.1.0"
11+
YAXArrays = "0.1.3"
1012
julia = "~1.4, ~1.5, ~1.6"
1113

1214
[extras]
1315
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
16+
MCMCDiagnosticTools = "be115224-59cd-429b-ad48-344e309966f0"
1417
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
1519

1620
[targets]
17-
test = ["ChainRulesCore", "Test"]
21+
test = ["ChainRulesCore", "MCMCDiagnosticTools", "Test", "YAXArrays"]

src/TestEnv.jl

+4-27
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,10 @@ using Pkg.Operations: manifest_info, manifest_resolve!, project_deps_resolve!
66
using Pkg.Operations: project_rel_path, project_resolve!
77

88
using Pkg.Types: Types, projectfile_path, manifestfile_path
9-
10-
# Version specific imports
11-
@static if VERSION >= v"1.4.0"
12-
using Pkg.Operations: gen_target_project
13-
else
14-
using Pkg.Operations: with_dependencies_loadable_at_toplevel
15-
end
16-
@static if isdefined(Pkg.Operations, :update_package_test!)
17-
using Pkg.Operations: update_package_test!
18-
else
19-
function update_package_test!(pkg, entry)
20-
is_stdlib(pkg.uuid) && return
21-
pkg.version = entry.version
22-
pkg.tree_hash = entry.tree_hash
23-
pkg.repo = entry.repo
24-
pkg.path = entry.path
25-
pkg.pinned = entry.pinned
26-
end
27-
end
28-
29-
@static if VERSION >= v"1.2.0"
30-
using Pkg.Types: is_stdlib
31-
using Pkg.Operations: sandbox, source_path, sandbox_preserve, abspath!
32-
else
33-
using Pkg.Operations: find_installed
34-
using Pkg.Types: SHA1
35-
end
9+
using Pkg.Operations: gen_target_project
10+
using Pkg.Operations: update_package_test!
11+
using Pkg.Types: is_stdlib
12+
using Pkg.Operations: sandbox, source_path, sandbox_preserve, abspath!
3613

3714

3815
include("exceptions.jl")

src/activate.jl

+4-15
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,12 @@ is of type `Pkg.Types.Context`. For earlier versions, they are of type
4444
`Pkg.Types.EnvCache`.
4545
"""
4646
function isinstalled!(ctx::Context, pkgspec::Pkg.Types.PackageSpec)
47-
var = @static if v"1.4.0" <= VERSION < v"1.7.0-"
48-
ctx
49-
else
50-
ctx.env
51-
end
52-
project_resolve!(var, [pkgspec])
53-
project_deps_resolve!(var, [pkgspec])
54-
55-
manifest = @static if VERSION < v"1.7.0-"
56-
var
57-
else
58-
var.manifest
59-
end
60-
manifest_resolve!(manifest, [pkgspec])
47+
project_resolve!(ctx, [pkgspec])
48+
project_deps_resolve!(ctx, [pkgspec])
49+
manifest_resolve!(ctx, [pkgspec])
6150

6251
try
63-
ensure_resolved(manifest, [pkgspec])
52+
ensure_resolved(ctx, [pkgspec])
6453
catch err
6554
err isa MethodError && rethrow()
6655
return false

src/make_test_env.jl

+68-91
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,85 @@
11

22
# Originally from Pkg.Operations.sandbox
3-
@static if VERSION <= v"1.1" # 1.0 or 1.1
4-
# For now will just abuse that we solved sandbox
5-
function make_test_env(ctx::Context, pkgspec)
6-
safe_dir = mktempdir()
7-
_sandbox(ctx, pkgspec) do
8-
cp(Base.active_project(), joinpath(safe_dir, "Project.toml"))
9-
end
10-
Pkg.activate(safe_dir)
11-
Pkg.resolve()
12-
return nothing
3+
function make_test_env(ctx::Context, target)
4+
# This needs to be first as `gen_target_project` fixes `target.path` if it is nothing
5+
sandbox_project_override = if !test_dir_has_project_file(ctx, target)
6+
sandbox_project_override = gen_target_project(ctx, target, target.path, "test")
7+
else
8+
nothing
139
end
14-
else
15-
function make_test_env(ctx::Context, target)
16-
# This needs to be first as `gen_target_project` fixes `target.path` if it is nothing
17-
sandbox_project_override = if !test_dir_has_project_file(ctx, target)
18-
sandbox_project_override = @static if VERSION < v"1.7-a"
19-
gen_target_project(ctx, target, target.path, "test")
20-
else
21-
gen_target_project(ctx.env, ctx.registries, target, target.path, "test")
22-
end
23-
else
24-
nothing
25-
end
2610

27-
sandbox_path = joinpath(target.path, "test")
28-
sandbox_project = projectfile_path(sandbox_path)
11+
sandbox_path = joinpath(target.path, "test")
12+
sandbox_project = projectfile_path(sandbox_path)
2913

30-
tmp = mktempdir()
31-
tmp_project = projectfile_path(tmp)
32-
tmp_manifest = manifestfile_path(tmp)
14+
tmp = mktempdir()
15+
tmp_project = projectfile_path(tmp)
16+
tmp_manifest = manifestfile_path(tmp)
3317

34-
# Copy env info over to temp env
35-
if sandbox_project_override !== nothing
36-
Types.write_project(sandbox_project_override, tmp_project)
37-
elseif isfile(sandbox_project)
38-
cp(sandbox_project, tmp_project)
39-
chmod(tmp_project, 0o600)
40-
end
41-
# create merged manifest
42-
# - copy over active subgraph
43-
# - abspath! to maintain location of all deved nodes
44-
working_manifest = if VERSION <= v"1.7-a"
45-
abspath!(ctx, sandbox_preserve(ctx, target, tmp_project))
46-
else
47-
abspath!(ctx.env, sandbox_preserve(ctx.env, target, tmp_project))
48-
end
49-
# - copy over fixed subgraphs from test subgraph
50-
# really only need to copy over "special" nodes
51-
sandbox_env = Types.EnvCache(projectfile_path(sandbox_path))
52-
sandbox_manifest = if VERSION <= v"1.7-a"
53-
abspath!(sandbox_path, sandbox_env.manifest)
54-
else
55-
abspath!(sandbox_env, sandbox_env.manifest)
56-
end
57-
for (name, uuid) in sandbox_env.project.deps
58-
entry = get(sandbox_manifest, uuid, nothing)
59-
if entry !== nothing && isfixed(entry)
60-
subgraph = prune_manifest(sandbox_manifest, [uuid])
61-
for (uuid, entry) in subgraph
62-
if haskey(working_manifest, uuid)
63-
pkgerror("can not merge projects")
64-
end
65-
working_manifest[uuid] = entry
18+
# Copy env info over to temp env
19+
if sandbox_project_override !== nothing
20+
Types.write_project(sandbox_project_override, tmp_project)
21+
elseif isfile(sandbox_project)
22+
cp(sandbox_project, tmp_project)
23+
chmod(tmp_project, 0o600)
24+
end
25+
# create merged manifest
26+
# - copy over active subgraph
27+
# - abspath! to maintain location of all deved nodes
28+
working_manifest = abspath!(ctx, sandbox_preserve(ctx, target, tmp_project))
29+
30+
# - copy over fixed subgraphs from test subgraph
31+
# really only need to copy over "special" nodes
32+
sandbox_env = Types.EnvCache(projectfile_path(sandbox_path))
33+
sandbox_manifest = abspath!(sandbox_path, sandbox_env.manifest)
34+
35+
for (name, uuid) in sandbox_env.project.deps
36+
entry = get(sandbox_manifest, uuid, nothing)
37+
if entry !== nothing && isfixed(entry)
38+
subgraph = prune_manifest(sandbox_manifest, [uuid])
39+
for (uuid, entry) in subgraph
40+
if haskey(working_manifest, uuid)
41+
pkgerror("can not merge projects")
6642
end
43+
working_manifest[uuid] = entry
6744
end
6845
end
46+
end
6947

70-
Types.write_manifest(working_manifest, tmp_manifest)
48+
Types.write_manifest(working_manifest, tmp_manifest)
7149

72-
# sandbox
73-
push!(empty!(LOAD_PATH), "@", tmp)
74-
Base.ACTIVE_PROJECT[] = nothing
50+
# sandbox
51+
push!(empty!(LOAD_PATH), "@", tmp)
52+
Base.ACTIVE_PROJECT[] = nothing
7553

76-
temp_ctx = Context()
77-
temp_ctx.env.project.deps[target.name] = target.uuid
54+
temp_ctx = Context()
55+
temp_ctx.env.project.deps[target.name] = target.uuid
7856

79-
try
80-
Pkg.resolve(temp_ctx; io=devnull)
81-
@debug "Using _parent_ dep graph"
82-
catch err# TODO
83-
@debug err
84-
@warn "Could not use exact versions of packages in manifest, re-resolving"
85-
temp_ctx.env.manifest.deps = Dict(
86-
uuid => entry for
87-
(uuid, entry) in temp_ctx.env.manifest.deps if isfixed(entry)
88-
)
89-
Pkg.resolve(temp_ctx; io=devnull)
90-
@debug "Using _clean_ dep graph"
91-
end
57+
try
58+
Pkg.resolve(temp_ctx; io=devnull)
59+
@debug "Using _parent_ dep graph"
60+
catch err# TODO
61+
@debug err
62+
@warn "Could not use exact versions of packages in manifest, re-resolving"
63+
temp_ctx.env.manifest.deps = Dict(
64+
uuid => entry for
65+
(uuid, entry) in temp_ctx.env.manifest.deps if isfixed(entry)
66+
)
67+
Pkg.resolve(temp_ctx; io=devnull)
68+
@debug "Using _clean_ dep graph"
69+
end
9270

93-
# Absolutify stdlibs paths
94-
for (uuid, entry) in temp_ctx.env.manifest
95-
if is_stdlib(uuid)
96-
entry.path = Types.stdlib_path(entry.name)
97-
end
71+
# Absolutify stdlibs paths
72+
for (uuid, entry) in temp_ctx.env.manifest
73+
if is_stdlib(uuid)
74+
entry.path = Types.stdlib_path(entry.name)
9875
end
99-
write_env(temp_ctx.env; update_undo=false)
100-
101-
# update enviroment variables
102-
path_sep = Sys.iswindows() ? ';' : ':'
103-
ENV["JULIA_LOAD_PATH"] = "@$(path_sep)$(tmp)"
104-
delete!(ENV, "JULIA_PROJECT")
105-
106-
return Base.active_project()
10776
end
77+
write_env(temp_ctx.env; update_undo=false)
78+
79+
# update enviroment variables
80+
path_sep = Sys.iswindows() ? ';' : ':'
81+
ENV["JULIA_LOAD_PATH"] = "@$(path_sep)$(tmp)"
82+
delete!(ENV, "JULIA_PROJECT")
83+
84+
return Base.active_project()
10885
end

src/sandbox.jl

+8-47
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,11 @@
1-
2-
3-
if VERSION <= v"1.1" # 1.0 or 1.1
4-
_sandbox(f, ctx, pkgspec) = _manual_sandbox(f, ctx, pkgspec)
5-
elseif VERSION <= v"1.3" # 1.2 or 1.3
6-
function _sandbox(f, ctx, pkgspec)
7-
test_dir_has_project_file(ctx, pkgspec) || return _manual_sandbox(f, ctx, pkgspec)
8-
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test")) do
9-
flush(stdout)
10-
f()
11-
end
1+
function _sandbox(f, ctx, pkgspec)
2+
test_project_override = if !test_dir_has_project_file(ctx, pkgspec)
3+
gen_target_project(ctx, pkgspec, pkgspec.path, "test")
4+
else
5+
nothing
126
end
13-
elseif VERSION >= v"1.7-a"
14-
function _sandbox(f, ctx, pkgspec)
15-
test_project_override = if !test_dir_has_project_file(ctx, pkgspec)
16-
gen_target_project(ctx.env, ctx.registries, pkgspec, pkgspec.path, "test")
17-
else
18-
nothing
19-
end
20-
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test"), test_project_override) do
21-
flush(stdout)
22-
f()
23-
end
24-
end
25-
else
26-
@assert VERSION >= v"1.3"
27-
function _sandbox(f, ctx, pkgspec)
28-
test_project_override = if !test_dir_has_project_file(ctx, pkgspec)
29-
gen_target_project(ctx, pkgspec, pkgspec.path, "test")
30-
else
31-
nothing
32-
end
33-
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test"), test_project_override) do
34-
flush(stdout)
35-
f()
36-
end
7+
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test"), test_project_override) do
8+
flush(stdout)
9+
f()
3710
end
3811
end
39-
#sandbox(ctx::Context, target::PackageSpec, target_path::String,sandbox_path::String, sandbox_project_override)
40-
41-
function _manual_sandbox(f, ctx, pkgspec)
42-
with_dependencies_loadable_at_toplevel(ctx, pkgspec; might_need_to_resolve=true) do localctx
43-
Pkg.activate(localctx.env.project_file)
44-
try
45-
f()
46-
finally
47-
Pkg.activate(ctx.env.project_file)
48-
end
49-
end
50-
end

0 commit comments

Comments
 (0)