-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document "exported" preferences #48
base: master
Are you sure you want to change the base?
Conversation
This gives examples showing how to use "exported" (I prefer "package-wide") preferences. It also reorganizes the README around the major decision-points of project- vs package-specific, and runtime vs compiletime.
Codecov Report
@@ Coverage Diff @@
## master #48 +/- ##
=======================================
Coverage 85.93% 85.93%
=======================================
Files 2 2
Lines 128 128
=======================================
Hits 110 110
Misses 18 18 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
If you call `load_preference` (or its macro variant `@load_preference`) from "top-level" in the package, | ||
this is a compile-time preference. Otherwise (e.g., if it is "buried" inside a function, and that | ||
function doesn't get executed at top-level), it is a run-time preference. See examples in the first API section below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't exactly true; a preference can still be loaded from within a function and used at compile time if that function is invoked during precompilation time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and that function doesn't get executed at top-level"? But obviously it's not clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah. I'm honestly not sure it matters much to draw a distinction between compile-time and non-compile-time preferences; perhaps we should just have a note that says "if you use a preference at compile time, you will have to restart Julia before the changes will be seen" and leave it at that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, perhaps we could instead have set_preferences()
spit out a @warn()
when it notices a compile-time preference has been changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea!
We still might need to discuss this issue somewhere, otherwise people might be mystified about why it sometimes requires a restart and why it sometimes doesn't. (Might feel like a bug when it doesn't warn.)
@@ -80,6 +94,41 @@ end | |||
end # module UsesPreferences | |||
``` | |||
|
|||
With the macros, all preferences are project-specific. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be better to figure out how to pass kwargs to a macro, so we can have @set_preferences!("foo" => "bar"; export=true)
, or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would make sense. A related issue: currently you have to read the docstring for set_preferences!
in order to understand the force
comment in the docstring for @set_preferences!
. What do you want to do about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't understand active_project_only
well enough myself to even try describing it in the README (I could read the code, but...)
Hmm, actually "package-wide" preferences don't work. Create a dummy package,
name = "WithPreferences"
uuid = "dcf8c38c-589d-4550-bcab-b56e5c9171f3"
authors = ["Tim Holy <[email protected]>"]
version = "0.1.0"
[deps]
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
[preferences.WithPreferences]
awesome_languages = ["Julia"]
module WithPreferences
using Preferences
const awesome_languages = String[]
function loadprefs()
prefs = @load_preference("awesome_languages")
if prefs !== nothing
append!(awesome_languages, prefs)
end
end
end Works if you're using the package's Project.toml as your environment:
Does not if you use your default environment:
I'm assuming it's supposed to work in the second case, but if not then I'd love to know your thoughts on whether it would be useful & worthwhile to support "package-wide" preferences and if so how to design it. |
Also, with the current design, won't package-specific preferences need to be reconfigured each time you update to a new version? I see why that might be necessary, but it also seems likely to be frustrating for packages with complex configuration. Or even just "why is it back to using the xyz backend, I thought I just configured that!" |
This gives examples showing how to use "exported"
(I prefer "package-wide") preferences. It also reorganizes
the README around the major decision-points of
project- vs package-specific, and runtime vs compiletime.