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
Use stdlib toml provider on Python >= 3.11. Switch to tomli otherwise #20
Conversation
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.
Generally in favour of this, but not really okay with the parser-neutral methods having toml specific stuff in them...
@cjw296 It turned out to be much cleaner and simpler modifying |
configurator/config.py
Outdated
stream = StringIO(text) | ||
return cls.from_stream(stream, parser) | ||
if isinstance(text, bytes): | ||
text = text.decode(encoding) |
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.
When is this bytes
?
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.
Are you looking at an older commit? There should be no changes in config.py
any longer.
The conversion from bytes to text is there in master currently, since 2019 acc21db
@@ -33,5 +25,5 @@ def __missing__(self, extension): | |||
except KeyError: | |||
raise ParseError('No parser found for {!r}'.format(extension)) | |||
else: | |||
module = __import__(module_name) | |||
module = import_module(module_name) |
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.
nice!
When are you looking for a release? ASAP? |
Wherever it’s ready. This is for an app, so I don’t mind to lock my requirements txt directly to the git hash in the meantime. |
I would like to use configurator with a TOML file in Python 3.11, but lose that 3rd-party
toml
dependency, since Python 3.11+ hastomllib
.The current provider is not compliant with the TOML spec and does not roundtrip:
For Python < 3.11, may I recommend to move to
tomli
, which is what stdlibtomllib
was based upon. Many existing projects usetomli
(e.g.pip
,build
,pytest
,mypy
,black
,flit
,coverage
,setuptools-scm
,cibuildwheel
). According to PEP 680, the projectuiri/toml
was rejected because it's not actively maintained, does not support TOML 1.0.0 and has a number of known bugs.Unfortunately the abstractions in configurator made it a little complicated to integrate
tomli
/tomllib
, because the TOML specification requires the input to be UTF-8.tomli
implements this requirement by forcing the user to use binary mode "b" when reading the file, then does the decoding. I've tried my best to handle TOML files in a correct way, without drastic refactoring.