Skip to content

Commit 189056e

Browse files
committed
Some pep8 fixes
1 parent a03f664 commit 189056e

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

pythonforandroid/toolchain.py

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import json
2121
import glob
2222
import shutil
23-
import fnmatch
2423
import re
24+
import imp
25+
import contextlib
26+
import logging
2527
from functools import wraps
2628
from datetime import datetime
2729
from distutils.spawn import find_executable
@@ -31,24 +33,18 @@
3133
from urllib import FancyURLopener
3234

3335
import argparse
34-
3536
from appdirs import user_data_dir
37+
import sh
38+
from colorama import Style, Fore
3639

3740
curdir = dirname(__file__)
3841
sys.path.insert(0, join(curdir, "tools", "external"))
3942

40-
import sh
41-
import logging
42-
import contextlib
43-
import imp
44-
45-
from colorama import Style, Fore
4643

4744
DEFAULT_ANDROID_API = 14
4845

4946

5047
logger = logging.getLogger('p4a')
51-
# logger.setLevel(logging.DEBUG)
5248
if not hasattr(logger, 'touched'): # Necessary as importlib reloads
5349
# this, which would add a second
5450
# handler and reset the level
@@ -59,33 +55,40 @@
5955
Style.BRIGHT, Style.RESET_ALL))
6056
ch.setFormatter(formatter)
6157
logger.addHandler(ch)
62-
# logger.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
6358
info = logger.info
6459
debug = logger.debug
6560
warning = logger.warning
6661

6762

6863
IS_PY3 = sys.version_info[0] >= 3
6964

70-
info(Style.BRIGHT + Fore.RED + 'This python-for-android revamp is an experimental alpha release!' + Style.RESET_ALL)
71-
info(Fore.RED + 'It should work (mostly), but you may experience missing features or bugs.' + Style.RESET_ALL)
72-
info(Fore.RED + 'See http://inclem.net/files/p4a_revamp_doc/index.html for the current (WIP) documentation.' + Style.RESET_ALL)
65+
info(''.join([Style.BRIGHT, Fore.RED,
66+
'This python-for-android revamp is an experimental alpha release!',
67+
Style.RESET_ALL]))
68+
info(''.join([Fore.RED,
69+
('It should work (mostly), but you may experience '
70+
'missing features or bugs.'),
71+
Style.RESET_ALL]))
72+
info(''.join([Fore.RED,
73+
('See http://inclem.net/files/p4a_revamp_doc/index.html '
74+
'for the current (WIP) documentation.'),
75+
Style.RESET_ALL]))
7376

7477

7578
def info_main(*args):
7679
logger.info(''.join([Style.BRIGHT, Fore.GREEN] + list(args) +
7780
[Style.RESET_ALL, Fore.RESET]))
7881

7982
def shprint(command, *args, **kwargs):
83+
'''Runs the command (which should be an sh.Command instance), while
84+
logging the output.'''
8085
kwargs["_iter"] = True
8186
kwargs["_out_bufsize"] = 1
8287
kwargs["_err_to_out"] = True
8388
if len(logger.handlers) > 1:
8489
logger.removeHandler(logger.handlers[1])
8590
command_path = str(command).split('/')
8691
command_string = command_path[-1]
87-
# if len(command_path) > 1:
88-
# command_string = '.../' + command_string
8992
string = ' '.join(['running', command_string] + list(args))
9093

9194
# If logging is not in DEBUG mode, trim the command if necessary
@@ -96,7 +99,7 @@ def shprint(command, *args, **kwargs):
9699
logger.info(short_string + Style.RESET_ALL)
97100
else:
98101
logger.debug(string + Style.RESET_ALL)
99-
102+
100103
output = command(*args, **kwargs)
101104
need_closing_newline = False
102105
for line in output:
@@ -144,6 +147,8 @@ def wrapper_func(self, args):
144147

145148

146149
def get_directory(filename):
150+
'''If the filename ends with a recognised file extension, return the
151+
filename without this extension.'''
147152
if filename.endswith('.tar.gz'):
148153
return basename(filename[:-7])
149154
elif filename.endswith('.tgz'):
@@ -158,6 +163,7 @@ def get_directory(filename):
158163
exit(1)
159164

