Skip to content

Commit f2b621e

Browse files
authored
Merge pull request kivy#2115 from AndreMiras/feature/minor_fixes
Minor fixes and cleanup
2 parents a548330 + 22b7dfe commit f2b621e

File tree

15 files changed

+58
-126
lines changed

15 files changed

+58
-126
lines changed

pythonforandroid/archs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pythonforandroid.util import BuildInterruptingException, build_platform
99

1010

11-
class Arch(object):
11+
class Arch:
1212

1313
toolchain_prefix = None
1414
'''The prefix for the toolchain dir in the NDK.'''
@@ -46,7 +46,6 @@ class Arch(object):
4646
]
4747

4848
def __init__(self, ctx):
49-
super().__init__()
5049
self.ctx = ctx
5150

5251
# Allows injecting additional linker paths used by any recipe.

pythonforandroid/bdistapk.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
from setuptools import Command
32

43
import sys

pythonforandroid/bootstrap.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def rank_bootstrap(bootstrap):
6363
return 1
6464

6565

66-
class Bootstrap(object):
66+
class Bootstrap:
6767
'''An Android project template, containing recipe stuff for
6868
compilation and templated fields for APK info.
6969
'''
@@ -294,15 +294,15 @@ def distribute_libs(self, arch, src_dirs, wildcard='*', dest_dir="libs"):
294294
tgt_dir = join(dest_dir, arch.arch)
295295
ensure_dir(tgt_dir)
296296
for src_dir in src_dirs:
297-
for lib in glob.glob(join(src_dir, wildcard)):
298-
shprint(sh.cp, '-a', lib, tgt_dir)
297+
libs = glob.glob(join(src_dir, wildcard))
298+
shprint(sh.cp, '-a', *libs, tgt_dir)
299299

300300
def distribute_javaclasses(self, javaclass_dir, dest_dir="src"):
301301
'''Copy existing javaclasses from build dir to current dist dir.'''
302302
info('Copying java files')
303303
ensure_dir(dest_dir)
304-
for filename in glob.glob(javaclass_dir):
305-
shprint(sh.cp, '-a', filename, dest_dir)
304+
filenames = glob.glob(javaclass_dir)
305+
shprint(sh.cp, '-a', *filenames, dest_dir)
306306

307307
def distribute_aars(self, arch):
308308
'''Process existing .aar bundles and copy to current dist dir.'''
@@ -335,8 +335,7 @@ def _unpack_aar(self, aar, arch):
335335
debug(" to {}".format(so_tgt_dir))
336336
ensure_dir(so_tgt_dir)
337337
so_files = glob.glob(join(so_src_dir, '*.so'))
338-
for f in so_files:
339-
shprint(sh.cp, '-a', f, so_tgt_dir)
338+
shprint(sh.cp, '-a', *so_files, so_tgt_dir)
340339

341340
def strip_libraries(self, arch):
342341
info('Stripping libraries')

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python3
22

