diff --git a/.travis.yml b/.travis.yml index 33f43e645c73a6afd140963a8ce35ceb68e60200..c97e5cd15ce5fdb749ee30a9f8cc981b1fad6f4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build - pip install -r requirements.txt - - pip install coverage nose2 requests + - pip install coverage nose2 jobs: include: - stage: test diff --git a/CHANGELOG.md b/CHANGELOG.md index 783eb50abadb08d2e53a7b39b8e8da6226bb1e09..7eb50e4cde5d6c5f5cb81d667ef6157a4d898e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ # v2.8.12 +* added optional `ujson` support diff --git a/docs/configuration/sources.rst b/docs/configuration/sources.rst index 1e613f6bbb78fde65ea83ac4c9ec142c2557b827..c62e5452711a896984ace20ef2143b91ae9b2312 100644 --- a/docs/configuration/sources.rst +++ b/docs/configuration/sources.rst @@ -37,6 +37,10 @@ Then there are abstract sources of configuration. In order to actually load the configuration, use the method ``provide()``. +Note that `FileSource` will try parsing the file with any modules, available, so if you +want parsing for **yaml** and **toml**, you better install `pyyaml` and `toml` respectively. + +Note that JSON will be parsed using `ujson` if the module is available. JSON schema ----------- diff --git a/requirements.txt b/requirements.txt index d36e77a2cf5accf12f8f22e842bfb5d8f2be0291..70f2858593e2c03d4c5ffce6cc4e3a7f170fd3ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ psutil pyyaml toml +requests +ujson diff --git a/satella/__init__.py b/satella/__init__.py index 386204b26d9bebc8275752b93a6ecb0db874ec8f..99ba688534cd640fab3a8f28cb00f3d297978854 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.8.12_a1' +__version__ = '2.8.12_a2' diff --git a/satella/configuration/sources/format.py b/satella/configuration/sources/format.py index b443f0df9993e75269a4ec11467b2a6dc38e336e..e39dff23099ce529c6d6e2cf2dba891aeee7e904 100644 --- a/satella/configuration/sources/format.py +++ b/satella/configuration/sources/format.py @@ -1,6 +1,5 @@ import binascii import codecs -import json import typing as tb from satella.coding.recast_exceptions import rethrow_as @@ -60,14 +59,26 @@ class FormatSource(BaseSource): else: return ret_val +try: + import ujson -@register_format_source -class JSONSource(FormatSource): - """ - Loads JSON strings - """ - TRANSFORM = json.loads - EXTRA_EXCEPTIONS = [json.JSONDecodeError] + @register_format_source + class JSONSource(FormatSource): + """ + Loads JSON strings + """ + TRANSFORM = ujson.loads + EXTRA_EXCEPTIONS = [ValueError] +except ImportError: + import json + + @register_format_source + class JSONSource(FormatSource): + """ + Loads JSON strings + """ + TRANSFORM = json.loads + EXTRA_EXCEPTIONS = [json.JSONDecodeError] try: diff --git a/setup.py b/setup.py index dbf6e556a3953cc4e00fc0d94c404d9c4b51347c..309535095a80cf212f03b051b0a567fcf5c6f449 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server', 'psutil' ], tests_require=[ - "nose2", "mock", "coverage", "nose2[coverage_plugin]", "requests" + "nose2", "mock", "coverage" ], test_suite='nose2.collector.collector', python_requires='!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*', @@ -17,6 +17,7 @@ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server', 'HTTPJSONSource': ['requests'], 'YAMLSource': ['pyyaml'], 'TOMLSource': ['toml'], + 'Faster JSONSource': ['ujson'], 'satella.cassandra': ['cassandra-driver'] } ) diff --git a/unittest.cfg b/unittest.cfg deleted file mode 100644 index 84743c4d941883b3d937ca5205dd980c16fc76de..0000000000000000000000000000000000000000 --- a/unittest.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[coverage] -always-on = True