160165
def which(program, path_env):
166+
'''Locate an executable in the system.'''
161167
import os
162168
def is_exe(fpath):
163169
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
@@ -432,25 +438,22 @@ def find_order(self):
432438
class Context(object):
433439
'''A build context. If anything will be built, an instance this class
434440
will be instantiated and used to hold all the build state.'''
435-
441+
436442
env = environ.copy()
437443
root_dir = None # the filepath of toolchain.py
438444
storage_dir = None # the root dir where builds and dists will be stored
439445
build_dir = None # in which bootstraps are copied for building and recipes are built
440446
dist_dir = None # the Android project folder where everything ends up
441-
libs_dir = None
447+
libs_dir = None # where Android libs are cached after build but
448+
# before being placed in dists
442449
javaclass_dir = None
443450
ccache = None # whether to use ccache
444451
cython = None # the cython interpreter name
445452

446-
sdk_dir = None # the directory of the android sdk
447-
ndk_dir = None # the directory of the android ndk
448453
ndk_platform = None # the ndk platform directory
449-
ndk_ver = None # the ndk version, defaults to r9
450-
android_api = None # the android api target, defaults to 14
451-
452-
dist_name = None
453-
bootstrap = None
454+
455+
dist_name = None # should be deprecated in favour of self.dist.dist_name
456+
bootstrap = None
454457
bootstrap_build_dir = None
455458

456459
recipe_build_order = None # Will hold the list of all built recipes
@@ -485,6 +488,7 @@ def setup_dirs(self):
485488

486489
@property
487490
def android_api(self):
491+
'''The Android API being targeted.'''
488492
if self._android_api is None:
489493
raise ValueError('Tried to access android_api but it has not '
490494
'been set - this should not happen, something '
@@ -497,6 +501,7 @@ def android_api(self, value):
497501

498502
@property
499503
def ndk_ver(self):
504+
'''The version of the NDK being used for compilation.'''
500505
if self._ndk_ver is None:
501506
raise ValueError('Tried to access android_api but it has not '
502507
'been set - this should not happen, something '
@@ -509,6 +514,7 @@ def ndk_ver(self, value):
509514

510515
@property
511516
def sdk_dir(self):
517+
'''The path to the Android SDK.'''
512518
if self._sdk_dir is None:
513519
raise ValueError('Tried to access android_api but it has not '
514520
'been set - this should not happen, something '
@@ -521,6 +527,7 @@ def sdk_dir(self, value):
521527

522528
@property
523529
def ndk_dir(self):
530+
'''The path to the Android NDK.'''
524531
if self._ndk_dir is None:
525532
raise ValueError('Tried to access android_api but it has not '
526533
'been set - this should not happen, something '
@@ -537,11 +544,14 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
537544
for the Android SDK etc.
538545
539546
..warning:: This *must* be called before trying any build stuff
547+
540548
'''
541549

542550
if self._build_env_prepared:
543551
return
544552

553+
# AND: This needs revamping to carefully check each dependency
554+
# in turn
545555
ok = True
546556

547557
# Work out where the Android SDK is
@@ -579,12 +589,14 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
579589
apis = [s for s in targets if re.match(r'^ *API level: ', s)]
580590
apis = [re.findall(r'[0-9]+', s) for s in apis]
581591
apis = [int(s[0]) for s in apis if s]
582-
info('Available Android APIs are ({})'.format(', '.join(map(str, apis))))
592+
info('Available Android APIs are ({})'.format(
593+
', '.join(map(str, apis))))
583594
if android_api in apis:
584-
info('Requested API target {} is available, continuing.'.format(android_api))
595+
info(('Requested API target {} is available, '
596+
'continuing.').format(android_api))
585597
else:
586-
warning('Requested API target {} is not available, install '
587-
'it with the SDK android tool.'.format(android_api))
598+
warning(('Requested API target {} is not available, install '
599+
'it with the SDK android tool.').format(android_api))
588600
warning('Exiting.')
589601
exit(1)
590602
# AND: If the android api target doesn't exist, we should
@@ -636,7 +648,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
636648
else:
637649
if ndk_ver is None:
638650
ndk_ver = reported_ndk_ver
639-
info('Got Android NDK version from the NDK dir: it is {}'.format(ndk_ver))
651+
info(('Got Android NDK version from the NDK dir: '
652+
'it is {}').format(ndk_ver))
640653
else:
641654
if ndk_ver != reported_ndk_ver:
642655
warning('NDK version was set as {}, but checking '
@@ -677,7 +690,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
677690
# path to some tools
678691
self.ccache = sh.which("ccache")
679692
if not self.ccache:
680-
info("ccache is missing, the build will not be optimized in the future.")
693+
info('ccache is missing, the build will not be optimized in the '
694+
'future.')
681695
for cython_fn in ("cython2", "cython-2.7", "cython"):
682696
cython = sh.which(cython_fn)
683697
if cython:

0 commit comments

Comments
 (0)