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

Ability to change override order #663

Open
rusmux opened this issue Jan 30, 2025 · 3 comments
Open

Ability to change override order #663

rusmux opened this issue Jan 30, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@rusmux
Copy link

rusmux commented Jan 30, 2025

🚀 Feature request

Add the ability to change the override order. In the documentation it's said that CLI arguments (including config files) take precedence over env variables. It would be great to be able to configure this order.

Motivation

I think it's a valid approach to set one config file and update it with env variables. This can be very useful in containerised deployments, when services can be dynamically configured with env variables. For example, this is my entry point in the Docker image:

python -m main --config config.yaml

And I would like to update its config before start by setting the environment variable:

APP__SOME_VALUE: new
@rusmux rusmux added the enhancement New feature or request label Jan 30, 2025
@rusmux rusmux changed the title Change override order Ability to change override order Jan 30, 2025
@mauvilsa
Copy link
Member

At least for the example above, you can already get the behavior you want.

  • Copy the config to a specific location, e.g. /app/config.yaml
  • Configure the parser with default_config_files=["/app/config.yaml"]
  • Run main without command line arguments python -m main
  • With this all environment variables would override what is in the config.

@rusmux
Copy link
Author

rusmux commented Jan 30, 2025

Thank you, that works, but I guess, it's still would be nice to have this feature, because users may want to change their config file location without updating the code. Or if they cannot set default_config_files because it's not their code, but a library providing the CLI

@mauvilsa
Copy link
Member

mauvilsa commented Feb 2, 2025

I guess the proposal here is only to be able to move 5. Command line arguments in order left to right before the env vars parsing. Not changing the override order to any permutation.

In a fixed environment like a container, using a fixed config location with default_config_files would be the recommended approach. If default_config_files not yet set in the code, then changing the code would be preferable before using it in a container. On the other hand, in interactive environments the command line is what gets written last and executed by the user. Giving precedence to environment variables doesn't seem logical to me.

The strongest argument for this feature would be a CLI in a library not controlled by someone. But still I am not convinced. Requesting a change in the library would be the optimal solution. And also I think there would be workarounds that wouldn't require modifying the library, which would be preferable than adding complexity to jsonargparse.

For now I wouldn't plan to add this feature. But rather keep this issue open for other people to show interest.

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

No branches or pull requests

2 participants