Skip to content

Commit ce48650

Browse files
committed
Merge pull request kivy#224 from inclement/pep8
Pep8 fixes for build.py
2 parents a5b9435 + ccc4ef4 commit ce48650

File tree

1 file changed

+113
-53
lines changed

1 file changed

+113
-53
lines changed

src/build.py

Lines changed: 113 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ANDROID = 'android'
2323
ANT = 'ant'
2424

25-
#if ANDROIDSDK is on path, use android from this path
25+
# if ANDROIDSDK is on path, use android from this path
2626
ANDROIDSDK = os.environ.get('ANDROIDSDK')
2727
if ANDROIDSDK:
2828
ANDROID = os.path.join(ANDROIDSDK, 'tools', ANDROID)
@@ -60,9 +60,9 @@
6060

6161

6262
def render(template, dest, **kwargs):
63-
'''
64-
Using jinja2, render `template` to the filename `dest`, supplying the keyword
65-
arguments as template parameters.
63+
'''Using jinja2, render `template` to the filename `dest`, supplying the
64+
65+
keyword arguments as template parameters.
6666
'''
6767

6868
template = environment.get_template(template)
@@ -85,11 +85,13 @@ def compile_dir(dfn):
8585
def is_whitelist(name):
8686
return match_filename(WHITELIST_PATTERNS, name)
8787

88+
8889
def is_blacklist(name):
8990
if is_whitelist(name):
90-
return False
91+
return False
9192
return match_filename(BLACKLIST_PATTERNS, name)
9293

94+
9395
def match_filename(pattern_list, name):
9496
for pattern in pattern_list:
9597
if pattern.startswith('^'):
@@ -131,11 +133,11 @@ def select(fn):
131133
fn = realpath(fn)
132134
assert(fn.startswith(d))
133135
fn = fn[len(d):]
134-
if fn.startswith('/site-packages/') or \
135-
fn.startswith('/config/') or \
136-
fn.startswith('/lib-dynload/') or \
137-
fn.startswith('/libpymodules.so'):
138-
return False
136+
if (fn.startswith('/site-packages/') or
137+
fn.startswith('/config/') or
138+
fn.startswith('/lib-dynload/') or
139+
fn.startswith('/libpymodules.so')):
140+
return False
139141
return fn
140142

141143
# get a list of all python file
@@ -174,7 +176,8 @@ def select(fn):
174176
for sd in source_dirs:
175177
sd = realpath(sd)
176178
compile_dir(sd)
177-
files += [(x, relpath(realpath(x), sd)) for x in listfiles(sd) if select(x)]
179+
files += [(x, relpath(realpath(x), sd)) for x in listfiles(sd)
180+
if select(x)]
178181

179182
# create tar.gz of thoses files
180183
tf = tarfile.open(tfn, 'w:gz')
@@ -220,9 +223,11 @@ def make_package(args):
220223
if args.icon_name:
221224
args.icon_name = args.icon_name.decode('utf-8')
222225

223-
versioned_name = args.name.replace(' ', '').replace('\'', '') + '-' + args.version
226+
versioned_name = (args.name.replace(' ', '').replace('\'', '') +
227+
'-' + args.version)
224228

225-
# Android SDK rev14 needs two ant execs (ex: debug installd) and new build.xml
229+
# Android SDK rev14 needs two ant execs (ex: debug installd) and
230+
# new build.xml
226231
build_tpl = 'build.xml'
227232

228233
if not args.icon_name:
@@ -257,7 +262,8 @@ def make_package(args):
257262
if args.ouya_category:
258263
args.ouya_category = args.ouya_category.upper()
259264
if args.ouya_category not in ('GAME', 'APP'):
260-
print 'Invalid --ouya-category argument. should be one of GAME or APP'
265+
print('Invalid --ouya-category argument. should be one of'
266+
'GAME or APP')
261267
sys.exit(-1)
262268

263269
# Get target android API
@@ -296,7 +302,7 @@ def make_package(args):
296302
# Update the project to a recent version.
297303
try:
298304
subprocess.call([ANDROID, 'update', 'project', '-p', '.', '-t',
299-
'android-{}'.format(android_api)])
305+
'android-{}'.format(android_api)])
300306
except (OSError, IOError):
301307
print 'An error occured while calling', ANDROID, 'update'
302308
print 'Your PATH must include android tools.'
@@ -324,13 +330,15 @@ def make_package(args):
324330

325331
# Copy over the icon and presplash files.
326332
shutil.copy(args.icon or default_icon, 'res/drawable/icon.png')
327-
shutil.copy(args.presplash or default_presplash, 'res/drawable/presplash.jpg')
333+
shutil.copy(args.presplash or default_presplash,
334+
'res/drawable/presplash.jpg')
328335

329336
# If OUYA support was requested, copy over the OUYA icon
330337
if args.ouya_category:
331338
if not os.path.isdir('res/drawable-xhdpi'):
332339
os.mkdir('res/drawable-xhdpi')
333-
shutil.copy(args.ouya_icon or default_ouya_icon, 'res/drawable-xhdpi/ouya_icon.png')
340+
shutil.copy(args.ouya_icon or default_ouya_icon,
341+
'res/drawable-xhdpi/ouya_icon.png')
334342

335343
# If extra Java jars were requested, copy them into the libs directory
336344
if args.add_jar:
@@ -359,43 +367,94 @@ def make_package(args):
359367
tools directory of the Android SDK.
360368
''')
361369

