Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added support of pyproject.toml file #41

Merged
merged 4 commits into from
Oct 20, 2024
Merged

Conversation

DolajoCZ
Copy link
Contributor

I've added support of pyproject.toml file for ability to configure xenon for CI/CD from this one configuration file common for other tools.

@rubik
Copy link
Owner

rubik commented Jul 20, 2021

@DolajoCZ Thanks for the contribution! Overall it looks very good, but I would make a change: the config values from pyproject.toml should not take precedence over the command line ones. It could be like this:

  1. the configuration starts with its default values
  2. the pyproject.toml file is read and any values from there are set
  3. the values from the command line are set, so that they override the previous ones

It would be great to have a test case with config values set in different places.

@DolajoCZ
Copy link
Contributor Author

@rubik. Thank you for response. I will change priorities as you suggesting.

Regarding last line It would be great to have a test case with config values set in different places. You mean add unittest where some values will be set from command line, some from pyproject.toml and some will be default?

@rubik
Copy link
Owner

rubik commented Jul 21, 2021

@DolajoCZ Yes, exactly. A test case with values set from different places (even the same values) to verify the priority.

@DolajoCZ
Copy link
Contributor Author

@rubik Ok I can do it but I need to specify required behaviour in case when I have parameter x with default value a, from cmd is set also to a and in pyproject.toml is set to b. Correct result in this case is a or b?

@DolajoCZ
Copy link
Contributor Author

DolajoCZ commented Aug 7, 2021

@rubik I made changes as you required. Please let me know, if it is according your expectations. Thanks

continue

# Set only in pyproject.toml
setattr(args, arg_name, arg_value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of cloning the args object and checking if a name is present, it's better to simply:

  1. set all the values from pyproject
  2. set all the values from the command line

That way no cloning is needed, no checking is needed and the priority of the sources is taken care of automatically, since CLI options will override those from pyproject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I understand it correctly. In second step when I need to get values set from cmd I also get arguments which were not passed by user but they have set default value.

Maybe if you can share piece of code to prove me where is my understanding incorrect. Then I will make necessary changes. Thank you

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DolajoCZ We can:

  1. start with the default values
  2. override them with pyproject values (if any)
  3. override them with command line values (if any)

Then the priority is respected naturally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your proposed approach, but i dont understand how you want to get only arguments and values which were passed by user in cmd. If I use args = parser.parse_args() I get arguments and values including arguments which were not set by user. Maybe I don't know appropriate command to get from parser only realy passed values. Can you give me advice please?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DolajoCZ You can remove the defaults from the ArgumentParser object and put them in a dictionary. Then if a user does not supply an option it will be None in the result of parser.parse_args(). So you just skip the ones with value None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubik thank you for advice. This was something which does not come to my mind. I made necessary modification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubik is current code ok according your expectations or should I modify it? One thing whitch I found when I looked at other python packages witch support pyproject.toml is that in case when parameter can be list of values (exclude for example), then even if you want use single value you shoud use ["value"] instead of "value". Current implementation allow use "value".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubik any comment?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any progress on this?

@rubik
Copy link
Owner

rubik commented Aug 8, 2021

@DolajoCZ Looking great! I added some comments.

@rubik rubik merged commit aff681b into rubik:master Oct 20, 2024
@rubik
Copy link
Owner

rubik commented Oct 20, 2024

@DolajoCZ Apologies for the delay, thank you so much for your contribution. I was unable to dedicate time to my open-source projects.

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

Successfully merging this pull request may close these issues.

3 participants