You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds the `CompilePreferences` standard library; a way to store a
TOML-serializable dictionary into top-level `Project.toml` files, then
force recompilation of child projects when the preferences are modified.
This commid adds the `CompilePreferences` standard library, which does
the actual writing to `Project.toml` files, as well as modifies the
loading code to check whether the preferences have changed.
@debug"Rejecting cache file $cachefile because preferences hash does not match 0x$(string(prefs_hash, base=16)) != 0x$(string(curr_prefs_hash, base=16))"
Julia's `CompilePreferences` API requires at least Julia 1.6.
5
+
6
+
`CompilePreferences` support embedding a simple `Dict` of metadata for a package on a per-project basis. These preferences allow for packages to set simple, persistent pieces of data that the user has selected, that can persist across multiple versions of a package.
7
+
8
+
## API Overview
9
+
10
+
`CompilePreferences` are used primarily through the `@load_preferences`, `@save_preferences` and `@modify_preferences` macros. These macros will auto-detect the UUID of the calling package, throwing an error if the calling module does not belong to a package. The function forms can be used to load, save or modify preferences belonging to another package.
11
+
12
+
Example usage:
13
+
14
+
```julia
15
+
using CompilePreferences
16
+
17
+
functionget_preferred_backend()
18
+
prefs =@load_preferences()
19
+
returnget(prefs, "backend", "native")
20
+
end
21
+
22
+
functionset_backend(new_backend)
23
+
@modify_preferences!() do prefs
24
+
prefs["backend"] = new_backend
25
+
end
26
+
end
27
+
```
28
+
29
+
By default, preferences are stored within the `Project.toml` file of the currently-active project, and as such all new projects will start from a blank state, with all preferences being un-set.
30
+
Package authors that wish to have a default value set for their preferences should use the `get(prefs, key, default)` pattern as shown in the code example above.
31
+
32
+
# API Reference
33
+
34
+
!!! compat "Julia 1.6"
35
+
Julia's `CompilePreferences` API requires at least Julia 1.6.
0 commit comments