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

Toml file badly processed if it contains table aka. section in .ini files (name in brackets []) #55

Open
GeorgeFischhof opened this issue Aug 31, 2022 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@GeorgeFischhof
Copy link

Hi,

confz is very good tool, started to use right now, and found the following:

I created the following config

# config.py
import os
from pathlib import Path

from confz import ConfZ, ConfZFileSource
from pydantic import AnyUrl


my_script_path = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))


class APIConfig(ConfZ):
    login_page: AnyUrl = "https://abc.com/login"

    CONFIG_SOURCES = ConfZFileSource(
        folder=Path(my_script_path),
        file_from_env='TESTING_API_CONFIG',
        optional=True,  # because default is added above
    )


# config_some_environment.toml
[APIConfig]
login_page = "https://abc.com/login----from_file_just_to_see_the_diff_debug"

# environment variable added
TESTING_API_CONFIG=config_some_environment.toml

and the login_page value was the default one. Started to debug it and found, that Toml interpreter creates nested dicts if the file contains table [APIConfig]:

{"APIConfig": {"login_page": "https://abc.com/login----from_file_just_to_see_the_diff_debug"}}

and found a call in confz.py line 50:

cls.confz_instance = super().__call__(**config)

perhaps this is the point where the nested dict makes the issue. Unfortunately PyCharm did not show the source of super()...
so finished debugging here.

Perhaps this relates a little bit to issue #14

BR,
George

@silvanmelchior
Copy link
Collaborator

silvanmelchior commented Sep 2, 2022

Hi George, thanks for your request!

You are right, this way it would only work if your APIConfig has a field which would again be called "APIConfig", and there then a field "login_page". I would have said that this is the intended behaviour.
I'm not so familiar with toml parsing, what if you remove the [APIConfig] tag and only have "login_page" in your toml?

@silvanmelchior
Copy link
Collaborator

Closing this issue due to inactivity. Please re-open if you still consider the current behaviour a bug.

@GeorgeFischhof
Copy link
Author

Hi @silvanmelchior,

if I remove the
[APIConfig]

it works well, but in this case the file is not a toml file, just a text file with key value pairs.

The
APIConfig -> APIConfig -> login_page
syntax is quite weird, I think. At least it should be documented in the current version.

And solving this would solve the issue #14 too. One file could contain more config parts in different sections

BR,
George

@GeorgeFischhof
Copy link
Author

Closing this issue due to inactivity. Please re-open if you still consider the current behaviour a bug.

Yes, I think it should be reopened, but only repo owner / collaborator can reopen the issue

@silvanmelchior
Copy link
Collaborator

I flag it as a possible improvement for the documentation, so it's more obvious that the toml file acts as the root of the config class and possible sections wihtin the toml file refer to sub-configs. Please also see the test file "https://github.com/Zuehlke/ConfZ/blob/main/tests/assets/config.toml" for more options.

@silvanmelchior silvanmelchior added the documentation Improvements or additions to documentation label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants