Skip to content

Commit

Permalink
Depend on simplejson for Python < 2.7
Browse files Browse the repository at this point in the history
This adds a dependency on simplejson for Python < 2.7 and moves the
stanza to import the appropriate json module into pyleus.compat.

Closes Yelp#46
  • Loading branch information
Patrick Lucas committed Oct 20, 2014
1 parent e1e7f28 commit 1e6ac7d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 33 deletions.
1 change: 0 additions & 1 deletion examples/top_urls/requirements.txt

This file was deleted.

7 changes: 1 addition & 6 deletions examples/top_urls/top_urls/requests_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
from random import choice
import time

try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from pyleus.compat import json
from pyleus.storm import Spout


Expand Down
11 changes: 10 additions & 1 deletion pyleus/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys

if sys.version_info[0] < 3:
python_version = (sys.version_info[0], sys.version_info[1])

if python_version < (3, 0):
from cStringIO import StringIO
BytesIO = StringIO
else:
Expand All @@ -9,3 +11,10 @@

_ = BytesIO # pyflakes
_ = StringIO # pyflakes

if python_version < (2, 7):
import simplejson as json
else:
import json

_ = json # pyflakes
9 changes: 2 additions & 7 deletions pyleus/json_fields_bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@

import logging

try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from .storm import SimpleBolt
from pyleus.compat import json
from pyleus.storm import SimpleBolt

log = logging.getLogger(__name__)

Expand Down
7 changes: 1 addition & 6 deletions pyleus/storm/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ class around Storm configurations.
import sys
import traceback

try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from pyleus.compat import json
from pyleus.storm import DEFAULT_STREAM
from pyleus.storm import StormTuple
from pyleus.storm.serializers.msgpack_serializer import MsgpackSerializer
Expand Down
7 changes: 1 addition & 6 deletions pyleus/storm/serializers/json_serializer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""JSON implementation of Pyleus serializer"""

try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from pyleus.compat import json
from pyleus.storm import StormWentAwayError
from pyleus.storm.serializers.serializer import Serializer

Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def run(self):
# argparse is in the standard library of Python >= 2.7
extra_install_requires.append("argparse")

# simplejson has better beformance in Python < 2.6 than the built-in json
# module
extra_install_requires.append("simplejson")


setup(
name="pyleus",
Expand Down
7 changes: 1 addition & 6 deletions tests/storm/serializers/json_serializer_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import mock

try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from pyleus.compat import json
from pyleus.compat import StringIO
from pyleus.storm.serializers.json_serializer import JSONSerializer
from testing.serializer import SerializerTestCase
Expand Down

0 comments on commit 1e6ac7d

Please sign in to comment.