Skip to content

Commit f80d1f6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into master
Conflicts: pythonforandroid/toolchain.py
2 parents 5fdbbd6 + a30fc53 commit f80d1f6

File tree

3 files changed

+63
-49
lines changed

3 files changed

+63
-49
lines changed

doc/source/bootstraps.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Bootstraps
33
==========
44

5-
python-for-android (p4a) supports multiple *bootstraps*. These fulfil a
5+
python-for-android (p4a) supports multiple *bootstraps*. These fulfill a
66
similar role to recipes, but instead of describing how to compile a
77
specific module they describe how a full Android project may be put
88
together from a combination of individual recipes and other
@@ -91,6 +91,6 @@ be clear. However, the :code:`run_distribute` method must do all the
9191
work of creating a build directory, copying recipes etc into it, and
9292
adding or removing any extra components as necessary.
9393

94-
If you'd like to creat a bootstrap, the best resource is to check the
94+
If you'd like to create a bootstrap, the best resource is to check the
9595
existing ones in the p4a source code. You can also :doc:`contact the
9696
developers <troubleshooting>` if you have problems or questions.

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ python-for-android
44
python-for-android is an open source build tool to let you package
55
Python code into standalone android APKs that can be passed around,
66
installed, or uploaded to marketplaces such as the Play Store just
7-
like any other Androip app. This tool was originally developed for the
7+
like any other Android app. This tool was originally developed for the
88
`Kivy cross-platform graphical framework <http://kivy.org/#home>`_,
99
but now supports multiple bootstraps and can be easily extended to
1010
package other types of Python app for Android.

pythonforandroid/toolchain.py

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from __future__ import print_function
1010

1111
import sys
12-
from sys import stdout, platform
12+
from sys import stdout, stderr, platform
1313
from os.path import (join, dirname, realpath, exists, isdir, basename,
1414
expanduser, splitext)
1515
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk, uname
@@ -44,16 +44,30 @@
4444
import argparse
4545
from appdirs import user_data_dir
4646
import sh
47-
if sys.stdout.isatty():
48-
from colorama import Style, Fore
47+
48+
from colorama import Style as Colo_Style, Fore as Colo_Fore
49+
from collections import defaultdict
50+
class colorama_shim(object):
51+
def __init__(self):
52+
self._dict = defaultdict(str)
53+
def __getattr__(self, key):
54+
return self._dict[key]
55+
Style = Fore = colorama_shim()
56+
Null_Style = Null_Fore = colorama_shim()
57+
58+
if stdout.isatty():
59+
Out_Style = Colo_Style
60+
Out_Fore = Colo_Fore
61+
else:
62+
Out_Style = Null_Style
63+
Out_Fore = Null_Fore
64+
65+
if stderr.isatty():
66+
Err_Style = Colo_Style
67+
Err_Fore = Colo_Fore
4968
else:
50-
from collections import defaultdict
51-
class colorama_shim(object):
52-
def __init__(self):
53-
self._dict = defaultdict(str)
54-
def __getattr__(self, key):
55-
return self._dict[key]
56-
Style = Fore = colorama_shim()
69+
Err_Style = Null_Style
70+
Err_Fore = Null_Fore
5771

5872
user_dir = dirname(realpath(os.path.curdir))
5973
toolchain_dir = dirname(__file__)
@@ -66,13 +80,13 @@ class LevelDifferentiatingFormatter(logging.Formatter):
6680
def format(self, record):
6781
if record.levelno > 20:
6882
record.msg = '{}{}[WARNING]{}{}: '.format(
69-
Style.BRIGHT, Fore.RED, Fore.RESET, Style.RESET_ALL) + record.msg
83+
Err_Style.BRIGHT, Err_Fore.RED, Err_Fore.RESET, Err_Style.RESET_ALL) + record.msg
7084
elif record.levelno > 10:
7185
record.msg = '{}[INFO]{}: '.format(
72-
Style.BRIGHT, Style.RESET_ALL) + record.msg
86+
Err_Style.BRIGHT, Err_Style.RESET_ALL) + record.msg
7387
else:
7488
record.msg = '{}{}[DEBUG]{}{}: '.format(
75-
Style.BRIGHT, Fore.LIGHTBLACK_EX, Fore.RESET, Style.RESET_ALL) + record.msg
89+
Err_Style.BRIGHT, Err_Fore.LIGHTBLACK_EX, Err_Fore.RESET, Err_Style.RESET_ALL) + record.msg
7690
return super(LevelDifferentiatingFormatter, self).format(record)
7791

7892
logger = logging.getLogger('p4a')
@@ -81,7 +95,7 @@ def format(self, record):
8195
# handler and reset the level
8296
logger.setLevel(logging.INFO)
8397
logger.touched = True
84-
ch = logging.StreamHandler(stdout) if sys.stdout.isatty() else logging.NullHandler()
98+
ch = logging.StreamHandler(stderr)
8599
formatter = LevelDifferentiatingFormatter('%(message)s')
86100
ch.setFormatter(formatter)
87101
logger.addHandler(ch)
@@ -92,20 +106,20 @@ def format(self, record):
92106

