-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Discussion] First-class config overrides via pyproject.toml? #87
Comments
First off, thanks for all the kind words and for using Cyclopts! Lets see if I can try and answer some of your questions.
If i'm to understand this correctly, it's to determine if the user is explicitly overriding the (possible) value provided in their
Admittedly, it is getting a bit unwieldy, but at least it's consistent :P. Note: if
Correct, at that stage Cyclopts has "done it's job." It parsed, converted, and validated CLI arguments, and transformed them into a callable function with arguments. We're then just further modifying those bound arguments.
I think as we get to this stage, the solution ends up being some sort of integration with pydantic/cattrs, and let those libraries perform the heavy lifting. I think you brought up a bunch of good questions, that unfortunately I don't have any immediate good solutions for. I'm all for brainstorming up possible solutions. If we think we can achieve a lot of what you want with pydantic integration, we can combine discussions with #86. |
This feature is implemented in the newly released v2.7.0. See the example in the docs and the API docs for usage. |
Hi! Thanks for building this awesome tool. I'm loving using it so far, and excited to show our users how awesome our CLIs can be. I did want to get your thoughts on how you might envision cyclopts evolving. There are some areas the story seems a little unclear with how configs loaded from pyproject.toml interact with those passed in. These aren't feature requests, but it would be good to get your reaction to these, and the general idea of first-class support for pyproject.toml:
Meta App Parameter Overrides
While there is a nice example showing how to override values for commands, I was playing around with this a bit and didn't see an immediately obvious way to infer defaults for parameters passed to the meta app. Take the following example, using verbose and quiet logging flags as an example:
[edit: in case it's not clear why I felt like I have to use
None
as a default, we otherwise couldn't tell the difference between a passed False config and the method default value of False]It is entirely possible I am way off the prescribed path here, so if there is an easier way to do this, please let me know. If not, it should be hopefully a little clear how using meta app params ends up feeling a little complex and also locks you out of documenting default values via type hints.
Config Validation
Configs loaded via pyproject.toml seem to skip the standard validation for CLI parameters. E.g. I could have updated the defaults via pyprject to some invalid combination, and this would not be caught by e.g.
validators.LimitedChoice()
. You can test out the example above, by adding a section to your project.yaml with bothverbose
andquiet
config set to true.There's probably a number of ways to work around this, but I think you'd have to load in the pyproject.toml early to get these values set in advance of the current validator logic. Perhaps loading pyproject.toml on init and attaching default_config dict to the App class would be one way to go about this? There are probably some considerations for not accidentally changing the defaults as they show in the CLI help text.
Schema Validation
It would be really awesome to be able to generate schema validation json for any commands. By this, I mean some compatibility functionality to generate a schema.json file from the command definitions themselves. These schema definitions can be used by IDEs etc to provide inspection capability to users who are adding a section to configure a published tool. An example of ruff's schema.json is https://github.com/astral-sh/ruff/blob/main/ruff.schema.json.
Having a defined schema for pyproject.toml input would also allow auto-coercion for any types from pyproject.toml, so you wouldn't have to manually validate each config.
Thanks again for sharing this library, it really is great, and I'd love to hear more about your thoughts on this problem space.
The text was updated successfully, but these errors were encountered: