-
Notifications
You must be signed in to change notification settings - Fork 122
Updates toml library #317
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
base: master
Are you sure you want to change the base?
Updates toml library #317
Conversation
.github/workflows/test.yml
Outdated
| path: downloaded_artifacts | ||
|
|
||
| - name: Clean up temporary artifacts | ||
| uses: geekyeggo/delete-artifact@v5 |
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.
not to be paranoid, but how do we know we can trust geekyeggo/delete-artifact ?
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.
See the
Depends on: #316
on the PR description. There is code here that is actually part of the PR above. Which is why i want to merge it faster.
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.
That PR also used geekyeggo - which looks fine - but in general we want to be security-conscious when using 3rd party tools / images.
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.
This was fixed in the main PR #316 -- has nothing to do with this PR
|
Also, please. I need this for another project, can this be released as soon as possible? 1.7.2 or 1.8.0? |
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.
Pull Request Overview
This PR updates the TOML library integration by using tomllib (with a fallback to tomli) and adds new tests to increase coverage for TOML configurations. Key changes include:
- Updating the TOML parser in configargparse to support newer libraries.
- Adding extensive tests for TOML parsing scenarios.
- Adjusting setup.py dependencies for TOML support.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/test_configargparse.py | Added tests for various TOML parsing cases, though duplicate test names were noted. |
| setup.py | Updated extras_require to include the correct dependency for TOML. |
| configargparse.py | Updated TOML parsing to use tomllib with fallback to tomli, with an outdated comment. |
Comments suppressed due to low confidence (2)
tests/test_configargparse.py:1824
- Duplicate test function name 'test_empty_section' found. Consider renaming one of them to clearly differentiate between the intended test scenarios.
def test_empty_section(self):
configargparse.py:523
- The comment referring to 'configparser' is outdated since the parser now uses tomllib (with a fallback to tomli). Please update the comment to reflect the current implementation for clarity.
# parse with configparser to allow multi-line values
|
Looks fine to me. @tristanlatr @tbooth @agyoungs any objections to this and doing another release? |
Thanks for the ping. I'll have time in a day or two to look at this unless someone beats me to it |
|
The switch to the new However, I'll note that this PR introduces a dependency on the Personally I find the I think if there is a decision to move to this style of tests it should be all or nothing, and not just introduced on-the-fly within this PR. Or else, these new tests could very easily be written without the need for pytest. |
|
Speaking as a pytest dev member -- well you know my bias.. I'm very pro-pytest. |
|
@kingbuzzman I appreciate @tbooth 's point, and looking at this again, I agree that we should avoid heterogeneous testing styles where possible. Would you be up for switching this to the same style as existing tests? |
tests/test_configargparse.py
Outdated
| def test_advanced(self): | ||
| parser = configargparse.TomlConfigParser(['tool.section']) | ||
| with open('config.toml', 'rb') as f: | ||
| assert parser.parse(f) == {'key1': "toml1", 'key2': [1, 2, 3]} |
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 suspect this test should be checking the following instead. And yes it’s not how it works right now for some reason, I suspect there is a regression compared to what the code was supposed to do initially, this because the tests were not merged at the same time as the extra config parser classes. The idea behind this is that anything that is not a string is casted to string because argparse expect only strings and will later re-convert il the string to float or whatever type.
This problem has been discovered in #314 and I don’t had the time to troubleshoot that behavior yet.
| assert parser.parse(f) == {'key1': "toml1", 'key2': [1, 2, 3]} | |
| assert parser.parse(f) == {'key1': "toml1", 'key2': ['1', '2', '3']} |
So adding tests is good but the code is kinda broken right now.
So what ide suggest is:
- first make the original tests pass,
- then switch the TOML parsing library, ensuring that no breaking changes are introduced.
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'm sure I fixed this somewhere in my monster PR...
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.
Yes, I did. See here: c1e3f16
Rather that the current behaviour where each individual parser is responsible for converting the config file contents to strings, I made a single function which is called by all the config file parsers. Note that at the request of @bw2 I later renamed _tweak_value() to _process_config_entry() but the logic is the same.
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.
While i disagree with the approach, I understand the issue.
For now, I'm going to set this to draft.
But this has nothing to do with my PR, I'm going to set this to draft and create a PR where I ONLY create tests for what we currently have now, then ANOTHER PR where i fix the recast issue, THEN we can merge this PR.
|
I'm looking to put my money where my mouth is and re-write the tests without using pytest myself. It's a useful exercise as in the process I'm uncovering some issues. Specifically, if I comment out line 1844 in That can't be right! |
|
Also, if I switch back to using the old |
Depends on:
tomliif its not there