93107
IS_PY3 = sys.version_info[0] >= 3
94108

95-
info(''.join([Style.BRIGHT, Fore.RED,
109+
info(''.join([Err_Style.BRIGHT, Err_Fore.RED,
96110
'This python-for-android revamp is an experimental alpha release!',
97-
Style.RESET_ALL]))
98-
info(''.join([Fore.RED,
111+
Err_Style.RESET_ALL]))
112+
info(''.join([Err_Fore.RED,
99113
('It should work (mostly), but you may experience '
100114
'missing features or bugs.'),
101-
Style.RESET_ALL]))
115+
Err_Style.RESET_ALL]))
102116

103117
def info_main(*args):
104-
logger.info(''.join([Style.BRIGHT, Fore.GREEN] + list(args) +
105-
[Style.RESET_ALL, Fore.RESET]))
118+
logger.info(''.join([Err_Style.BRIGHT, Err_Fore.GREEN] + list(args) +
119+
[Err_Style.RESET_ALL, Err_Fore.RESET]))
106120

107121
def info_notify(s):
108-
info('{}{}{}{}'.format(Style.BRIGHT, Fore.LIGHTBLUE_EX, s, Style.RESET_ALL))
122+
info('{}{}{}{}'.format(Err_Style.BRIGHT, Err_Fore.LIGHTBLUE_EX, s, Err_Style.RESET_ALL))
109123

110124
def pretty_log_dists(dists, log_func=info):
111125
infos = []
@@ -114,7 +128,7 @@ def pretty_log_dists(dists, log_func=info):
114128
'includes recipes ({Fore.GREEN}{recipes}'
115129
'{Style.RESET_ALL})'.format(
116130
name=dist.name, recipes=', '.join(dist.recipes),
117-
Fore=Fore, Style=Style))
131+
Fore=Err_Fore, Style=Err_Style))
118132

119133
for line in infos:
120134
log_func('\t' + line)
@@ -151,9 +165,9 @@ def shprint(command, *args, **kwargs):
151165

152166
# If logging is not in DEBUG mode, trim the command if necessary
153167
if logger.level > logging.DEBUG:
154-
logger.info('{}{}'.format(shorten_string(string, columns - 12), Style.RESET_ALL))
168+
logger.info('{}{}'.format(shorten_string(string, columns - 12), Err_Style.RESET_ALL))
155169
else:
156-
logger.debug('{}{}'.format(string, Style.RESET_ALL))
170+
logger.debug('{}{}'.format(string, Err_Style.RESET_ALL))
157171

158172
need_closing_newline = False
159173
try:
@@ -165,7 +179,7 @@ def shprint(command, *args, **kwargs):
165179
msg = line.replace('\n', ' ').replace('\t', ' ').replace('\b', ' ').rstrip()
166180
if msg:
167181
# if len(msg) > msg_width: msg = msg[:(msg_width - 3)] + '...'
168-
sys.stdout.write('{}\r{}{:<{width}}'.format(Style.RESET_ALL, msg_hdr, shorten_string(msg, msg_width), width=msg_width))
182+
sys.stdout.write('{}\r{}{:<{width}}'.format(Err_Style.RESET_ALL, msg_hdr, shorten_string(msg, msg_width), width=msg_width))
169183
sys.stdout.flush()
170184
need_closing_newline = True
171185
else:
@@ -265,25 +279,25 @@ def is_exe(fpath):
265279
@contextlib.contextmanager
266280
def current_directory(new_dir):
267281
cur_dir = getcwd()
268-
logger.info(''.join((Fore.CYAN, '-> directory context ', new_dir,
269-
Fore.RESET)))
282+
logger.info(''.join((Err_Fore.CYAN, '-> directory context ', new_dir,
283+
Err_Fore.RESET)))
270284
chdir(new_dir)
271285
yield
272-
logger.info(''.join((Fore.CYAN, '<- directory context ', cur_dir,
273-
Fore.RESET)))
286+
logger.info(''.join((Err_Fore.CYAN, '<- directory context ', cur_dir,
287+
Err_Fore.RESET)))
274288
chdir(cur_dir)
275289

276290
@contextlib.contextmanager
277291
def temp_directory():
278292
temp_dir = mkdtemp()
279293
try:
280-
logger.debug(''.join((Fore.CYAN, ' + temp directory used ', temp_dir,
281-
Fore.RESET)))
294+
logger.debug(''.join((Err_Fore.CYAN, ' + temp directory used ', temp_dir,
295+
Err_Fore.RESET)))
282296
yield temp_dir
283297
finally:
284298
shutil.rmtree(temp_dir)
285-
logger.debug(''.join((Fore.CYAN, ' - temp directory deleted ', temp_dir,
286-
Fore.RESET)))
299+
logger.debug(''.join((Err_Fore.CYAN, ' - temp directory deleted ', temp_dir,
300+
Err_Fore.RESET)))
287301

