python-kacl
python-kacl copied to clipboard
Support config in pyproject.toml
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")
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.