Skip to content

Commit

Permalink
Update to v1.5.0
Browse files Browse the repository at this point in the history
Changes args passed of 'to_primitive()' methods.
  • Loading branch information
o3bvv committed Nov 18, 2020
2 parents 77de8cc + c008238 commit 2573c07
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 34 deletions.
File renamed without changes.
21 changes: 14 additions & 7 deletions candv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion candv/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utils import export
from ._utils import export


@export
Expand Down
20 changes: 14 additions & 6 deletions candv/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .exceptions import CandvValueNotFoundError

from .utils import export
from ._utils import export


@export
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions candv/version.py
Original file line number Diff line number Diff line change
@@ -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])
8 changes: 0 additions & 8 deletions docs/candv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
10 changes: 7 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
}
7 changes: 7 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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")


Expand Down

0 comments on commit 2573c07

Please sign in to comment.