Open Roger-luo opened 3 years ago
The first step for this is to print Preferences.jl
in as an external stdlib, just like Pkg
or Tar
.
Why? That doesn't seem necessary. There is a TOML parser in base already.
I actually tried to implement this myself, I don't see the need of using Preferences.jl inside Base? or I could be wrong, I think we need a list of configurations that should go into the julia preference field first (I'll init a list of them here I found later). For whoever sees an issue related to perference or could be configured, maybe link to this issue
And the other problem is should we special case the julia
since I don't think julia
has a UUID as a package right? or it has? I'm not sure what does this do: https://github.com/JuliaRegistries/General/blob/master/J/julia/Package.toml
or should this UUID be recognized as the Julia UUID?
or should this UUID be recognized as the Julia UUID?
Yes, the UUID of Julia itself is 1222c4b2-2114-5bfd-aeef-88e4692bbb3e
. We use that all over the place in Pkg.
There is a TOML parser in base already.
I guess if we don't want to support writing preferences, and we don't care about marking .ji
files to contain their list of compile-time preferences, then the only thing we really need is:
function load_julia_preferences()
# Re-use definition in `base/loading.jl` so as to not repeat code.
d = Base.get_preferences(Base.UUID("1222c4b2-2114-5bfd-aeef-88e4692bbb3e"))
# Drop any nested `__clear__` keys:
function drop_clears(data::Dict)
delete!(data, "__clear__")
for (k, v) in data
if isa(v, Dict)
drop_clears(v)
end
end
return data
end
drop_clears(x) = x
return drop_clears(d)
end
# Initialize JULIA_PREFS with a value so it can be used at compile time
const JULIA_PREFS = Ref{Dict}(load_julia_preferences())
function __init__()
# Re-initialize JULIA_PREFS at `__init__()` time, so that users can make changes to things that are not compile-time sensitive
JULIA_PREFS[] = load_julia_preferences()
end
And we tell users "if you want to modify the preferences, you either edit them by hand, or you use Preferences.jl
from an already-running Julia instance.
I think now with the preference system, it would be nice to configure julia itself withit per environment, e.g
-J<path to system image>
per project environmentcompile=min
or-O1
or other compiler flags for certain project while developingnot all of the above is achievable/convenient by messing up system environment variables, from user experience if we support the new configure system one can:
.julia
which is seperate with.bashrc
/.zshrc
etc. this will make it easier to migrate the same preference to cluster etc.my proposed implementation is to support a special field like following
for
Project.toml
for
LocalPreference.toml
edit: I realize not all the options can be configured easily using the preference system since it seems to require loading stdlib TOML.jl first, which means things implemented in C won't be able to configured afterwards, but still would be nice to be able to configure things within REPL itself (even by restart REPL to activate the new configuration)