Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Make serde-ext Fields and validators available #75

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ clean: docs-clean ## Remove all build artifacts.
find . \( -name *.pyc -o -name *.pyo -o -name __pycache__ -o -name *.egg-info \) -exec rm -rf {} +

install: ## Install package and all features.
$(VIRTUAL_ENV)/bin/pip install -e ".[cbor,toml,yaml]"
$(VIRTUAL_ENV)/bin/pip install -e ".[ext,cbor,toml,yaml]"

install-plain: ## Install package, all features, and testing dependencies.
$(VIRTUAL_ENV)/bin/pip install -e ".[cbor,toml,yaml,dev.test]"
$(VIRTUAL_ENV)/bin/pip install -e ".[ext,cbor,toml,yaml,dev.test]"

install-dev: ## Install package, all features, and linting and testing dependencies.
$(VIRTUAL_ENV)/bin/pip install -e ".[cbor,toml,yaml,dev.lint,dev.test]"
$(VIRTUAL_ENV)/bin/pip install -e ".[ext,cbor,toml,yaml,dev.lint,dev.test]"

install-all: install-dev ## Install package, all features, and all development dependencies.
$(VIRTUAL_ENV)/bin/pip install sphinx twine
Expand Down
7 changes: 7 additions & 0 deletions RELEASES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Releases
========

0.5.1
-----

- Reexport `serde-ext`_ Fields and validators. (`#75`_)

.. _#75: https://github.com/rossmacarthur/serde/pull/75

0.5.0
-----

Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def get_metadata():
'six >=1.0.0, <2.0.0',
'validators >=0.12.0, <0.13.0'
]
ext_requires = [
'serde-ext >=0.1.0, <0.2.0'
]
cbor_requires = [
'cbor2 >=4.0.0, <5.0.0'
]
Expand Down Expand Up @@ -73,6 +76,7 @@ def get_metadata():
# Options
install_requires=install_requires,
extras_require={
'ext': ext_requires,
'cbor': cbor_requires,
'json': json_requires,
'toml': toml_requires,
Expand Down
5 changes: 4 additions & 1 deletion src/serde/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

from serde import validate
from serde.exceptions import SerdeError, SkipSerialization, ValidationError
from serde.utils import zip_equal
from serde.utils import try_import_all, zip_equal


__all__ = [
Expand Down Expand Up @@ -1336,3 +1336,6 @@ def deserialize(self, value):
FIELD_CLASSES[unicode] = Unicode
except NameError:
pass


try_import_all('serde_ext.fields', globals())
19 changes: 19 additions & 0 deletions src/serde/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ def try_import(name, package=None):
pass


def try_import_all(name, namespace):
"""
Try import the names from the given library, ignoring ImportErrors.

Args:
name (str): the name to import.
namespace (dict): the namespace to update.
"""
module = try_import(name)

if module:
if hasattr(module, '__all__'):
all_names = module.__all__
else:
all_names = (name for name in dir(module) if not name.startswith('_'))

namespace.update({name: getattr(module, name) for name in all_names})


def zip_equal(*iterables):
"""
A zip function that validates that all the iterables have the same length.
Expand Down
4 changes: 4 additions & 0 deletions src/serde/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from serde.exceptions import ValidationError
from serde.utils import try_import_all


__all__ = [
Expand Down Expand Up @@ -315,3 +316,6 @@ def contains_(value):
raise ValidationError('{!r} is not a valid choice'.format(value))

return contains_


try_import_all('serde_ext.validate', globals())