3-
from __future__ import print_function
4-
53
import json
64
from os.path import (
75
dirname, join, isfile, realpath,

pythonforandroid/build.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
from os.path import (
42
abspath, join, realpath, dirname, expanduser, exists,
53
split, isdir
@@ -79,7 +77,7 @@ def get_available_apis(sdk_dir):
7977
return apis
8078

8179

82-
class Context(object):
80+
class Context:
8381
'''A build context. If anything will be built, an instance this class
8482
will be instantiated and used to hold all the build state.'''
8583

@@ -132,34 +130,33 @@ def templates_dir(self):
132130
@property
133131
def libs_dir(self):
134132
# Was previously hardcoded as self.build_dir/libs
135-
dir = join(self.build_dir, 'libs_collections',
136-
self.bootstrap.distribution.name)
137-
ensure_dir(dir)
138-
return dir
133+
directory = join(self.build_dir, 'libs_collections',
134+
self.bootstrap.distribution.name)
135+
ensure_dir(directory)
136+
return directory
139137

140138
@property
141139
def javaclass_dir(self):
142140
# Was previously hardcoded as self.build_dir/java
143-
dir = join(self.build_dir, 'javaclasses',
144-
self.bootstrap.distribution.name)
145-
ensure_dir(dir)
146-
return dir
141+
directory = join(self.build_dir, 'javaclasses',
142+
self.bootstrap.distribution.name)
143+
ensure_dir(directory)
144+
return directory
147145

148146
@property
149147
def aars_dir(self):
150-
dir = join(self.build_dir, 'aars', self.bootstrap.distribution.name)
151-
ensure_dir(dir)
152-
return dir
148+
directory = join(self.build_dir, 'aars', self.bootstrap.distribution.name)
149+
ensure_dir(directory)
150+
return directory
153151

154152
@property
155153
def python_installs_dir(self):
156-
dir = join(self.build_dir, 'python-installs')
157-
ensure_dir(dir)
158-
return dir
154+
directory = join(self.build_dir, 'python-installs')
155+
ensure_dir(directory)
156+
return directory
159157

160158
def get_python_install_dir(self):
161-
dir = join(self.python_installs_dir, self.bootstrap.distribution.name)
162-
return dir
159+
return join(self.python_installs_dir, self.bootstrap.distribution.name)
163160

164161
def setup_dirs(self, storage_dir):
165162
'''Calculates all the storage and build dirs, and makes sure
@@ -264,7 +261,7 @@ def prepare_build_environment(self,
264261
possible_dirs = glob.glob(expanduser(join(
265262
'~', '.buildozer', 'android', 'platform', 'android-sdk-*')))
266263
possible_dirs = [d for d in possible_dirs if not
267-
(d.endswith('.bz2') or d.endswith('.gz'))]
264+
d.endswith(('.bz2', '.gz'))]
268265
if possible_dirs:
269266
info('Found possible SDK dirs in buildozer dir: {}'.format(
270267
', '.join([d.split(os.sep)[-1] for d in possible_dirs])))
@@ -427,15 +424,13 @@ def prepare_build_environment(self,
427424
for executable in ("pkg-config", "autoconf", "automake", "libtoolize",
428425
"tar", "bzip2", "unzip", "make", "gcc", "g++"):
429426
if not sh.which(executable):
430-
warning("Missing executable: {} is not installed".format(
431-
executable))
427+
warning(f"Missing executable: {executable} is not installed")
432428

433429
if not ok:
434430
raise BuildInterruptingException(
435431
'python-for-android cannot continue due to the missing executables above')
436432

437433
def __init__(self):
438-
super().__init__()
439434
self.include_dirs = []
440435

441436
self._build_env_prepared = False
@@ -605,23 +600,16 @@ def build_recipes(build_order, python_modules, ctx, project_dir,
605600
ignore_setup_py=ignore_project_setup_py
606601
)
607602

608-
return
609-
610603

611604
def project_has_setup_py(project_dir):
612-
if project_dir is not None and \
613-
(os.path.exists(os.path.join(project_dir,
614-
"setup.py")) or
615-
os.path.exists(os.path.join(project_dir,
616-
"pyproject.toml"))
617-
):
618-
return True
619-
return False
605+
return (project_dir is not None and
606+
(exists(join(project_dir, "setup.py")) or
607+
exists(join(project_dir, "pyproject.toml"))
608+
))
620609

621610

622611
def run_setuppy_install(ctx, project_dir, env=None):
623-
if env is None:
624-
env = dict()
612+
env = env or {}
625613

626614
with current_directory(project_dir):
627615
info('got setup.py or similar, running project install. ' +
@@ -1076,5 +1064,4 @@ def copylibs_function(soname, objs_paths, extra_link_dirs=[], env=None):
10761064
'\n\t'.join(needed_libs))
10771065

10781066
print('Copying libraries')
1079-
for lib in sofiles:
1080-
shprint(sh.cp, lib, dest)
1067+
shprint(sh.cp, *sofiles, dest)

pythonforandroid/distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from shutil import rmtree
88

99

10-
class Distribution(object):
10+
class Distribution:
1111
'''State container for information about a distribution (i.e. an
1212
Android project).
1313

pythonforandroid/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def obvious_conflict_checker(ctx, name_tuples, blacklist=None):
160160
current_to_be_added = list(to_be_added)
161161
to_be_added = []
162162
for (added_tuple, adding_recipe) in current_to_be_added:
163-
assert(type(added_tuple) == tuple)
163+
assert type(added_tuple) == tuple
164164
if len(added_tuple) > 1:
165165
# No obvious commitment in what to add, don't check it itself
166166
# but throw it into deps for later comparing against

pythonforandroid/logger.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77
from collections import defaultdict
88
from colorama import Style as Colo_Style, Fore as Colo_Fore
99

10-
# six import left for Python 2 compatibility during initial Python version check
11-
import six
12-
13-
# This codecs change fixes a bug with log output, but crashes under python3
14-
if not six.PY3:
15-
import codecs
16-
stdout = codecs.getwriter('utf8')(stdout)
17-
stderr = codecs.getwriter('utf8')(stderr)
18-
19-
if six.PY2:
20-
unistr = unicode # noqa F821
21-
else:
22-
unistr = str
2310

2411
# monkey patch to show full output
2512
sh.ErrorReturnCode.truncate_cap = 999999
@@ -61,7 +48,7 @@ def format(self, record):
6148
error = logger.error
6249

6350

64-
class colorama_shim(object):
51+
class colorama_shim:
6552

6653
def __init__(self, real):
6754
self._dict = defaultdict(str)
@@ -114,12 +101,12 @@ def shorten_string(string, max_width):
114101
return string
115102
visible = max_width - 16 - int(log10(string_len))
116103
# expected suffix len "...(and XXXXX more)"
117-
if not isinstance(string, unistr):
118-
visstring = unistr(string[:visible], errors='ignore')
104+
if not isinstance(string, str):
105+
visstring = str(string[:visible], errors='ignore')
119106
else:
120107
visstring = string[:visible]
121108
return u''.join((visstring, u'...(and ',
122-
unistr(string_len - visible), u' more)'))
109+
str(string_len - visible), u' more)'))
123110

