From 45251bcdb5bfa8b3f38f75dbd89e1175528dbd92 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 5 Feb 2018 23:38:54 -0800 Subject: [PATCH] Rename to voluptuous serialize --- README.md | 22 +++++++++---------- setup.py | 8 +++---- tests/test_lib.py | 2 +- .../__init__.py | 3 ++- 4 files changed, 18 insertions(+), 17 deletions(-) rename {voluptuous_json => voluptuous_serialize}/__init__.py (94%) diff --git a/README.md b/README.md index 98b308f..f6bb6a4 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -### This is an experiment. Not production ready. Do not use. +# Voluptuous Serialize -# Voluptuous JSON (experiment) - -This is an experiment to see if it is possible to easily convert voluptuous schemas to JSON. - -Goal would be to create a set of Polymer components that can consume this data and generate a form that matches the expected data. +Convert Voluptuous schemas to dictionaries so they can be serialized. ```python -vol.Schema({ - vol.Required('name'): vol.All(str, vol.Length(min=5)), - vol.Required('age'): vol.All(vol.Coerce(int), vol.Range(min=18)), - vol.Optional('hobby', default='not specified'): str -}) +from collections import OrderedDict + +# Use OrderedDict instead of dict. +# Only starting Python 3.6+ are dictionaries ordered. +schema = OrderedDict() +schema[vol.Required('name')] = vol.All(str, vol.Length(min=5)) +schema[vol.Required('age')] = vol.All(vol.Coerce(int), vol.Range(min=18)) +schema[vol.Optional('hobby', default='not specified')] = str +schema = vol.Schema(schema) ``` becomes diff --git a/setup.py b/setup.py index 0defb9b..da91324 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ from setuptools import setup -setup(name='voluptuous-json', +setup(name='voluptuous-serialize', version='0.1', - description='Convert voluptuous schemas to JSON', - url='http://github.com/balloob/voluptuous-json', + description='Convert voluptuous schemas to dictionaries', + url='http://github.com/balloob/voluptuous-serialize', author='Paulus Schoutsen', author_email='Paulus@PaulusSchoutsen.nl', license='Apache License 2.0', install_requires=['voluptuous'], packages=['voluptuous_json'], - zip_safe=True) \ No newline at end of file + zip_safe=True) diff --git a/tests/test_lib.py b/tests/test_lib.py index 4432790..bcf825d 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -1,6 +1,6 @@ import voluptuous as vol -from voluptuous_json import convert +from voluptuous_serialize import convert def test_int_schema(): diff --git a/voluptuous_json/__init__.py b/voluptuous_serialize/__init__.py similarity index 94% rename from voluptuous_json/__init__.py rename to voluptuous_serialize/__init__.py index 0737543..5bcec1b 100644 --- a/voluptuous_json/__init__.py +++ b/voluptuous_serialize/__init__.py @@ -1,3 +1,4 @@ +"""Module to convert voluptuous schemas to dictionaries.""" import collections import voluptuous as vol @@ -12,7 +13,7 @@ def convert(schema): - """Convert a voluptuous schema to JSON.""" + """Convert a voluptuous schema to a dictionary.""" if isinstance(schema, vol.Schema): schema = schema.schema