362-
ap.add_argument('--package', dest='package', help='The name of the java package the project will be packaged under.', required=True)
363-
ap.add_argument('--name', dest='name', help='The human-readable name of the project.', required=True)
364-
ap.add_argument('--version', dest='version', help='The version number of the project. This should consist of numbers and dots, and should have the same number of groups of numbers as previous versions.', required=True)
365-
ap.add_argument('--numeric-version', dest='numeric_version', help='The numeric version number of the project. If not given, this is automatically computed from the version.')
366-
ap.add_argument('--dir', dest='dir', help='The directory containing public files for the project.')
367-
ap.add_argument('--private', dest='private', help='The directory containing additional private files for the project.')
370+
ap.add_argument('--package', dest='package',
371+
help=('The name of the java package the project will be'
372+
' packaged under.'),
373+
required=True)
374+
ap.add_argument('--name', dest='name',
375+
help=('The human-readable name of the project.'),
376+
required=True)
377+
ap.add_argument('--version', dest='version',
378+
help=('The version number of the project. This should '
379+
'consist of numbers and dots, and should have the '
380+
'same number of groups of numbers as previous '
381+
'versions.'),
382+
required=True)
383+
ap.add_argument('--numeric-version', dest='numeric_version',
384+
help=('The numeric version number of the project. If not '
385+
'given, this is automatically computed from the '
386+
'version.'))
387+
ap.add_argument('--dir', dest='dir',
388+
help=('The directory containing public files for the '
389+
'project.'))
390+
ap.add_argument('--private', dest='private',
391+
help=('The directory containing additional private files '
392+
'for the project.'))
368393
ap.add_argument('--launcher', dest='launcher', action='store_true',
369-
help='Provide this argument to build a multi-app launcher, rather than a single app.')
370-
ap.add_argument('--icon-name', dest='icon_name', help='The name of the project\'s launcher icon.')
394+
help=('Provide this argument to build a multi-app '
395+
'launcher, rather than a single app.'))
396+
ap.add_argument('--icon-name', dest='icon_name',
397+
help='The name of the project\'s launcher icon.')
371398
ap.add_argument('--orientation', dest='orientation', default='landscape',
372-
help='The orientation that the game will display in. Usually one of "landscape", "portrait" or "sensor"')
373-
ap.add_argument('--permission', dest='permissions', action='append', help='The permissions to give this app.')
374-
ap.add_argument('--ignore-path', dest='ignore_path', action='append', help='Ignore path when building the app')
375-
ap.add_argument('--icon', dest='icon', help='A png file to use as the icon for the application.')
376-
ap.add_argument('--presplash', dest='presplash', help='A jpeg file to use as a screen while the application is loading.')
377-
ap.add_argument('--ouya-category', dest='ouya_category', help='Valid values are GAME and APP. This must be specified to enable OUYA console support.')
378-
ap.add_argument('--ouya-icon', dest='ouya_icon', help='A png file to use as the icon for the application if it is installed on an OUYA console.')
379-
ap.add_argument('--install-location', dest='install_location', default='auto', help='The default install location. Should be "auto", "preferExternal" or "internalOnly".')
380-
ap.add_argument('--compile-pyo', dest='compile_pyo', action='store_true', help='Compile all .py files to .pyo, and only distribute the compiled bytecode.')
381-
ap.add_argument('--intent-filters', dest='intent_filters', help='Add intent-filters xml rules to the AndroidManifest.xml file. The argument is a filename containing xml. The filename should be located relative to the python-for-android directory')
382-
ap.add_argument('--with-billing', dest='billing_pubkey', help='If set, the billing service will be added')
399+
help=('The orientation that the game will display in. '
400+
'Usually one of "landscape", "portrait" or '
401+
'"sensor"'))
402+
ap.add_argument('--permission', dest='permissions', action='append',
403+
help='The permissions to give this app.')
404+
ap.add_argument('--ignore-path', dest='ignore_path', action='append',
405+
help='Ignore path when building the app')
406+
ap.add_argument('--icon', dest='icon',
407+
help='A png file to use as the icon for the application.')
408+
ap.add_argument('--presplash', dest='presplash',
409+
help=('A jpeg file to use as a screen while the '
410+
'application is loading.'))
411+
ap.add_argument('--ouya-category', dest='ouya_category',
412+
help=('Valid values are GAME and APP. This must be '
413+
'specified to enable OUYA console support.'))
414+
ap.add_argument('--ouya-icon', dest='ouya_icon',
415+
help=('A png file to use as the icon for the application '
416+
'if it is installed on an OUYA console.'))
417+
ap.add_argument('--install-location', dest='install_location',
418+
default='auto',
419+
help=('The default install location. Should be "auto", '
420+
'"preferExternal" or "internalOnly".'))
421+
ap.add_argument('--compile-pyo', dest='compile_pyo', action='store_true',
422+
help=('Compile all .py files to .pyo, and only distribute '
423+
'the compiled bytecode.'))
424+
ap.add_argument('--intent-filters', dest='intent_filters',
425+
help=('Add intent-filters xml rules to the '
426+
'AndroidManifest.xml file. The argument is a '
427+
'filename containing xml. The filename should be '
428+
'located relative to the python-for-android '
429+
'directory'))
430+
ap.add_argument('--with-billing', dest='billing_pubkey',
431+
help='If set, the billing service will be added')
383432
ap.add_argument('--blacklist', dest='blacklist',
384-
default=join(curdir, 'blacklist.txt'),
385-
help='Use a blacklist file to match unwanted file in the final APK')
433+
default=join(curdir, 'blacklist.txt'),
434+
help=('Use a blacklist file to match unwanted file in '
435+
'the final APK'))
386436
ap.add_argument('--whitelist', dest='whitelist',
387-
default=join(curdir, 'whitelist.txt'),
388-
help='Use a whitelist file to prevent blacklisting of file in the final APK')
389-
ap.add_argument('--sdk', dest='sdk_version', default='8', help='Android SDK version to use. Default to 8')
390-
ap.add_argument('--minsdk', dest='min_sdk_version', default='8', help='Minimum Android SDK version to use. Default to 8')
437+
default=join(curdir, 'whitelist.txt'),
438+
help=('Use a whitelist file to prevent blacklisting of '
439+
'file in the final APK'))
440+
ap.add_argument('--sdk', dest='sdk_version', default='8',
441+
help='Android SDK version to use. Default to 8')
442+
ap.add_argument('--minsdk', dest='min_sdk_version', default='8',
443+
help='Minimum Android SDK version to use. Default to 8')
391444
ap.add_argument('--window', dest='window', action='store_true',
392-
help='Indicate if the application will be windowed')
445+
help='Indicate if the application will be windowed')
393446
ap.add_argument('--wakelock', dest='wakelock', action='store_true',
394-
help='Indicate if the application needs the device to stay on')
395-
ap.add_argument('command', nargs='*', help='The command to pass to ant (debug, release, installd, installr)')
396-
ap.add_argument('--add-jar', dest='add_jar', action='append', help='Add a Java .jar to the libs, so you can access its classes with pyjnius. You can specify this argument more than once to include multiple jars')
447+
help=('Indicate if the application needs the device '
448+
'to stay on'))
449+
ap.add_argument('command', nargs='*',
450+
help=('The command to pass to ant (debug, release, '
451+
'installd, installr)'))
452+
ap.add_argument('--add-jar', dest='add_jar', action='append',
453+
help=('Add a Java .jar to the libs, so you can access its '
454+
'classes with pyjnius. You can specify this '
455+
'argument more than once to include multiple jars'))
397456
ap.add_argument('--meta-data', dest='meta_data', action='append',
398-
help='Custom key=value to add in application metadata')
457+
help='Custom key=value to add in application metadata')
399458

