-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
CompilePreferences
standard library
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.
- Loading branch information
1 parent
b62ef14
commit 466867b
Showing
15 changed files
with
573 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ let | |
:Distributed, | ||
:SharedArrays, | ||
:TOML, | ||
:CompilePreferences, | ||
:Artifacts, | ||
:Pkg, | ||
:Test, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name = "CompilePreferences" | ||
uuid = "21216c6a-2e73-6563-6e65-726566657250" | ||
|
||
[deps] | ||
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" | ||
|
||
[extras] | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "Pkg"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# CompilePreferences | ||
|
||
!!! compat "Julia 1.6" | ||
Julia's `CompilePreferences` API requires at least Julia 1.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, and trigger recompilation of the package when the preferences change, to allow for customization of package behavior at compile-time. | ||
|
||
## API Overview | ||
|
||
`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. | ||
|
||
Example usage: | ||
|
||
```julia | ||
using CompilePreferences | ||
|
||
function get_preferred_backend() | ||
prefs = @load_preferences() | ||
return get(prefs, "backend", "native") | ||
end | ||
|
||
function set_backend(new_backend) | ||
@modify_preferences!() do prefs | ||
prefs["backend"] = new_backend | ||
end | ||
end | ||
``` | ||
|
||
Preferences are stored within the first `Project.toml` that represents an environment that contains the given UUID, even as a transitive dependency. | ||
If no project that contains the given UUID is found, the preference is recorded in the `Project.toml` file of the currently-active project. | ||
The initial state for preferences is an empty dictionary, 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. | ||
|
||
# API Reference | ||
|
||
!!! compat "Julia 1.6" | ||
Julia's `CompilePreferences` API requires at least Julia 1.6. | ||
|
||
```@docs | ||
CompilePreferences.load_preferences | ||
CompilePreferences.@load_preferences | ||
CompilePreferences.save_preferences! | ||
CompilePreferences.@save_preferences! | ||
CompilePreferences.modify_preferences! | ||
CompilePreferences.@modify_preferences! | ||
CompilePreferences.clear_preferences! | ||
CompilePreferences.@clear_preferences! | ||
``` |
Oops, something went wrong.