Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upSet auto_envvar_prefix to STREAMLIT #477
Conversation
This comment has been minimized.
This comment has been minimized.
|
Awesome! I'm having trouble testing this, though. How do I set the The problem I'm running into is that |
This comment has been minimized.
This comment has been minimized.
|
I'm looking into this. |
Set auto_envvar_prefix to STREAMLIT to accept parameters from environment variables in addition to regular CLI arguments. This is a Click option that will automatically get values from env vars if available.
This comment has been minimized.
This comment has been minimized.
|
@tvst I've moved The format of the environment variables that Click generates is PREFIX_COMMAND_VARIABLE. So, for the
If you temporarily set
I noticed that you attempted to set With the prefix on run_main instead of the root main:
|
This comment has been minimized.
This comment has been minimized.
|
Another option is to leave This overlaps with the Another thing that might be useful is assigning an envvar to the
|
Override the environment variable names for the options dynamically
added by configurator_options to be STREAMLIT_CONFIG_{option}. So, for
--server.port, the corresponding envvar is STREAMLIT_CONFIG_SERVER_PORT
instead of STREAMLIT_RUN_SERVER_PORT.
Set the environment variable for the file_or_url argument on the run command to STREAMLIT_RUN_FILE_OR_URL. Click does not do automatic envvars for arguments. This makes it possible to specify the file or url to run using an environment variable.
This comment has been minimized.
This comment has been minimized.
|
I've pushed commits to override the envvar names for the config options and add an envvar for the
|
This comment has been minimized.
This comment has been minimized.
|
Awesome PR @kinghuang! Two questions (@tvst should be the decider):
$ export STREAMLIT_RUN_TARGET=sa/gui.py
$ streamlit run ${STREAMLIT_RUN_TARGET} |
|
Just tried this and it's really amazing! Can you also add this to
And while you're at it, do you mind fixing line 26? .. note::
When passing your script some custom arguments, **they must be passed after a
"--"** (double dash). Otherwise the arguments get interpreted as arguments to
Streamlit itself. |
| @@ -147,6 +147,7 @@ def configurator_options(func): | |||
| parsed_parameter["param"], | |||
| help=parsed_parameter["description"], | |||
| type=parsed_parameter["type"], | |||
| envvar='STREAMLIT_CONFIG_{}'.format(parsed_parameter["param"].upper()), | |||
This comment has been minimized.
This comment has been minimized.
tvst
Oct 24, 2019
Collaborator
Make the suffix use snake case too. We have a function called to_snake_case() in case_converters.py that should do the trick.
In which case this line will get really long and nasty, so you could pull this logic into the _convert_config_option_to_click_option function.
Even better if we could change line 145 to just
config_option = click.option(**parsed_parameter)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
kinghuang
Oct 24, 2019
Author
Contributor
I've moved the logic into _convert_config_option_to_click_option(). But, I'm not so sure about applying to_snake_case.
For an option like server.baseUrlPath, we have:
STREAMLIT_CONFIG_SERVER_BASE_URL_PATH (with snakecase)
STREAMLIT_CONFIG_SERVER_BASEURLPATH (without snakecase)
I think the without snakecase version matches the underlying config name better. With the snakecase version, I wouldn't know if it's supposed to match a config named server.base.url.path, server.baseUrl.path, serverBaseUrlPath, etc.
This comment has been minimized.
This comment has been minimized.
treuille
Oct 25, 2019
Collaborator
The plan is to have only a two-level hierarchy for config options, so there shouldn't be any ambiguity so I think STREAMLIT_CONFIG_SERVER_BASE_URL_PATH is better.
This comment has been minimized.
This comment has been minimized.
kinghuang
Oct 26, 2019
•
Author
Contributor
The non-snakecase version has already been merged. But, here's how some other projects do config to environment variable mappings, for comparison. Overall, I feel that converting camelCase to straight uppercase without snake-casing is the better choice because it matches more closely with other apps.
Click's Default Behaviour
Turning on automatic environment variables in Click converts option names to uppercase, without snake casing.
--server.baseUrlPath == {PREFIX}_SERVER_BASEURLPATH
Traefik
Traefik's configs have camelCase names, and are mapped to CLI options in lowercase. The corresponding environment variables are not snake-cased.
[accessLog] filePath == --accesslog.filepath == TRAEFIK_ACCESSLOG_FILEPATH
Kafka (using Confluent Platform images)
Kafka's configs are all lowercase, and tend to have each word separated by a period (as opposed to camelCasing or snake_casing). In the Confluent Platform image for Kafka, the corresponding environment variables are only uppercased.
auto.create.topics.enable == KAFKA_AUTO_CREATE_TOPICS_ENABLE
Grafana
Grafana's configs are snake cased, which are preserved in environment variables.
[server] http_port == GF_SERVER_HTTP_PORT
This comment has been minimized.
This comment has been minimized.
tvst
Oct 28, 2019
Collaborator
Ooops, I think I merged this too soon. No problem, we'll address it in another PR.
This comment has been minimized.
This comment has been minimized.
|
For @treuille's questions:
|
Move the logic for constructing an environment variable name out of configuration_options() to _convert_config_option_to_click_option(), where the other Click options are prepped.
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
Ok, I just changed it to |
This comment has been minimized.
This comment has been minimized.
|
Awesome. I couldn't quite squeeze in that change in between meetings, today. :D |
This comment has been minimized.
This comment has been minimized.
Ah. That's compelling. Still I feel like |
This comment has been minimized.
This comment has been minimized.
|
Btw, this is really exciting work, @kinghuang ! |
* develop: Use custom context manager for temporary file in cli.py (streamlit#489) Update pull_request_template.md Update pull_request_template.md Handle lack of trailing slash (streamlit#528) Set auto_envvar_prefix to STREAMLIT (streamlit#477) Strip slashes in path components (streamlit#523) Create doc_improvement.md ESlint: allow @ts-ignore (streamlit#499) Update Pipfile (streamlit#505) Release 0.49.0 (streamlit#509) Removing package json (streamlit#501) Feature/input number (streamlit#416) ESLint warnings are fatal in Circle (streamlit#492) Doc updates (streamlit#286)
This comment has been minimized.
This comment has been minimized.
dijitali
commented
Jan 15, 2020
|
Thanks for this PR @kinghuang , it's exactly what I'm after but I'm just a bit confused on the correct usage. The v0.50.1 release notes state:
But the docs state:
I've tried setting both |
This comment has been minimized.
This comment has been minimized.
|
@dijitali Ah, the docs are incorrect! The For the
This is also shown in the help text for the run command.
|
This comment has been minimized.
This comment has been minimized.
dijitali
commented
Jan 16, 2020
|
Perfect, many thanks. Wasn't aware the |
kinghuang commentedOct 20, 2019
Issue: #476
Description: Set auto_envvar_prefix to STREAMLIT to accept parameters from environment variables in addition to regular CLI arguments. This is a Click option that will automatically get values from env vars if available.
Contribution License Agreement
By submiting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.