400459
args = ap.parse_args()
401460

@@ -413,19 +472,20 @@ def make_package(args):
413472

414473
if args.compile_pyo:
415474
if PYTHON is None:
416-
ap.error('To use --compile-pyo, you need Python 2.7.1 installed and in your PATH.')
475+
ap.error('To use --compile-pyo, you need Python 2.7.1 installed '
476+
'and in your PATH.')
417477
BLACKLIST_PATTERNS += ['*.py', '*.pyc']
418478

419479
if args.blacklist:
420480
with open(args.blacklist) as fd:
421-
patterns = [x.strip() for x in fd.read().splitlines() if x.strip() and not
422-
x.startswith('#')]
481+
patterns = [x.strip() for x in fd.read().splitlines() if x.strip()
482+
and not x.startswith('#')]
423483
BLACKLIST_PATTERNS += patterns
424-
484+
425485
if args.whitelist:
426486
with open(args.whitelist) as fd:
427-
patterns = [x.strip() for x in fd.read().splitlines() if x.strip() and not
428-
x.startswith('#')]
487+
patterns = [x.strip() for x in fd.read().splitlines() if x.strip()
488+
and not x.startswith('#')]
429489
WHITELIST_PATTERNS += patterns
430490

431491
make_package(args)

0 commit comments

Comments
 (0)