-
Notifications
You must be signed in to change notification settings - Fork 13
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
Allow configuration via environment variables #57
base: main
Are you sure you want to change the base?
Conversation
@ludovicm67 Can you please have a look at this and try it out and let me know what you think? I think it nicely addresses the problem we talked about last week. For testing, in oder to get the environment variables for one of the preconfigured Qleverfiles, you can do the following:
In your shell script, you can then copy&paste these environment variables (and modify them as you see fit) and then simply call whatever |
@hannahbast I will give it a try! This is similar than what I've done here in a shell script: https://github.com/zazukoians/qlever-tests/blob/76068584b86a620ab1fdde4a309d81bdda733e36/docker/common/generate-qleverfile.sh It's great that we are fully on the same page for the variable names 👍 |
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 gave it a try, and it seems that qlever
is able to get its configuration from the environment variables successfully 👍
Thanks a lot for this very useful change!
subparser.add_argument( | ||
"--get-qleverfile", type=str, | ||
choices=self.qleverfile_names, | ||
help="Get one the many pre-configured Qleverfiles") | ||
subparser.add_argument( | ||
"--show-qleverfile", action="store_true", | ||
default=False, | ||
help="Show the configuration from the Qleverfile " | ||
"(if it exists)") | ||
subparser.add_argument( | ||
"--show-envvars", action="store_true", default=False, | ||
help="Show all existing environment variables of the form " | ||
"QLEVER_SECTION_VARIABLE") | ||
subparser.add_argument( | ||
"--varname-width", type=int, default=25, | ||
help="Width for variable names in the output") | ||
subparser.add_argument( | ||
"--set-envvars-from-qleverfile", action="store_true", | ||
default=False, | ||
help="Set the environment variables that correspond to the " | ||
"Qleverfile configuration (for copying and pasting)") | ||
subparser.add_argument( | ||
"--unset-envvars", action="store_true", default=False, | ||
help="Unset all environment variables of the form " | ||
"QLEVER_SECTION_VARIABLE (for copying and pasting)") |
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.
For me many of these feel more natural as a subcommand than as a parameter
The
qlever
script can now get its config either from aQleverfile
(just like before) or from environment variables (this is new). The environment variables have names that are fully analogous to the variable names in theQleverfile
. For example, the variablePORT
in sectionserver
of theQleverfile
corresponds to the environment variableQLEVER_SERVER_PORT
.The
qlever
script now checks if either aQleverfile
exists or if environment variables of the formQLEVER_SECTION_VARIABLE
exist. If exactly one of these exists, it will automatically parse the configuration from there. If both exist, it will complain (it would be easy to merge both, by letting one override the other, but I don't see a use case for that, but the potential for unexpected behavior instead, since a user might not be aware of which environment variables are set).There is now also a new command
qlever config
with various convenience options, in particular:--show-qleverfile
,--show-envvars
,--set-envvars-from-qleverfile
, and--unset-envvars
. Seeqlever config --help
for a description of what exactly they do.