simplistix / configurator

A Python library for handling configuration files.
https://configurator.readthedocs.io
MIT License
40 stars 6 forks source link

Use stdlib toml provider on Python >= 3.11. Switch to tomli otherwise #20

Closed wimglenn closed 1 year ago

wimglenn commented 1 year ago

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+ has tomllib.

The current provider is not compliant with the TOML spec and does not roundtrip:

>>> import toml
>>> d = {'k': None}
>>> toml.loads(toml.dumps(d)) == d
False

For Python < 3.11, may I recommend to move to tomli, which is what stdlib tomllib was based upon. Many existing projects use tomli (e.g. pip, build, pytest, mypy, black, flit, coverage, setuptools-scm, cibuildwheel). According to PEP 680, the project uiri/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.

wimglenn commented 1 year ago

@cjw296 It turned out to be much cleaner and simpler modifying parsers.py to use importlib. And it still works on 3.6 this way.

cjw296 commented 1 year ago

When are you looking for a release? ASAP?

wimglenn commented 1 year ago

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.

cjw296 commented 1 year ago

https://pypi.org/project/configurator/3.2.0/ for ya!