Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hannahbast
Copy link
Member

The qlever script can now get its config either from a Qleverfile (just like before) or from environment variables (this is new). The environment variables have names that are fully analogous to the variable names in the Qleverfile. For example, the variable PORT in section server of the Qleverfile corresponds to the environment variable QLEVER_SERVER_PORT.

The qlever script now checks if either a Qleverfile exists or if environment variables of the form QLEVER_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. See qlever config --help for a description of what exactly they do.

@hannahbast
Copy link
Member Author

hannahbast commented Aug 14, 2024

@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:

qlever config --get-qleverfile olympics
qlever config --set-envvars-from-qleverfile

In your shell script, you can then copy&paste these environment variables (and modify them as you see fit) and then simply call whatever qlever commands you want to run. That is maximally simple, and you avoid duplicating any of the work that should really be (and with this PR is) done by the script.

@ludovicm67
Copy link
Contributor

@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 👍

Copy link
Contributor

@ludovicm67 ludovicm67 left a 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!

Comment on lines +35 to +59
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)")
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants