Normalize arguments loaded from pyproject.toml (#75)#85
Conversation
ssbarnea
left a comment
There was a problem hiding this comment.
Maybe I am missing something but my impression is that this could be done with a generic conversion from underline to dash instead of an arguably ugly chain for specific cases.
Am I missing something here, like other values that do not respect that rule? Even if I am, it would clearly make sense to create a map with replacements and loop of over it.
|
I agree that the repetitive try/except blocks are ugly. You are not missing anything -- there are no special cases where an option shouldn't be renamed. I haven't made any contributions to this project before so I chose to base my patch on the |
Instead of using the implementation of `from_ini()` as inspiration, simply loop over the items in the `[tool.doc8]` dictionary and replace hyphens in names with underscores. There is a special case for the `ignore-path-errors` argument because the elements of that list each need to be parsed. I removed the extra handling for the `extensions` argument which stripped whitespace from each element in the list. On reflection, I realized that the stripping was necessary for INI files due to the way the `ConfigParser` works and not because it's necessary to guard against extensions with whitespace.
|
I removed the mention of |
|
@ejd Can you please add a test? The reason why I did not merge this fix is because I do not have any confidence that it fixes anything and that we will not break it later. We just need a test for loading the pyproject.toml. |
stephenfin
left a comment
There was a problem hiding this comment.
LGTM. As an aside, I find it weird that we don't do "schema validation" of the parsed options (i.e. there are no options that shouldn't be there) but that's not strictly related to this
|
If anyone wants to add schema validation, we should produce an JSON Schema and use jsonschema-python project to validate it. I am already doing this on other projects but I am afraid that I do not have the time to do it here. |
|
Can you provide a link to one of those other projects? |
|
https://github.com/ansible/ansible-navigator validates its own config using schema and https://github.com/ansible/ansible-lint uses schemas to validate various files. |
This PR converts arguments loaded from a
pyproject.tomlfile into the internal representation used for all other argument sources. This conversion assumes the argument values inpyproject.tomltake advantage of TOML types instead of using strings alone. For example, whiledoc8.inimight haveAn equivalent
pyproject.tomlwould have the following: