# HG changeset patch # User Franz Glasner # Date 1619359740 -7200 # Node ID 2a2f5b86fe342cbfefcb6d1e9a06d249725c97d9 # Parent 063099b188cd5339b36091475dcec761fa2f2e86 Move some important public constants into the .constants sub-module diff -r 063099b188cd -r 2a2f5b86fe34 CHANGES.txt --- a/CHANGES.txt Sun Apr 25 14:05:16 2021 +0200 +++ b/CHANGES.txt Sun Apr 25 16:09:00 2021 +0200 @@ -13,6 +13,16 @@ -------------- .. changelog:: + :version: none + :released: not yet + + .. change:: + :tags: breaking, misc + + Moved some important public constants from :py:mod:`configmix` + into the :py:mod:`configmix.constants` module. + +.. changelog:: :version: 0.13 :released: 2021-04-21 diff -r 063099b188cd -r 2a2f5b86fe34 configmix/__init__.py --- 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("") -"""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): diff -r 063099b188cd -r 2a2f5b86fe34 configmix/constants.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configmix/constants.py Sun Apr 25 16:09:00 2021 +0200 @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# :- +# :Copyright: (c) 2015-2021, Franz Glasner. All rights reserved. +# :License: BSD-3-Clause. See LICENSE.txt for details. +# :- +"""Some important public contants + +""" + +from .compat import u + + +COMMENTS = [ + u("__comment"), + u("__doc"), +] +"""Prefixes for comment configuration keys that are to be handled as +comments + +""" + +DIR_PREFIX = u("") +"""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 + +""" diff -r 063099b188cd -r 2a2f5b86fe34 docs/apidoc.rst --- a/docs/apidoc.rst Sun Apr 25 14:05:16 2021 +0200 +++ b/docs/apidoc.rst Sun Apr 25 16:09:00 2021 +0200 @@ -30,6 +30,13 @@ :ignore-module-all: +Module :mod:`configmix.constants` +--------------------------------- + +.. automodule:: configmix.constants + :members: + + Module :mod:`configmix.ini` --------------------------- diff -r 063099b188cd -r 2a2f5b86fe34 docs/changes.rst --- a/docs/changes.rst Sun Apr 25 14:05:16 2021 +0200 +++ b/docs/changes.rst Sun Apr 25 16:09:00 2021 +0200 @@ -16,6 +16,17 @@ Breaking Changes ================ +none +---- + +- Move some important public constants from :py:mod:`configmix` into + the :py:mod:`configmix.constants` module. + + This is technically a breaking change while the author does not + believe that any of the current clients is affected by this + change. + + 0.9 ---