288302

289303
def cache_execution(f):
@@ -2745,13 +2759,13 @@ def recipes(self, args):
27452759
print('{Fore.BLUE}{Style.BRIGHT}{recipe.name:<12} '
27462760
'{Style.RESET_ALL}{Fore.LIGHTBLUE_EX}'
27472761
'{version:<8}{Style.RESET_ALL}'.format(
2748-
recipe=recipe, Fore=Fore, Style=Style,
2762+
recipe=recipe, Fore=Out_Fore, Style=Out_Style,
27492763
version=version))
27502764
print(' {Fore.GREEN}depends: {recipe.depends}'
2751-
'{Fore.RESET}'.format(recipe=recipe, Fore=Fore))
2765+
'{Fore.RESET}'.format(recipe=recipe, Fore=Out_Fore))
27522766
if recipe.conflicts:
27532767
print(' {Fore.RED}conflicts: {recipe.conflicts}'
2754-
'{Fore.RESET}'.format(recipe=recipe, Fore=Fore))
2768+
'{Fore.RESET}'.format(recipe=recipe, Fore=Out_Fore))
27552769
else:
27562770
print("{recipe.name:<12} {recipe.version:<8}".format(
27572771
recipe=recipe))
@@ -2763,9 +2777,9 @@ def bootstraps(self, args):
27632777
for bs in Bootstrap.list_bootstraps():
27642778
bs = Bootstrap.get_bootstrap(bs, self.ctx)
27652779
print('{Fore.BLUE}{Style.BRIGHT}{bs.name}{Style.RESET_ALL}'.format(
2766-
bs=bs, Fore=Fore, Style=Style))
2780+
bs=bs, Fore=Out_Fore, Style=Out_Style))
27672781
print(' {Fore.GREEN}depends: {bs.recipe_depends}{Fore.RESET}'.format(
2768-
bs=bs, Fore=Fore))
2782+
bs=bs, Fore=Out_Fore))
27692783

27702784
def clean_all(self, args):
27712785
'''Delete all build components; the package cache, package builds,
@@ -2991,11 +3005,11 @@ def distributions(self, args):
29913005

29923006
if dists:
29933007
print('{Style.BRIGHT}Distributions currently installed are:'
2994-
'{Style.RESET_ALL}'.format(Style=Style, Fore=Fore))
3008+
'{Style.RESET_ALL}'.format(Style=Out_Style, Fore=Out_Fore))
29953009
pretty_log_dists(dists, print)
29963010
else:
29973011
print('{Style.BRIGHT}There are no dists currently built.'
2998-
'{Style.RESET_ALL}'.format(Style=Style))
3012+
'{Style.RESET_ALL}'.format(Style=Out_Style))
29993013

30003014
def delete_dist(self, args):
30013015
dist = self._dist
@@ -3054,24 +3068,24 @@ def logcat(self, args):
30543068
def build_status(self, args):
30553069

30563070
print('{Style.BRIGHT}Bootstraps whose core components are probably already built:'
3057-
'{Style.RESET_ALL}'.format(Style=Style))
3071+
'{Style.RESET_ALL}'.format(Style=Out_Style))
30583072
for filen in os.listdir(join(self.ctx.build_dir, 'bootstrap_builds')):
30593073
print(' {Fore.GREEN}{Style.BRIGHT}{filen}{Style.RESET_ALL}'.format(
3060-
filen=filen, Fore=Fore, Style=Style))
3074+
filen=filen, Fore=Out_Fore, Style=Out_Style))
30613075

30623076
print('{Style.BRIGHT}Recipes that are probably already built:'
3063-
'{Style.RESET_ALL}'.format(Style=Style))
3077+
'{Style.RESET_ALL}'.format(Style=Out_Style))
30643078
if exists(join(self.ctx.build_dir, 'other_builds')):
30653079
for filen in sorted(os.listdir(join(self.ctx.build_dir, 'other_builds'))):
30663080
name = filen.split('-')[0]
30673081
dependencies = filen.split('-')[1:]
30683082
recipe_str = (' {Style.BRIGHT}{Fore.GREEN}{name}'
30693083
'{Style.RESET_ALL}'.format(
3070-
Style=Style, name=name, Fore=Fore))
3084+
Style=Out_Style, name=name, Fore=Out_Fore))
30713085
if dependencies:
30723086
recipe_str += (' ({Fore.BLUE}with ' + ', '.join(dependencies) +
3073-
'{Fore.RESET})').format(Fore=Fore)
3074-
recipe_str += '{Style.RESET_ALL}'.format(Style=Style)
3087+
'{Fore.RESET})').format(Fore=Out_Fore)
3088+
recipe_str += '{Style.RESET_ALL}'.format(Style=Out_Style)
30753089
print(recipe_str)
30763090

30773091

0 commit comments

Comments
 (0)