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

Support config in pyproject.toml #24

Open
ItsDrike opened this issue Dec 30, 2022 · 1 comment
Open

Support config in pyproject.toml #24

ItsDrike opened this issue Dec 30, 2022 · 1 comment

Comments

@ItsDrike
Copy link

The pyproject.toml is supported by most linters/formatters/type checkers and other python utilities to be used as the configuration file. Would you consider adding support for it here too, instead of, or as an alternative to the current standalone config file?

Note that python <3.11 doesn't have any stdlib TOML parsing library, a commonly used one is tomli, which you can use as an optional dependency (extras), making support for pyproject.toml entirely optional and if people don't need it, but still providing it if it's installed, as it's pretty much the standard configuration place for python tools.

To do this, people can install the dependency like: pip install python-kacl[tomli] (you'll need to specify tomli as one of extras to the library in setup.py). Then, in the file where you're handling configuration file parsing, you can do something like:

from pathlib import Path
try:
    import tomli
except ImportError:
    tomli = None


def get_project_config():
    primary_cfg_file = Path(".kacl.yml")
    if primary_cfg_file.exists():
        return parse_yml_config(primary_cfg_file)
    
    secondary_cfg_file = Path("pyproject.toml")
    if secondary_cfg_file.exists():
        if tomli is not None:
            return parse_toml_config(secondary_cfg_file)
        raise NoConfigFound(".kacl.yml configuration file is missing, and tomli isn't installed so pyproject.toml is ignored")
        
    raise NoConfigFound(".kacl.yml nor pyproject.toml was found, project config missing")
@mschmieder
Copy link
Owner

Hi,
I either way planned to rework the system to some degree, as the CI does not really work well anymore. I will have a look at your proposal but it sounds reasonable.

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

No branches or pull requests

2 participants