From 84419f6bfbd2ae1e36f9d533856d05912b360ce4 Mon Sep 17 00:00:00 2001 From: robbles Date: Wed, 28 Sep 2011 11:13:26 -0700 Subject: [PATCH 1/6] fix mismatch with argument names for progress.bar --- clint/textui/progress.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clint/textui/progress.py b/clint/textui/progress.py index 4ca2b0f..3a94d1b 100644 --- a/clint/textui/progress.py +++ b/clint/textui/progress.py @@ -17,16 +17,17 @@ STREAM = sys.stderr BAR_TEMPLATE = '%s[%s%s] %i/%i\r' DOTS_CHAR = '.' +BAR_FILLED_CHAR = '#' +BAR_EMPTY_CHAR = ' ' - -def bar(it, label='', width=32, hide=False, empty_char='-', filled_char='='): +def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR): """Progress iterator. Wrap your iterables with it.""" def _show(_i): x = int(width*_i/count) if not hide: STREAM.write(BAR_TEMPLATE % ( - label, bar_filled_char*x, bar_empty_char*(width-x), _i, count)) + label, filled_char*x, empty_char*(width-x), _i, count)) STREAM.flush() count = len(it) From 8e6973253f45dc4bbf5aa489531cc70f9e0c209c Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 28 Oct 2011 13:04:31 -0300 Subject: [PATCH 2/6] Update clint/textui/progress.py --- clint/textui/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clint/textui/progress.py b/clint/textui/progress.py index 4ca2b0f..c958e2b 100644 --- a/clint/textui/progress.py +++ b/clint/textui/progress.py @@ -26,7 +26,7 @@ def bar(it, label='', width=32, hide=False, empty_char='-', filled_char='='): x = int(width*_i/count) if not hide: STREAM.write(BAR_TEMPLATE % ( - label, bar_filled_char*x, bar_empty_char*(width-x), _i, count)) + label, filled_char*x, empty_char*(width-x), _i, count)) STREAM.flush() count = len(it) From 1ea4c5afdc3eb9a14b076b265a8647dd99304fb9 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 5 Jan 2012 23:24:25 +0000 Subject: [PATCH 3/6] Installable on Python 3. --- clint/arguments.py | 6 +++++- clint/eng.py | 13 +++++++------ clint/resources.py | 2 +- clint/textui/__init__.py | 2 +- clint/utils.py | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/clint/arguments.py b/clint/arguments.py index 4b823b6..e4f25a4 100644 --- a/clint/arguments.py +++ b/clint/arguments.py @@ -14,7 +14,11 @@ from __future__ import absolute_import import os from sys import argv -from .packages.ordereddict import OrderedDict +try: + from collections import OrderedDict +except ImportError: + from .packages.ordereddict import OrderedDict + from .utils import expand_path, is_collection __all__ = ('Args', ) diff --git a/clint/eng.py b/clint/eng.py index c8e5774..8d9f608 100644 --- a/clint/eng.py +++ b/clint/eng.py @@ -7,6 +7,7 @@ clint.eng This module provides English language string helpers. """ +from __future__ import print_function MORON_MODE = False COMMA = ',' @@ -41,9 +42,9 @@ def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA): return unicode(str().join(collector)) if __name__ == '__main__': - print join(['blue', 'red', 'yellow'], conj='or', im_a_moron=True) - print join(['blue', 'red', 'yellow'], conj='or') - print join(['blue', 'red'], conj='or') - print join(['blue', 'red'], conj='and') - print join(['blue'], conj='and') - print join(['blue', 'red', 'yellow', 'green', 'ello'], conj='and') \ No newline at end of file + print(join(['blue', 'red', 'yellow'], conj='or', im_a_moron=True)) + print(join(['blue', 'red', 'yellow'], conj='or')) + print(join(['blue', 'red'], conj='or')) + print(join(['blue', 'red'], conj='and')) + print(join(['blue'], conj='and')) + print(join(['blue', 'red', 'yellow', 'green', 'ello'], conj='and')) diff --git a/clint/resources.py b/clint/resources.py index b482750..b499a0f 100644 --- a/clint/resources.py +++ b/clint/resources.py @@ -115,7 +115,7 @@ class AppDir(object): remove(fn) else: removedirs(fn) - except OSError, why: + except OSError as why: if why.errno == errno.ENOENT: pass else: diff --git a/clint/textui/__init__.py b/clint/textui/__init__.py index 39681c6..3b8c92a 100644 --- a/clint/textui/__init__.py +++ b/clint/textui/__init__.py @@ -12,4 +12,4 @@ This module provides the text output helper system. from . import colored from . import progress -from core import * +from .core import * diff --git a/clint/utils.py b/clint/utils.py index b215c33..fb41ff1 100644 --- a/clint/utils.py +++ b/clint/utils.py @@ -49,7 +49,7 @@ def mkdir_p(path): """Emulates `mkdir -p` behavior.""" try: makedirs(path) - except OSError, exc: # Python >2.5 + except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST: pass else: From b16b2ce7237159c3764c5cc2a3e7292d31310d25 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 6 Jan 2012 00:11:51 +0000 Subject: [PATCH 4/6] All examples work on Python 3. --- clint/eng.py | 5 +++++ clint/textui/colored.py | 18 +++++++++++++----- clint/utils.py | 4 ++++ examples/colors_all.py | 4 +++- examples/eng_join.py | 2 +- examples/resources.py | 12 +++++++----- examples/text_width.py | 5 +++-- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/clint/eng.py b/clint/eng.py index 8d9f608..e903631 100644 --- a/clint/eng.py +++ b/clint/eng.py @@ -14,6 +14,11 @@ COMMA = ',' CONJUNCTION = 'and' SPACE = ' ' +try: + unicode +except NameError: + unicode = str + def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA): """Joins lists of words. Oxford comma and all.""" diff --git a/clint/textui/colored.py b/clint/textui/colored.py index e7c0754..63d7593 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -14,6 +14,8 @@ from __future__ import absolute_import import re import sys +PY3 = sys.version_info[0] >= 3 + from ..packages import colorama __all__ = ( @@ -53,12 +55,18 @@ class ColoredString(object): def __repr__(self): return "<%s-string: '%s'>" % (self.color, self.s) - def __str__(self): - return self.__unicode__().encode('utf8') - def __unicode__(self): return self.color_str + if PY3: + __str__ = __unicode__ + else: + def __str__(self): + return unicode(self).encode('utf8') + + def __iter__(self): + return iter(self.color_str) + def __add__(self, other): return str(self.color_str) + str(other) @@ -68,8 +76,8 @@ class ColoredString(object): def __mul__(self, other): return (self.color_str * other) - def split(self, x=' '): - return map(self._new, self.s.split(x)) + def split(self, sep=None): + return [self._new(s) for s in self.s.split(sep)] def _new(self, s): return ColoredString(self.color, s) diff --git a/clint/utils.py b/clint/utils.py index fb41ff1..e84e851 100644 --- a/clint/utils.py +++ b/clint/utils.py @@ -16,6 +16,10 @@ import os.path from os import makedirs from glob import glob +try: + basestring +except NameError: + basestring = str def expand_path(path): """Expands directories and globs in given path.""" diff --git a/examples/colors_all.py b/examples/colors_all.py index 92dd779..79d09c5 100755 --- a/examples/colors_all.py +++ b/examples/colors_all.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function + import sys import os @@ -13,4 +15,4 @@ text = 'THIS TEXT IS COLORED %s!' if __name__ == '__main__': for color in colored.COLORS: - print getattr(colored, color)(text % color.upper()) \ No newline at end of file + print(getattr(colored, color)(text % color.upper())) diff --git a/examples/eng_join.py b/examples/eng_join.py index c2736b1..12d3dee 100644 --- a/examples/eng_join.py +++ b/examples/eng_join.py @@ -17,7 +17,7 @@ colors = [ colored.magenta('magenta') ] -colors = map(str, colors) +colors = [str(cs) for cs in colors] puts('Smart:') diff --git a/examples/resources.py b/examples/resources.py index 7380c09..0ec65d0 100755 --- a/examples/resources.py +++ b/examples/resources.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function + import sys import os @@ -13,16 +15,16 @@ resources.init('kennethreitz', 'clint') lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' -print '%s created.' % resources.user.path +print('%s created.' % resources.user.path) resources.user.write('lorem.txt', lorem) -print 'lorem.txt created' +print('lorem.txt created') assert resources.user.read('lorem.txt') == lorem -print 'lorem.txt has correct contents' +print('lorem.txt has correct contents') resources.user.delete('lorem.txt') -print 'lorem.txt deleted' +print('lorem.txt deleted') assert resources.user.read('lorem.txt') == None -print 'lorem.txt deletion confirmed' \ No newline at end of file +print('lorem.txt deletion confirmed') diff --git a/examples/text_width.py b/examples/text_width.py index bfbfe15..ed37716 100755 --- a/examples/text_width.py +++ b/examples/text_width.py @@ -19,5 +19,6 @@ if __name__ == '__main__': col = 60 - puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None], [(colored.magenta('Column III')), col])) - puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col])) \ No newline at end of file + puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None], + [(colored.magenta('Column III')), col])) + puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col])) From 9a4705f090dda6a345e9ac5900fddf936d3edb08 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 6 Jan 2012 00:16:14 +0000 Subject: [PATCH 5/6] Update trove classifiers. --- .gitignore | 1 + setup.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b49e53e..875204c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ MANIFEST *.pyc .tox +build/ diff --git a/setup.py b/setup.py index a6f90e7..fd62e29 100644 --- a/setup.py +++ b/setup.py @@ -38,14 +38,18 @@ setup( license='ISC', classifiers=( # 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: ISC License (ISCL)', 'Programming Language :: Python', + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', - # 'Programming Language :: Python :: 3.0', - # 'Programming Language :: Python :: 3.1', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.1', + 'Programming Language :: Python :: 3.2', + 'Topic :: Terminals :: Terminal Emulators/X Terminals', ), ) From dbb063840a09511b122683f9d37c5e4f229ca3c1 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 5 Jan 2012 22:14:33 -0500 Subject: [PATCH 6/6] v0.3.0 --- AUTHORS | 1 + HISTORY.rst | 5 +++++ clint/__init__.py | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index f172f24..5d258aa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,3 +16,4 @@ Patches and Suggestions - Will Thames - Greg Haskins - Miguel Araujo +- takluyver \ No newline at end of file diff --git a/HISTORY.rst b/HISTORY.rst index 5ece8fc..d13983e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,11 @@ History ------- +0.3.0 ++++++ + +* Python 3 support! + 0.2.4 +++++ diff --git a/clint/__init__.py b/clint/__init__.py index 793226b..609b948 100644 --- a/clint/__init__.py +++ b/clint/__init__.py @@ -19,11 +19,11 @@ from .pipes import piped_in __title__ = 'clint' -__version__ = '0.2.5' -__build__ = 0x000205 +__version__ = '0.3.0' +__build__ = 0x000300 __author__ = 'Kenneth Reitz' __license__ = 'ISC' -__copyright__ = 'Copyright 2011 Kenneth Reitz' +__copyright__ = 'Copyright 2012 Kenneth Reitz' __docformat__ = 'restructuredtext'