Skip to content
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

Add TOML support #649

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

mexanick
Copy link

  • implement class TOMLFileConfigLoader
  • implement corresponding test case
  • add toml to requires list in setup.py

Fixes #648

- implement class TOMLFileConfigLoader
- implement corresponding test case
- add toml to requires list in setup.py
@rmorshea
Copy link
Contributor

Looks like the failed tests are unrelated to your changes. There's another PR with just doc enhancements that fails too.

@mexanick
Copy link
Author

can it be related to jupyter/notebook#5986?

@ivanov
Copy link
Member

ivanov commented Apr 15, 2021

It's great to see an addition of a format for traitlets, but I think it would make more sense to not make it a hard dependency. TOMLFileConfigLoader could wrap the currently top-level "import toml" in a try-except to not force the installation of toml for anyone who won't be using that feature, but giving a helpful error message for those wanting to use it to install toml.

@willingc willingc closed this May 8, 2021
@willingc willingc reopened this May 8, 2021
@willingc
Copy link
Member

willingc commented May 8, 2021

@rmorshea @ivanov I've closed/reopened this PR to trigger build on GH-Actions. Tests are green now on GH.

Probably the next step would be to determine offer @mexanick some guidance to avoid the hard dependency.

@mexanick
Copy link
Author

mexanick commented May 17, 2021

I have added the optional import of toml. The only thing which is suboptimal now is the testing of optional dependency (it is a bit ugly). I'd appreciate if someone has a better idea of testing implementation (or suggestion on optional dependcy incorporation)

@rmorshea
Copy link
Contributor

rmorshea commented May 17, 2021

Normally in these situations, I try to isolate this sort of "environment dependent code" in its own module so you don't have to do any try/except handling. Then, when the user tries to import it, if they haven't installed toml, they get an import error complaining that import toml failed. Thus, if no-one else has objections, my suggestions would be to add a new traitlets.config.toml_loader module containing the TOMLFileConfigLoader. This would set a precedent for future modules of the form {format}_loader. For example, if one wanted a YAML config loader, you'd create an isolated yaml_loader module since that would require the user to have yaml installed.

@@ -9,6 +9,11 @@
import re
import sys
import json
try:
import toml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should likely now prefer py3.11+ stdlib's tomllib and fall back to tomli

@@ -108,7 +108,8 @@
]

extras_require = setuptools_args['extras_require'] = {
'test': ['pytest'],
'test': ['pytest', 'toml'],
'with-toml': ['toml'],
Copy link
Contributor

@bollwyvl bollwyvl Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would probably just add tomli ; python_version < 3.11 to install_requires instead

return toml.load(f)

def _convert_to_config(self, dictionary):
if 'version' in dictionary:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't recall having seen version on any of the other sources, and don't see why we'd want to add that constraint here unless it was added to all of them, which would be a major version bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add toml support
5 participants