AndrewVeee/nucleo-ai

Use of tomllib (and not toml)

Closed this issue ยท 4 comments

I hope I don't regret choosing toml - it's supposed to be a simpler config format, but it's not used much.

To be honest I hate toml, not the format itself, but the fact that tomllib only exists in python >= 3.11. And most distributions still use python 3.10 (including me :-) as it's the remcommended stable (and for stable diffusion) version.
You can maybe use the toml module, instead of tomllib? Not sure if it's ok with python >= 3.11

Originally posted by @AndrewVeee in #5 (comment)

This looks like the best option. I'll give it a try soon!

If you want to try, here is the modified config.py file I used personnally:

import toml

class Config:
  def __init__(self, app):
    self.app = app
    self.user_conf = self.load_toml('../data/config.toml')
    self.config = {}
    self.config.update(self.user_conf)

  def get(self, name, default=None, path=None):
    cfg = self.config
    if path:
      for part in path.split("."):
        if part in cfg:
          cfg = cfg[part]
        else:
          return default
    if name in cfg:
      return cfg[name]
    return default
  
  def load_toml(self, file):
    cfg = toml.load(file)
    return cfg

Thanks! I'll definitely give this a try next week and try to get it out. I think without tomllib as a dependency, the app will work on a lot more python versions.

Switched to toml from tomllib and pushed the code. Hope this helps future installs!