124111

125112
def get_console_width():

pythonforandroid/recipe.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split
22
import glob
33
from shutil import rmtree
4-
from six import PY2, with_metaclass
4+
from six import with_metaclass
55

66
import hashlib
77
from re import match
@@ -22,26 +22,17 @@
2222

2323

2424
def import_recipe(module, filename):
25-
if PY2:
26-
import imp
27-
import warnings
28-
with warnings.catch_warnings():
29-
# ignores warnings raised by hierarchical module names
30-
# (names containing dots) on Python 2
31-
warnings.simplefilter("ignore", RuntimeWarning)
32-
return imp.load_source(module, filename)
25+
# Python 3.5+
26+
import importlib.util
27+
if hasattr(importlib.util, 'module_from_spec'):
28+
spec = importlib.util.spec_from_file_location(module, filename)
29+
mod = importlib.util.module_from_spec(spec)
30+
spec.loader.exec_module(mod)
31+
return mod
3332
else:
34-
# Python 3.5+
35-
import importlib.util
36-
if hasattr(importlib.util, 'module_from_spec'):
37-
spec = importlib.util.spec_from_file_location(module, filename)
38-
mod = importlib.util.module_from_spec(spec)
39-
spec.loader.exec_module(mod)
40-
return mod
41-
else:
42-
# Python 3.3 and 3.4:
43-
from importlib.machinery import SourceFileLoader
44-
return SourceFileLoader(module, filename).load_module()
33+
# Python 3.3 and 3.4:
34+
from importlib.machinery import SourceFileLoader
35+
return SourceFileLoader(module, filename).load_module()
4536

4637

4738
class RecipeMeta(type):

pythonforandroid/recipes/android/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour
32
from pythonforandroid.util import current_directory
43
from pythonforandroid import logger

pythonforandroid/toolchain.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
This module defines the entry point for command line and programmatic use.
77
"""
88

9-
from __future__ import print_function
109
from os import environ
1110
from pythonforandroid import __version__
1211
from pythonforandroid.pythonpackage import get_dep_names_of_package
@@ -235,7 +234,7 @@ def _get_option_tuples(self, option_string):
235234
return []
236235

237236

238-
class ToolchainCL(object):
237+
class ToolchainCL:
239238

240239
def __init__(self):
241240

pythonforandroid/tools/biglink

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43
import os
54
import sys
65
import subprocess

pythonforandroid/tools/liblink

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43
import sys
54
import subprocess
65
from os import environ
@@ -22,7 +21,7 @@ while i < len(sys.argv):
2221
i += 1
2322
continue
2423

25-
if opt.startswith("-l") or opt.startswith("-L"):
24+
if opt.startswith(("-l", "-L")):
2625
libs.append(opt)
2726
continue
2827

@@ -34,27 +33,8 @@ while i < len(sys.argv):
3433
i += 1
3534
continue
3635

37-
if opt.startswith("-I") or opt.startswith('-isystem'):
38-
continue
39-
40-
if opt.startswith("-m"):
41-
continue
42-
43-
if opt.startswith("-f"):
44-
continue
45-
46-
if opt.startswith("-O"):
47-
continue
48-
49-
if opt.startswith("-g"):
50-
continue
51-
52-
if opt.startswith("-D"):
53-
continue
54-
55-
if opt.startswith("-R"):
56-
# for -rpath, not implemented yet.
57-
continue
36+
if opt.startswith(
37+
("-I", "-isystem", "-m", "-f", "-O", "-g", "-D", "-R")):
5838

5939
if opt.startswith("-"):
6040
print(sys.argv)

pythonforandroid/util.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
from fnmatch import fnmatch
77
from tempfile import mkdtemp
88

9-
# This Python version workaround left for compatibility during initial version check
10-
try: # Python 3
11-
from urllib.request import FancyURLopener
12-
except ImportError: # Python 2
13-
from urllib import FancyURLopener
9+
from urllib.request import FancyURLopener
1410

1511
from pythonforandroid.logger import (logger, Err_Fore, error, info)
1612

0 commit comments

Comments
 (0)