-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
A better config system #366
Comments
I think we can consider use the same method I used in Comonicon's
function Pluto.run(host, port;kwargs...)
toml_config = read_toml(some_pluto_config_file)
# merge config file configs and configs specified
# by users using kwargs
config = merge_config(toml_config, kwargs)
# validate configs, see if there are anything incorrect
validate_config(config)
# actual run with all configs
Pluto.run(configs) # This is dispatched on Pluto.run(::Dict)
end
As for config file, I actually suggest to just use a TOML, since you can limit what your config file can do in a TOML (given all we want to set up are PATHs, execution options etc. rather than arbitrary Julia code) but not an arbitrary Julia script. And note Pkg ships with a TOML and it will be a stdlib in 1.6. |
I think that I just want a way for a Julia script (like the CLI or the binder launch script) to run Pluto with extra configuration options - and not much more. So support for .toml & ENV should not be part of Pluto itself - if people need those then they should be able to write a tiny script to support it. Maybe it's also a matter of taste - I prefer having only one option to do things, with more options only if necessary. I think it should be something like julia> Base.@kwdef mutable struct ServerConfiguration
port::Integer=1234
host::String="localhost"
url::Union{String,Nothing}=nothing
launch_browser::Bool=true
security_mode::Pluto.SecurityMode=Something(1, 2, true)
main_menu::Pluto.MainMenuMode=menu_default
end and you use it with Pluto.run(; session=ServerSession(), configuration=ServerConfiguration()) |
I think this also depends on much configurations are there gonna be: I'm personally OK with defining a Julia struct like the As for environment variables, I think it's just necessary to tweak the default behaviour: imagine that a server admin wants to set the default environment to be specific folder, while allowing different server config to run on the same machine (e.g on different port and ip address with different security mode) However, environment variables and config file can be set via the CLI indeed with a wrapper around
I think this will be more extensible than defining a run(;session=ServerSession(), TOML.parsefile("Pluto.toml")...) |
Thanks! It sounds like |
I really like the idea of Pluto's configuration being contained in structs. You mentioned poor readability, but with ServerConfiguration(
port=123,
launch_browser=false
) # other fields get the default value I do not like environment variables inside Pluto's code, but I do see the need for them in the startup code for Pluto. So, kind if like we have now, it should be isolated into one file (like you did in #367), and from that point on, Pluto's code only deals with configuration And there should also be the options to bypass ENV variables and set up I added a third struct in my latest commit: but I am not quite happy with the structure yet. I think that instead, |
Also I quite like the division of Pluto.jl to have as few features/options as possible, and PlutoUtils.jl to have everything that a sysadmin would ever ask for. Something like If possible, I would like the same with environment variables, but maybe that doesn't make sense |
I agree environment variables is probably not very useful in terms of REPL-based interface in Pluto as long as we make it more configurable in This makes more sense since only when one wants to use a CLI, will they need environment variables to setup some default behaviour. Regarding to name = "MyPlutoConfig"
show_banner="false"
[workspace]
distributed="true"
run_notebook_on_load="false"
[julia]
compile="all"
project="@."
sysimg="some path to a system image"
startup-file="no"
optimize=2 I think I'd expect this config file grows longer, and if we do it as When someone find that we need some more options, we can simply parse those extra options by adding a pass, since like On the other hand, if we do it using |
To summarize,
On the other hand, users need to write less code if we support the Pluto.run(;project="@.", compile="min", ...) instead of Pluto.run(;s=WorkspaceOptions(distributed=true), CompilerOptions(compile="all", ...)) tho, this is more a personal taste of interface, but I feel Update: |
Side note: what do you mean with the |
Great that you brought up |
So in that case, Pluto will have built in functionality that goes from a 'flat' structure of kwargs to the more structured combination of |
Yes, I think we can just handle all the environment variables in PlutoUtils side as a way to config the CLI. And for
directly passing the parsed dict to |
There is only one potential issue to handle all the environment variables in PlutoUtils, is that it prevents someone to change the Pluto instance configuration using environment variable at runtime, since Pluto won't read up |
True, let's just not support that then |
Okay nice! I can have a closer look at how Pkg works and have another go at making the |
I think this is resolved by #367 |
@Roger-luo
Right now we have some
ENV
variables with a custom function to get default values - this was quickly put together for some flags in the automated testing, but I'd like to have something better.First some use cases: (feel free to suggest more)
Some requirements to make this easy:
Ideas:
Pluto.run
ServerSession
will contain all of this. A config file is just a.jl
script that defines aServerSession
.The text was updated successfully, but these errors were encountered: