From 3a4869b325aafb918f7b934e7d93c9e0d1c2a4a8 Mon Sep 17 00:00:00 2001 From: Ryan Pessa Date: Tue, 15 Dec 2015 16:11:05 -0600 Subject: [PATCH 1/2] improve installed package detection --- pythonforandroid/build.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index a25b8ddcb0..683159685d 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -471,6 +471,13 @@ def get_libs_dir(self, arch): return join(self.libs_dir, arch) def has_package(self, name, arch=None): + try: + recipe = Recipe.get_recipe(name, self) + except IOError: + pass + else: + name = getattr(recipe, 'site_packages_name', None) or name + name = name.replace('.', '/') site_packages_dir = self.get_site_packages_dir(arch) return (exists(join(site_packages_dir, name)) or exists(join(site_packages_dir, name + '.py')) or From 1833ae94c7c9ed06fad54929bbc82dc102b27602 Mon Sep 17 00:00:00 2001 From: Ryan Pessa Date: Tue, 15 Dec 2015 16:12:34 -0600 Subject: [PATCH 2/2] fix decode error on py2; allow console width to be set via COLUMNS env var --- pythonforandroid/logger.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pythonforandroid/logger.py b/pythonforandroid/logger.py index 6e8af698ca..d3ab179ef9 100644 --- a/pythonforandroid/logger.py +++ b/pythonforandroid/logger.py @@ -92,8 +92,27 @@ def shorten_string(string, max_width): return string visible = max_width - 16 - int(log10(string_len)) # expected suffix len "...(and XXXXX more)" - return ''.join((string[:visible], '...(and ', str(string_len - visible), - ' more)')) + return u''.join((string[:visible], u'...(and ', str(string_len - visible), + u' more)')) + + +def get_console_width(): + try: + cols = int(os.environ['COLUMNS']) + except (KeyError, ValueError): + pass + else: + if cols >= 25: + return cols + + try: + cols = max(25, int(os.popen('stty size', 'r').read().split()[1])) + except Exception: + pass + else: + return cols + + return 100 def shprint(command, *args, **kwargs): @@ -109,10 +128,7 @@ def shprint(command, *args, **kwargs): filter_out = kwargs.pop('_filterout', None) if len(logger.handlers) > 1: logger.removeHandler(logger.handlers[1]) - try: - columns = max(25, int(os.popen('stty size', 'r').read().split()[1])) - except: - columns = 100 + columns = get_console_width() command_path = str(command).split('/') command_string = command_path[-1] string = ' '.join(['running', command_string] + list(args))