Skip to content

Commit

Permalink
Merge pull request #4112 from JuliaLang/backports-release-1.10
Browse files Browse the repository at this point in the history
Backports release 1.10
  • Loading branch information
KristofferC authored Dec 13, 2024
2 parents 407e140 + be8f4ca commit 0ac49eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
18 changes: 9 additions & 9 deletions docs/src/creating-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
# name of extension to the left
# extension dependencies required to load the extension to the right
# use a list for multiple extension dependencies
PlottingContourExt = "Contour"
ContourExt = "Contour"

[compat]
Contour = "0.6.2"
Expand All @@ -341,9 +341,9 @@ end
end # module
```

`ext/PlottingContourExt.jl` (can also be in `ext/PlottingContourExt/PlottingContourExt.jl`):
`ext/ContourExt.jl` (can also be in `ext/ContourExt/ContourExt.jl`):
```julia
module PlottingContourExt # Should be same name as the file (just like a normal package)
module ContourExt # Should be same name as the file (just like a normal package)

using Plotting, Contour

Expand All @@ -354,8 +354,8 @@ end
end # module
```

Extensions can have any arbitrary name (here `PlottingContourExt`), but using something similar to the format of
this example that makes the extended functionality and dependency of the extension clear is likely a good idea.
Extensions can have arbitrary names (here `ContourExt`), following the format of this example is likely a good idea for extensions with a single dependency.
In `Pkg` output, extension names are always shown together with their parent package name.

A user that depends only on `Plotting` will not pay the cost of the "extension" inside the `PlottingContourExt` module.
It is only when the `Contour` package actually gets loaded that the `PlottingContourExt` extension is loaded
Expand Down Expand Up @@ -396,7 +396,7 @@ This is done by making the following changes (using the example above):

@static if !isdefined(Base, :get_extension)
function __init__()
@require Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/PlottingContourExt.jl")
@require Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/ContourExt.jl")
end
end
```
Expand All @@ -410,11 +410,11 @@ This is done by making the following changes (using the example above):
# Other init functionality here

@static if !isdefined(Base, :get_extension)
@require Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/PlottingContourExt.jl")
@require Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/ContourExt.jl")
end
end
```
- Make the following change in the conditionally-loaded code:
- Make the following change in the conditionally-loaded code in `ContourExt.jl`:
```julia
isdefined(Base, :get_extension) ? (using Contour) : (using ..Contour)
```
Expand All @@ -431,7 +431,7 @@ This is done by making the following changes (using the example above):
- Add the following to your main package file (typically at the bottom):
```julia
if !isdefined(Base, :get_extension)
include("../ext/PlottingContourExt.jl")
include("../ext/ContourExt.jl")
end
```

Expand Down
9 changes: 6 additions & 3 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ function _mv_temp_artifact_dir(temp_dir::String, new_path::String)::Nothing
Base.uv_error("rename of $(repr(temp_dir)) to $(repr(new_path))", err)
end
end
chmod(new_path, filemode(dirname(new_path)))
set_readonly(new_path)
end
end

Expand Down Expand Up @@ -395,7 +393,12 @@ function download_artifact(
return err
finally
# Always attempt to cleanup
rm(temp_dir; recursive=true, force=true)
try
rm(temp_dir; recursive=true, force=true)
catch e
e isa InterruptException && rethrow()
@warn("Failed to clean up temporary directory $(repr(temp_dir))", exception=e)
end
end
return true
end
Expand Down
4 changes: 2 additions & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ function collect_project(pkg::Union{PackageSpec, Nothing}, path::String)
#=
# 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 at `$path`"")
if !isnothing(julia_compat) && !(VERSION in julia_compat)
pkgerror("julia version requirement from Project.toml's compat section not satisfied for package at `$path`")
end
=#
for (name, uuid) in project.deps
Expand Down
20 changes: 20 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,24 @@ using UUIDs
@test !("LogExpFunctions" in keys(ctx.env.project.weakdeps))
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"

# Check that explicitly adding a package that is a weak dep removes it from the set of weak deps
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.weakdeps)
@test !("LogExpFunctions" in keys(ctx.env.project.deps))
Pkg.add("LogExpFunctions")
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.deps)
@test !("LogExpFunctions" in keys(ctx.env.project.weakdeps))
end
end
end

0 comments on commit 0ac49eb

Please sign in to comment.