@@ -6,23 +6,14 @@ Module providing basic tools to manage a *package registry*, by which is meant a
6
6
environment, together with "package metata", in the form of a dictionary of TOML-parsable
7
7
values, keyed on the environment's package dependencies, which is stored in a TOML
8
8
file. (This file is called Metadata.toml and is located in the same folder as environment
9
- Project.toml file.)re Not to be confused with a package registry in the sense of the
9
+ Project.toml file.) Not to be confused with a package registry in the sense of the
10
10
standard library, `Pkg`.
11
11
12
12
# Methods
13
13
14
14
- `GenericRegistry.dependencies(environment)`: Get a list of the environment's
15
15
dependencies (vector of package name strings).
16
16
17
- - [`GenericRegistry.run`](@ref): In a new Julia process, load a package (or packages) from
18
- the package environment and execute a Julia expression there; results are returned as
19
- `Future` objects, to allow asynchronous `run` calls. Useful for generating metadata about
20
- a package.
21
-
22
- - `GenericRegistry.close(future)`: Shut down the process intitiated by the `run`
23
- call that returned `future` (after calling `fetch(future)` to get the result of
24
- evaluation).
25
-
26
17
- [`GenericRegistry.put`](@ref): Insert an item in the metadata dictionary
27
18
28
19
- [`GenericRegistry.get`](@ref): Inspect the metadata
@@ -31,6 +22,14 @@ standard library, `Pkg`.
31
22
no longer dependencies in the environment. (In any case, `get` will return `nothing` for
32
23
any `pkg` not currently a dependency.)
33
24
25
+ - [`GenericRegistry.run`](@ref): In a new Julia process, load a package or packages and
26
+ execute a Julia expression there; results are returned as `Future` objects, to allow
27
+ asynchronous `run` calls. Useful for generating metadata about a package.
28
+
29
+ - [`GenericRegistry.close(future)`](@ref): Shut down the process intitiated by the `run`
30
+ call that returned `future` (after calling `fetch(future)` to get the result of
31
+ evaluation).
32
+
34
33
# Example
35
34
36
35
```julia
@@ -44,13 +43,13 @@ Pkg.status()
44
43
45
44
Pkg.activate(temp=true)
46
45
Pkg.add("MLJModelRegistry")
47
- using MLJModels .GenericRegistry
46
+ using MLJModelRegistry .GenericRegistry
48
47
packages = GenericRegistry.dependencies(env)
49
48
# 2-element Vector{String}:
50
49
# "Tables"
51
50
# "Example"
52
51
53
- future = GenericRegistry.run(:(names(Tables)), ["Tables",], env )
52
+ future = GenericRegistry.run(["Tables",], :(names(Tables)) )
54
53
value = fetch(future)
55
54
# 3-element Vector{Symbol}:
56
55
# :Tables
@@ -59,8 +58,8 @@ value = fetch(future)
59
58
60
59
GenericRegistry.close(future)
61
60
GenericRegistry.put("Tables", string.(value), env)
62
- less ("/Users/anthony/MyEnv/Metadata.toml")
63
- # Tables = ["Tables", "columntable", "rowtable"]
61
+ read ("/Users/anthony/MyEnv/Metadata.toml", String )
62
+ # " Tables = [\ " Tables\ " , \ " columntable\ " , \ " rowtable\" ] \n "
64
63
65
64
GenericRegistry.get("Tables", env)
66
65
# 3-element Vector{String}:
@@ -78,11 +77,6 @@ import Pkg.TOML as TOML
78
77
79
78
# # LOGGING
80
79
81
- err_missing_packages (pkgs) = ArgumentError (
82
- " One or more of the following specified packages are not " *
83
- " dependencies in the specified environment. "
84
- )
85
-
86
80
err_invalid_package (pkg) = ArgumentError (
87
81
" The package \" $pkg \" is an invalid key, as it is " *
88
82
" not a dependency in the specified environment. "
@@ -117,47 +111,44 @@ end
117
111
# # METHODS
118
112
119
113
"""
120
- GenericRegistry.run(ex, pkgs[, environment])
114
+ GenericRegistry.run([setup,] packages, program)
115
+
116
+ In a temporary Julia process, and using a temporary package environment, do this:
121
117
122
- In a temporary Julia process, evaluate the expression `ex` after importing the specified
123
- packages, `pkgs`, using an instantiated version of the specified package `environment`,
124
- when specified. If `environment` is omitted, a fresh temporary environment is created, and
125
- populated by only the specified packages, before instantiation.
118
+ 1. Evaluate the `setup` expression (if present).
119
+
120
+ 2. Add the specified `packages` to the environment, and instantiate.
121
+
122
+ 3. Evaluate the `program` expression.
126
123
127
124
The returned value is a `Future` object which must be `fetch`ed to get the actual
128
125
evaluated expression. Shut the temporary process down by calling `close` on the `Future`.
129
126
130
127
"""
131
- function run (ex, pkgs, env)
132
- pkgs isa Vector || (pkgs = [pkgs,])
133
- issubset (pkgs, dependencies (env)) || throw (err_missing_packages (pkgs))
134
- imports = [:(import $ (Symbol (pkg))) for pkg in pkgs]
135
- program = quote
136
- using Pkg
137
- Pkg. activate ($ env)
138
- Pkg. instantiate ()
139
- $ (imports... )
140
- $ ex
141
- end
142
- return run_in_temporary_process (program)
143
- end
144
-
145
- function run (ex, pkgs)
128
+ function run (setup, pkgs, program)
146
129
pkgs isa Vector || (pkgs = [pkgs,])
147
130
additions = [:(Pkg. add ($ pkg)) for pkg in pkgs]
148
131
imports = [:(import $ (Symbol (pkg))) for pkg in pkgs]
149
132
program = quote
150
133
using Pkg
151
134
Pkg. activate (temp= true )
152
135
$ (additions... )
136
+ $ setup
153
137
Pkg. instantiate ()
154
138
$ (imports... )
155
- $ ex
139
+ $ program
156
140
end
157
- @show program
158
141
return run_in_temporary_process (program)
159
142
end
143
+ run (pkgs, program) = run (:(), pkgs, program)
144
+
145
+ """
146
+ GenericRegistry.close(future)
147
+
148
+ Shut down the Julia process whose output was encapsulated by the `Future` instance,
149
+ `future`.
160
150
151
+ """
161
152
close (future) = rmprocs (future. where)
162
153
163
154
"""
0 commit comments