diff --git a/candv/utils.py b/candv/_utils.py similarity index 100% rename from candv/utils.py rename to candv/_utils.py diff --git a/candv/core.py b/candv/core.py index 776e12c..a30749b 100644 --- a/candv/core.py +++ b/candv/core.py @@ -12,7 +12,7 @@ from .exceptions import CandvInvalidGroupMemberError from .exceptions import CandvMissingConstantError -from .utils import export +from ._utils import export UNBOUND_CONSTANT_CONTAINER_NAME = "__UNBOUND__" @@ -102,10 +102,13 @@ def full_name(self): ) return f"{prefix}.{self.name}" - def to_primitive(self, context=None): + def to_primitive(self, *args, **kwargs): """ Represent the constant via Python's primitive data structures. + .. versionchanged:: 1.5.0 + The ``context`` param is replaced by ``*args`` and ``**kwargs``. + .. versionadded:: 1.3.0 """ @@ -185,9 +188,9 @@ def _make_to_primitive(group, constant): constant_primitive = constant.to_primitive group_primitive = group.to_primitive - def to_primitive(self, context=None): - primitive = constant_primitive(context) - primitive.update(group_primitive(context)) + def to_primitive(self, *args, **kwargs): + primitive = constant_primitive(*args, **kwargs) + primitive.update(group_primitive(*args, **kwargs)) return primitive return types.MethodType(to_primitive, group) @@ -494,12 +497,16 @@ def iteritems(self): #: values. itervalues = iterconstants - def to_primitive(self, context=None): + def to_primitive(self, *args, **kwargs): """ + .. versionchanged:: 1.5.0 + The ``context`` param is replaced by ``*args`` and ``**kwargs``. + .. versionadded:: 1.3.0 + """ items = [ - x.to_primitive(context) + x.to_primitive(*args, **kwargs) for x in self.iterconstants() ] return { diff --git a/candv/exceptions.py b/candv/exceptions.py index be434fb..fc2a73a 100644 --- a/candv/exceptions.py +++ b/candv/exceptions.py @@ -1,4 +1,4 @@ -from .utils import export +from ._utils import export @export diff --git a/candv/ext.py b/candv/ext.py index 5b81ea7..303e8bb 100644 --- a/candv/ext.py +++ b/candv/ext.py @@ -9,7 +9,7 @@ from .exceptions import CandvValueNotFoundError -from .utils import export +from ._utils import export @export @@ -59,11 +59,15 @@ def merge_into_group(self, group): group.verbose_name = self.verbose_name group.help_text = self.help_text - def to_primitive(self, context=None): + def to_primitive(self, *args, **kwargs): """ + .. versionchanged:: 1.5.0 + The ``context`` param is replaced by ``*args`` and ``**kwargs``. + .. versionadded:: 1.3.0 + """ - primitive = super().to_primitive(context) + primitive = super().to_primitive(*args, **kwargs) primitive.update({ 'verbose_name': ( str(self.verbose_name) @@ -117,18 +121,22 @@ def merge_into_group(self, group): super().merge_into_group(group) group.value = self.value - def to_primitive(self, context=None): + def to_primitive(self, *args, **kwargs): """ + .. versionchanged:: 1.5.0 + The ``context`` param is replaced by ``*args`` and ``**kwargs``. + .. versionadded:: 1.3.0 + """ - primitive = super().to_primitive(context) + primitive = super().to_primitive(*args, **kwargs) value = self.value if hasattr(value, "isoformat"): value = value.isoformat() if hasattr(value, "to_primitive"): - value = value.to_primitive(context) + value = value.to_primitive(*args, **kwargs) elif callable(value): value = value() diff --git a/candv/version.py b/candv/version.py index 07857d8..d7cb2e0 100644 --- a/candv/version.py +++ b/candv/version.py @@ -1,6 +1,7 @@ -VERSION_MAJOR = 1 -VERSION_MINOR = 4 -VERSION_PATCH = 0 +VERSION_SUFFIX = None +VERSION_PATCH = "0" + (VERSION_SUFFIX or "") +VERSION_MINOR = "5" +VERSION_MAJOR = "1" VERSION_INFO = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) VERSION = ".".join([str(x) for x in VERSION_INFO]) diff --git a/docs/candv.rst b/docs/candv.rst index 6727d25..de1e2e6 100644 --- a/docs/candv.rst +++ b/docs/candv.rst @@ -28,14 +28,6 @@ candv.ext module :undoc-members: :show-inheritance: -candv.utils module ------------------- - -.. automodule:: candv.utils - :members: - :undoc-members: - :show-inheritance: - candv.version module -------------------- diff --git a/docs/conf.py b/docs/conf.py index 9aec8be..3f1f6f6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,8 +9,8 @@ project = "candv" -version = "1.4" -release = "1.4.0" +version = "1.5" +release = "1.5.0" year = datetime.now().year copyright = f"{year}, Oleksandr Oblovatnyi" @@ -53,6 +53,10 @@ source_suffix = ".rst" master_doc = "index" +autodoc_default_options = { + 'member-order': 'bysource', +} + intersphinx_mapping = { - 'https://docs.python.org/3': None, + "https://docs.python.org/3": None, } diff --git a/docs/index.rst b/docs/index.rst index dd0f64e..e08c110 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -33,6 +33,12 @@ Contents Changelog ========= +* `1.5.0`_ (Nov 18, 2020) + + API changes: + + * ``to_primitive()`` methods use ``*args`` and ``**kwargs`` instead of the ``context`` param. + * `1.4.0`_ (Oct 30, 2020) API changes: public API is not changed, however, the following internal changes are introduced: @@ -175,6 +181,7 @@ Indices and tables .. _issue #1: https://github.com/oblalex/candv/issues/1 .. _issue #11: https://github.com/oblalex/candv/issues/11 +.. _1.5.0: https://github.com/oblalex/candv/compare/v1.4.0...v1.5.0 .. _1.4.0: https://github.com/oblalex/candv/compare/v1.3.1...v1.4.0 .. _1.3.1: https://github.com/oblalex/candv/compare/v1.3.0...v1.3.1 .. _1.3.0: https://github.com/oblalex/candv/compare/v1.2.0...v1.3.0 diff --git a/setup.py b/setup.py index d9b5dad..8b49b33 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,20 @@ import itertools import os import shlex +import sys + +if sys.version_info >= (3, 9): + List = list + Tuple = tuple +else: + from typing import List + from typing import Tuple from pathlib import Path from setuptools import setup from subprocess import check_output -from typing import List from typing import Optional -from typing import Text -from typing import Tuple __here__ = Path(__file__).absolute().parent @@ -19,7 +24,7 @@ exec(compile(version_file_path.read_text(), version_file_path, "exec")) -def maybe_get_shell_output(command: Text) -> Text: +def maybe_get_shell_output(command: str) -> str: try: args = shlex.split(command) with open(os.devnull, "w") as devnull: @@ -28,11 +33,11 @@ def maybe_get_shell_output(command: Text) -> Text: pass -def maybe_get_current_branch_name() -> Optional[Text]: +def maybe_get_current_branch_name() -> Optional[str]: return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD") -def maybe_get_current_commit_hash() -> Optional[Text]: +def maybe_get_current_commit_hash() -> Optional[str]: return maybe_get_shell_output("git rev-parse --short HEAD")