Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/__init__.py @ 303:2a2f5b86fe34
Move some important public constants into the .constants sub-module
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 25 Apr 2021 16:09:00 +0200 |
| parents | 5648e4611383 |
| children | ce7aea9eac4a |
line wrap: on
line diff
--- a/configmix/__init__.py Sun Apr 25 14:05:16 2021 +0200 +++ b/configmix/__init__.py Sun Apr 25 16:09:00 2021 +0200 @@ -31,30 +31,9 @@ import os import re -from .compat import u, u2fs +from .compat import u2fs from .config import Configuration - - -COMMENTS = [ - u("__comment"), - u("__doc"), -] -"""Prefixes for comment configuration keys that are to be handled as -comments - -""" - -DIR_PREFIX = u("<dir>") -"""Prefix for configuration values to read other configuration files from -given directory - -""" - -DEL_VALUE = u("{{::DEL::}}") -"""Value for configuration items to signal that the corresponding -key-value is to be deleted when configurations are merged - -""" +from . import constants def load(*files, **kwargs): @@ -90,7 +69,7 @@ else: ex = merge(None, Configuration(defaults)) for f in files: - if f.startswith(DIR_PREFIX): + if f.startswith(constants.DIR_PREFIX): for f2 in _get_configuration_files_from_dir(f[5:]): nx = _load_cfg_from_file(f2, ignore_unknown=True, strict=strict) if nx is not None: @@ -117,7 +96,7 @@ else: ex = safe_merge(None, Configuration(defaults)) for f in files: - if f.startswith(DIR_PREFIX): + if f.startswith(constants.DIR_PREFIX): for f2 in _get_configuration_files_from_dir(f[5:]): nx = _load_cfg_from_file(f2, ignore_unknown=True, strict=strict) if nx is not None: @@ -429,7 +408,7 @@ The configuration in `default` will be changed **inplace** when filtering out comments (which is the default). - If a value in `user` is equal to :data:`.DEL_VALUE` + If a value in `user` is equal to :data:`.constants.DEL_VALUE` (``{{::DEL::}}``) the corresponding key will be deleted from the merged output. @@ -448,7 +427,7 @@ if filter_comments and _is_comment(k): continue if k in user: - if user[k] == DEL_VALUE: + if user[k] == constants.DEL_VALUE: # do not copy del user[k] else: @@ -468,7 +447,7 @@ if filter_comments and _is_comment(k): continue if k in user: - if user[k] == DEL_VALUE: + if user[k] == constants.DEL_VALUE: # do not copy del user[k] else: @@ -501,7 +480,7 @@ if filter_comments and _is_comment(k): continue if k in user: - if user[k] == DEL_VALUE: + if user[k] == constants.DEL_VALUE: # do not copy del user[k] else: @@ -521,7 +500,7 @@ if filter_comments and _is_comment(k): continue if k in user: - if user[k] == DEL_VALUE: + if user[k] == constants.DEL_VALUE: # do not copy del user[k] else: @@ -535,7 +514,7 @@ """Recursively filter comments keys in the dict `d`. Comment keys are keys that start with any of the items in - :data:`.COMMENTS`. + :data:`.constants.COMMENTS`. """ if not isinstance(d, dict): @@ -550,7 +529,7 @@ def _is_comment(k): - for i in COMMENTS: + for i in constants.COMMENTS: try: if k.startswith(i): return True @@ -563,14 +542,14 @@ def _filter_deletions(d): """Recursively filter deletions in the dict `d`. - Deletions have values that equal :data:`.DEL_VALUE`. + Deletions have values that equal :data:`.constants.DEL_VALUE`. """ if not isinstance(d, dict): return # use a copy of the items because we change `d` while iterating for k, v in list(d.items()): - if v == DEL_VALUE: + if v == constants.DEL_VALUE: del d[k] else: if isinstance(d[k], dict):
