Remove use of prints in the setup package since nowadays most systems are UTF-8 based anyway

This commit is contained in:
Kovid Goyal 2018-09-10 19:55:49 +05:30
parent a9e07efecd
commit f4b3585549
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 49 deletions

View File

@ -25,7 +25,7 @@ check_version_info()
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import setup.commands as commands import setup.commands as commands
from setup import prints, get_warnings from setup import get_warnings
def option_parser(): def option_parser():
@ -93,13 +93,13 @@ def main(args=sys.argv):
clean_backups() clean_backups()
if opts.clean: if opts.clean:
prints('Cleaning', args[1]) print('Cleaning', args[1])
command.clean() command.clean()
return 0 return 0
if opts.clean_all: if opts.clean_all:
for cmd in commands.__all__: for cmd in commands.__all__:
prints('Cleaning', cmd) print('Cleaning', cmd)
getattr(commands, cmd).clean() getattr(commands, cmd).clean()
return 0 return 0
@ -108,10 +108,10 @@ def main(args=sys.argv):
warnings = get_warnings() warnings = get_warnings()
if warnings: if warnings:
print() print()
prints('There were', len(warnings), 'warning(s):') print('There were', len(warnings), 'warning(s):')
print() print()
for args, kwargs in warnings: for args, kwargs in warnings:
prints('*', *args, **kwargs) print('*', *args, **kwargs)
print() print()
return 0 return 0

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement from __future__ import with_statement, print_function
from __future__ import print_function
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
@ -120,46 +119,6 @@ initialize_constants()
preferred_encoding = 'utf-8' preferred_encoding = 'utf-8'
def prints(*args, **kwargs):
'''
Print unicode arguments safely by encoding them to preferred_encoding
Has the same signature as the print function from Python 3, except for the
additional keyword argument safe_encode, which if set to True will cause the
function to use repr when encoding fails.
'''
file = kwargs.get('file', sys.stdout)
sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n')
enc = preferred_encoding
safe_encode = kwargs.get('safe_encode', False)
for i, arg in enumerate(args):
if isinstance(arg, unicode):
try:
arg = arg.encode(enc)
except UnicodeEncodeError:
if not safe_encode:
raise
arg = repr(arg)
if not isinstance(arg, str):
try:
arg = str(arg)
except ValueError:
arg = unicode(arg)
if isinstance(arg, unicode):
try:
arg = arg.encode(enc)
except UnicodeEncodeError:
if not safe_encode:
raise
arg = repr(arg)
file.write(arg)
if i != len(args)-1:
file.write(sep)
file.write(end)
warnings = [] warnings = []
@ -266,12 +225,12 @@ class Command(object):
return newer(targets, sources) return newer(targets, sources)
def info(self, *args, **kwargs): def info(self, *args, **kwargs):
prints(*args, **kwargs) print(*args, **kwargs)
sys.stdout.flush() sys.stdout.flush()
def warn(self, *args, **kwargs): def warn(self, *args, **kwargs):
print('\n'+'_'*20, 'WARNING','_'*20) print('\n'+'_'*20, 'WARNING','_'*20)
prints(*args, **kwargs) print(*args, **kwargs)
print('_'*50) print('_'*50)
warnings.append((args, kwargs)) warnings.append((args, kwargs))
sys.stdout.flush() sys.stdout.flush()