Skip to content

Commit

Permalink
Make configuration files prefix configurable for any TOML filename (n…
Browse files Browse the repository at this point in the history
…ot only pyproject.toml)
  • Loading branch information
castalheiro committed Mar 6, 2022
1 parent 54219e1 commit ae5c426
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doit/doit_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ def __init__(self, application_name):
self.config = defaultdict(dict)
self._application_name = application_name

def loads(self, config_filenames):
def loads(self, config_filenames, toml_config_files_prefix):
for config_filename in config_filenames:
if str(config_filename).lower().endswith('.toml'):
prefix = f"tool.{self._application_name}" if config_filename == 'pyproject.toml' else ''
if toml_config_files_prefix:
prefix = toml_config_files_prefix
elif config_filename == 'pyproject.toml':
prefix = f'tool.{self._application_name}'
else:
prefix = ''
toml_config = self.load_config_toml(config_filename, prefix)
for section in toml_config:
self.config[section].update(toml_config[section].items())
Expand Down Expand Up @@ -161,7 +166,8 @@ class DoitMain(object):
def __init__(self, task_loader=None,
config_filenames=('pyproject.toml', 'doit.cfg'),
extra_config=None,
application_name='doit'):
application_name='doit',
toml_config_files_prefix=None):
"""
:param extra_config: dict of extra argument values (by argument name)
This is parameter is only used by explicit API call.
Expand All @@ -182,7 +188,7 @@ def __init__(self, task_loader=None,

# combine config option from INI/TOML files and API
config_in = DoitConfig(application_name)
config_in.loads(config_filenames)
config_in.loads(config_filenames, toml_config_files_prefix=toml_config_files_prefix)
for section, vals in config_in.as_dict().items():
self.config[section].update(vals)

Expand Down

0 comments on commit ae5c426

Please sign in to comment.