traitlets icon indicating copy to clipboard operation
traitlets copied to clipboard

Add TOML support

Open mexanick opened this issue 4 years ago • 6 comments

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

Fixes #648

mexanick avatar Mar 15 '21 11:03 mexanick

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

rmorshea avatar Mar 18 '21 18:03 rmorshea

can it be related to https://github.com/jupyter/notebook/pull/5986?

mexanick avatar Mar 26 '21 11:03 mexanick

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.

ivanov avatar Apr 15 '21 20:04 ivanov

@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.

willingc avatar May 08 '21 20:05 willingc

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)

mexanick avatar May 17 '21 16:05 mexanick

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.

rmorshea avatar May 17 '21 19:05 rmorshea