diff --git a/.gitignore b/.gitignore index 32a9f6e..bbf554a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .* *.pyc __pycache__/ +beeprint.egg-info/* +build/* +dist/* diff --git a/beeprint/helper.py b/beeprint/helper.py index 3749f5e..6328d83 100644 --- a/beeprint/helper.py +++ b/beeprint/helper.py @@ -10,10 +10,13 @@ from . import constants as C from . import settings as S -from .utils import pyv +from .utils import pyv, _unicode from .terminal_size import get_terminal_size # from kitchen.text import display +if pyv == 3: + xrange = range + def typeval(context, v): try: @@ -46,7 +49,7 @@ def pstr(s): ''' res = u'' - if isinstance(s, unicode): + if isinstance(s, _unicode): res += s elif isinstance(s, str): # in python 2/3, it's utf8 @@ -82,7 +85,7 @@ def string_type(s): # in py2, string literal is both instance of str and bytes # a literal string is str (i.e: coding encoded, eg: utf8) # a u-prefixed string is unicode - if isinstance(s, unicode): + if isinstance(s, _unicode): return C._ST_UNICODE_ elif isinstance(s, str): # same as isinstance(v, bytes) return C._ST_LITERAL_ | C._ST_BYTES_ @@ -139,7 +142,7 @@ def string_handle(context, s, st): left_margin%2*u' ', seg_list[i], ]) - s = '\n'.join(seg_list) + s = "\n".join(seg_list) str_encloser.body = s @@ -172,6 +175,10 @@ def wrap_string(s, width): t = urwid.Text(s) seg_list = t.render((width,)).text seg_list = [seg.rstrip() for seg in seg_list] + if pyv == 3: + # seg is the type of in py3 + # seg is the type of in py2 + seg_list = [seg.decode('utf8') for seg in seg_list] return seg_list def is_extendable(obj): @@ -202,7 +209,7 @@ def object_attr_default_filter(obj, name, val): for prop in S.prop_filters: # filter is a string - if isinstance(prop, str) or isinstance(prop, unicode): + if isinstance(prop, str) or isinstance(prop, _unicode): if name == prop: return True # filter is a type diff --git a/beeprint/printer.py b/beeprint/printer.py index d847fe8..d27b08f 100644 --- a/beeprint/printer.py +++ b/beeprint/printer.py @@ -18,8 +18,6 @@ reload(sys) sys.setdefaultencoding('utf-8') -else: - unicode = str from . import settings as S from . import constants as C diff --git a/beeprint/utils.py b/beeprint/utils.py index 6919a43..9471efe 100644 --- a/beeprint/utils.py +++ b/beeprint/utils.py @@ -8,10 +8,13 @@ import types +_unicode = None if sys.version_info < (3, 0): pyv = 2 + _unicode = unicode else: pyv = 3 + _unicode = str def is_class_method(name, val): if pyv == 2: diff --git a/makefile b/makefile index b69c306..f25e1de 100644 --- a/makefile +++ b/makefile @@ -12,7 +12,9 @@ register: python setup.py register -r pypitest || true full: - python setup.py sdist bdist_egg upload + python2.7 setup.py bdist_egg upload + python3.5 setup.py bdist_egg upload + python setup.py sdist upload test27: python2.7 -m unittest discover tests || true diff --git a/setup.py b/setup.py index edf71ff..9c31f92 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ -from distutils.core import setup +from setuptools import setup setup( name = 'beeprint', packages = ['beeprint'], # this must be the same as the name above - version = '0.1', - description = 'print object in beautiful format, like pprint', + version = '2.2.1', + description = 'make your debug printing more friendly', author = 'Yangyang Pan', author_email = '568397440@qq.com', url = 'https://github.com/panyanyany/beeprint', # use the URL to the github repo download_url = 'https://github.com/panyanyany/beeprint/archive/master.zip', # I'll explain this in a second - keywords = ['print', 'pprint', 'format'], # arbitrary keywords + keywords = ['print', 'pprint', 'format', 'debug'], # arbitrary keywords classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 2", @@ -22,7 +22,7 @@ "Topic :: Software Development", "Topic :: Utilities", ], - install_requires=[ + install_requires = [ 'urwid', ], )