Skip to content

Commit

Permalink
gluedeps -> weakdeps
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Nov 30, 2022
1 parent d0c879e commit e19710b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
46 changes: 23 additions & 23 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -758,14 +758,14 @@ function explicit_manifest_deps_get(project_file::String, where::PkgId, name::St
glue_entry = gluepkgs[where.name]
if glue_entry isa String && name == glue_entry ||
glue_entry isa Vector{String} && name in glue_entry
gluedeps = get(entry, "gluedeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if gluedeps !== nothing
if gluedeps isa Vector{String}
found_name = name in gluedeps
weakdeps = get(entry, "weakdeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if weakdeps !== nothing
if weakdeps isa Vector{String}
found_name = name in weakdeps
break
elseif gluedeps isa Dict{String, Any}
gluedeps = gluedeps::Dict{String, Any}
for (dep, uuid) in gluedeps
elseif weakdeps isa Dict{String, Any}
weakdeps = weakdeps::Dict{String, Any}
for (dep, uuid) in weakdeps
uuid::String
if dep === name
return PkgId(UUID(uuid), name)
Expand Down Expand Up @@ -816,8 +816,8 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
for (name, entries::Vector{Any}) in d
for entry in entries
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
gluedeps = get(entry, "gluepkgs", nothing)::Union{Nothing, Dict{String, Any}}
if gluedeps !== nothing && pkg.name in keys(gluedeps) && uuid !== nothing && uuid5(UUID(uuid), pkg.name) == pkg.uuid
weakdeps = get(entry, "gluepkgs", nothing)::Union{Nothing, Dict{String, Any}}
if weakdeps !== nothing && haskey(weakdeps, pkg.name) && uuid !== nothing && uuid5(UUID(uuid), pkg.name) == pkg.uuid
p = normpath(dirname(locate_package(PkgId(UUID(uuid), name))), "..")
gluefile = joinpath(p, "glue", pkg.name * ".jl")
isfile(gluefile) && return gluefile
Expand Down Expand Up @@ -1061,11 +1061,11 @@ end

function insert_glue_triggers_project(project_file::String, parent::PkgId)
d = parsed_toml(project_file)
gluedeps = get(d, "gluedeps", nothing)::Union{Nothing, Dict{String, Any}}
weakdeps = get(d, "weakdeps", nothing)::Union{Nothing, Dict{String, Any}}
gluepkgs = get(d, "gluepkgs", nothing)::Union{Nothing, Dict{String, Any}}
gluepkgs === nothing && return
gluedeps === nothing && return
_insert_glue_triggers(parent, gluepkgs, gluedeps)
weakdeps === nothing && return
_insert_glue_triggers(parent, gluepkgs, weakdeps)
end

function insert_glue_triggers_manifest(project_file::String, parent::PkgId)
Expand All @@ -1079,41 +1079,41 @@ function insert_glue_triggers_manifest(project_file::String, parent::PkgId)
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
uuid === nothing && continue
if UUID(uuid) === parent.uuid
gluedeps = get(entry, "gluedeps", nothing)::Union{Nothing, Vector{String}, Dict{String,Any}}
weakdeps = get(entry, "weakdeps", nothing)::Union{Nothing, Vector{String}, Dict{String,Any}}
gluepkgs = get(entry, "gluepkgs", nothing)::Union{Nothing, Dict{String, Any}}
gluepkgs === nothing && return
gluedeps === nothing && return
if gluedeps isa Dict{String, Any}
return _insert_glue_triggers(parent, gluepkgs, gluedeps)
weakdeps === nothing && return
if weakdeps isa Dict{String, Any}
return _insert_glue_triggers(parent, gluepkgs, weakdeps)
end

d_gluedeps = Dict{String, String}()
d_weakdeps = Dict{String, String}()
for (dep_name, entries) in d
dep_name in gluedeps || continue
dep_name in weakdeps || continue
entries::Vector{Any}
if length(entries) != 1
error("expected a single entry for $(repr(name)) in $(repr(project_file))")
end
entry = first(entries)::Dict{String, Any}
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
d_gluedeps[dep_name] = uuid
d_weakdeps[dep_name] = uuid
end
@assert length(d_gluedeps) == length(gluedeps)
return _insert_glue_triggers(parent, gluepkgs, d_gluedeps)
@assert length(d_weakdeps) == length(weakdeps)
return _insert_glue_triggers(parent, gluepkgs, d_weakdeps)
end
end
end
return
end

function _insert_glue_triggers(parent::PkgId, gluepkgs::Dict{String, <:Any}, gluedeps::Dict{String, <:Any})
function _insert_glue_triggers(parent::PkgId, gluepkgs::Dict{String, <:Any}, weakdeps::Dict{String, <:Any})
for (glue_entry::String, triggers::Union{String, Vector{String}}) in gluepkgs
triggers isa String && (triggers = [triggers])
triggers_id = PkgId[]
id = PkgId(uuid5(parent.uuid, glue_entry), glue_entry)
for trigger in triggers
# TODO: Better error message if this lookup fails?
uuid_trigger = UUID(gluedeps[trigger]::String)
uuid_trigger = UUID(weakdeps[trigger]::String)
push!(triggers_id, PkgId(uuid_trigger, trigger))
end
gid = GlueId(id, parent, triggers_id, false, false)
Expand Down
17 changes: 8 additions & 9 deletions doc/src/manual/code-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,25 +350,24 @@ The subscripted `rootsᵢ`, `graphᵢ` and `pathsᵢ` variables correspond to th
Since the primary environment is typically the environment of a project you're working on, while environments later in the stack contain additional tools, this is the right trade-off: it's better to break your development tools but keep the project working. When such incompatibilities occur, you'll typically want to upgrade your dev tools to versions that are compatible with the main project.
### "Glue" packages and dependencies

A "glue package" is a module that is automatically loaded when a specified set of other packages (called "glue dependencies") are loaded in the current Julia session.
These are defined by adding the following two sections to a package's `Project.toml` file:
A "glue package" is a module that is automatically loaded when a specified set of other packages (its "glue dependencies") are loaded in the current Julia session. The glue dependencies of a glue package is a subset of those packages listed under the `[weakdeps]` section of a Project file. Glue packages are defined under the `[gluepkgs]` section in the project file:

```toml
name = "MyPackage"

[gluedeps]
[weakdeps]
GlueDep = "c9a23..." # uuid
OtherGlueDep = "862e..." # uuid

[gluepkgs]
GlueFoo = "GlueDep"
GlueBar = ["GlueDep", "OtherGlueDep"]
GlueFoo = "GlueDep"
...
```

The keys under `gluepkgs` are the name of the glue packages.
They are loaded when all the packages on the right hand side (the glue dependencies) of the glue package are loaded.
If a glue package only has one glue dependency the lit of glue dependencies can be written as just a string for breviety.
They are loaded when all the packages on the right hand side (the glue dependencies) of that glue package are loaded.
If a glue package only has one glue dependency the list of glue dependencies can be written as just a string for brevity.
The location for the entry point of the glue package is either in `glue/GlueFoo.jl` or `glue/GlueFoo/GlueFoo.jl` for
glue package `GlueFoo`.
The content of a glue package is often structured as:
Expand All @@ -385,10 +384,10 @@ MyPackage.func(x::GlueDep.SomeStruct) = ...
end
```

When a package with glue packages is added to an environment, the `gluedeps` and `gluepkgs` sections
When a package with glue packages is added to an environment, the `weakdeps` and `gluepkgs` sections
are stored in the manifest file in the section for that package. The dependency lookup rules for
a package are the same as for its "parent" except that the listed glue dependencies are also
part of its dependencies.
a package are the same as for its "parent" except that the listed glue dependencies are also considered as
dependencies.
### Package/Environment Preferences

Preferences are dictionaries of metadata that influence package behavior within an environment.
Expand Down
2 changes: 1 addition & 1 deletion test/project/GluePkgs/HasDepWithGluePkgs.jl/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uuid = "55982ee5-2ad5-4c40-8cfe-5e9e1b01500d"
version = "0.1.0"

[[deps.HasGluePkgs]]
gluedeps = ["GlueDep", "GlueDep2"]
weakdeps = ["GlueDep", "GlueDep2"]
path = "../HasGluePkgs.jl"
uuid = "4d3288b3-3afc-4bb6-85f3-489fffe514c8"
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion test/project/GluePkgs/HasGluePkgs.jl/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "HasGluePkgs"
uuid = "4d3288b3-3afc-4bb6-85f3-489fffe514c8"
version = "0.1.0"

[gluedeps]
[weakdeps]
GlueDep = "fa069be4-f60b-4d4c-8b95-f8008775090c"
GlueDep2 = "55982ee5-2ad5-4c40-8cfe-5e9e1b01500d"

Expand Down

0 comments on commit e19710b

Please sign in to comment.