eyeseast / python-frontmatter

Parse and manage posts with YAML (or other) frontmatter
http://python-frontmatter.rtfd.io
MIT License
333 stars 42 forks source link

Use tomli in TOML handler #92

Open eyeseast opened 2 years ago

eyeseast commented 2 years ago

Looks like this is the new standard: https://pypi.org/project/tomli/

Need to check if this has the same API as the original toml. It might be worth creating an additional TOML handler using tomli, so you can import each one separately.

eyeseast commented 2 years ago

As noted here, I should add an extra so you can do pip install python-frontmatter[toml] (or [tomli]) and get everything in one shot.

pwwang commented 2 years ago

I would recommend rtoml

See: https://github.com/pwwang/toml-bench

merwok commented 2 years ago

FYI Python is gaining tomllib in the 3.11 standard library, which is adapted from tomli

pwwang commented 2 years ago

FYI Python is gaining tomllib in the 3.11 standard library, which is adapted from tomli

tomli is also a good choice, not only because of the reason you mentioned, it's implemented in pure python. If we don't need .load() or .loads(), which is implemented in a different package (tomli_w), then I am not against tomli here.

eyeseast commented 2 years ago

With Python 3.11 now available this feels like a higher priority. Since tomllib is read-only, I need to think about how to include it. Some options, in no particular order:

  1. Use tomllib but make the TOMLHandler read-only by default. In that case, you could read TOML but would have to write in another format, unless you install another library (probably tomli_w).
  2. Add tomli_w as a dependency. That preserves current functionality, maybe extends it a bit, but adds a dependency.
  3. Require tomli_w to use TOMLHandler. Again, basically the same as now, but with a different optional dependency.
  4. Use tomlkit to get reading and writing and also preserve format.

I don't use TOML enough to have a strong opinion here. Would like to hear from people who use the current TOML support.

tusharsadhwani commented 12 months ago

My suggestion: Add tomli_w as a dependency, and tomli as a dependency for when Python version is < 3.11

Something like this:

install_requires = 
  tomli==1.2.3; python_version < 3.11
  tomli-w==1.2.3

And in your Python code:

import tomli_w
if sys.version_info() >= (3, 11):
    import tomllib as tomli
else:
    import tomli