changeset 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 063099b188cd
children d8361dd70d2d
files CHANGES.txt configmix/__init__.py configmix/constants.py docs/apidoc.rst docs/changes.rst
diffstat 5 files changed, 73 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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):
--- /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("<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
+
+"""
--- 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`
 ---------------------------
 
--- 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
 ---