From 30a61e17a1cb3c2a582429caf793d38d92f9c655 Mon Sep 17 00:00:00 2001 From: Alexander Shorin Date: Sun, 25 Dec 2011 22:27:02 +0400 Subject: [PATCH] Add support of Python 2.4 and 2.5 with simplejson. --- jsonpatch.py | 6 +++++- setup.py | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/jsonpatch.py b/jsonpatch.py index 8ab5278..c82b692 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -39,8 +39,12 @@ __version__ = '0.1' __website__ = 'https://github.com/stefankoegl/python-json-patch' __license__ = 'Modified BSD License' +import sys -import json +if sys.version_info < (2, 6): + import simplejson as json +else: + import json class JsonPatchException(Exception): diff --git a/setup.py b/setup.py index c9a3900..b7f781f 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,14 @@ #!/usr/bin/env python -from distutils.core import setup +import sys import re +import warnings +try: + from setuptools import setup + has_setuptools = True +except ImportError: + from distutils.core import setup + has_setuptools = False src = open('jsonpatch.py').read() metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", src)) @@ -13,6 +20,20 @@ MODULES = ( 'jsonpatch', ) +REQUIREMENTS = [] +if sys.version_info < (2, 6): + REQUIREMENTS += ['simplejson'] + +if has_setuptools: + OPTIONS = { + 'install_requires': REQUIREMENTS + } +else: + if sys.version_info < (2, 6): + warnings.warn('No setuptools installed. Be sure that you have ' + 'json or simplejson package installed') + OPTIONS = {} + AUTHOR_EMAIL = metadata['author'] VERSION = metadata['version'] WEBSITE = metadata['website'] @@ -30,4 +51,5 @@ setup(name=PACKAGE, license=LICENSE, url=WEBSITE, py_modules=MODULES, + **OPTIONS )