Skip to content

Commit

Permalink
Added to_JSON for notations and fixed setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
PacketPerception committed Jun 12, 2016
1 parent 86e28d1 commit f13b27c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/pyjuggling.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions juggling/notation/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import json
import types


class JugglingNotation(object):
def __init__(self, notation_pattern, raise_invalid=False):
# type: (Any, int, bool)
Expand Down Expand Up @@ -33,3 +37,18 @@ def is_valid(self):

def pretty_print(self):
print(str(self.notation_pattern))

def to_JSON(self):
""" Return a JSON serialized version of the :class:`Notation` """
# We build up this data dict so that we capture the @properties as well as the attributes as well as get all
# inherited properties and values
data = {}
for attr in dir(self):
if attr.startswith('__'):
continue
value = getattr(self, attr)
if not (isinstance(value, types.MethodType) or
isinstance(value, types.FunctionType)):
data[attr] = value

return json.dumps(data, default=lambda o: o.__dict__, sort_keys=True, indent=4)
1 change: 0 additions & 1 deletion juggling/notation/siteswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def is_valid_siteswap_syntax(pattern, num_jugglers=1, return_match=False):
def convert_char_to_beat(beat_str):
# type: (str) -> (int or list)
""" Converts a single siteswap beat into a :class:`Pattern` beat """
print("converting: {}".format(beat_str))
if beat_str.startswith('['):
return [siteswap_char_to_int(_) for _ in beat_str[1:-1]]
elif beat_str.startswith('('):
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import sys

try:
from setuptools import setup
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup
from distutils.core import setup, find_packages

import juggling

Expand All @@ -28,9 +28,7 @@ def publish():
author='Brian Knobbs',
author_email='brian@packetperception.org',
url='https://github.com/PacketPerception/pyjuggling',
packages=[
'juggling',
],
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
extras_require={
},
license='MIT',
Expand Down

0 comments on commit f13b27c

Please sign in to comment.