Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and cleanup #2115

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pythonforandroid.util import BuildInterruptingException, build_platform


class Arch(object):
class Arch:

toolchain_prefix = None
'''The prefix for the toolchain dir in the NDK.'''
Expand Down Expand Up @@ -46,7 +46,6 @@ class Arch(object):
]

def __init__(self, ctx):
super().__init__()
self.ctx = ctx

# Allows injecting additional linker paths used by any recipe.
Expand Down
1 change: 0 additions & 1 deletion pythonforandroid/bdistapk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from setuptools import Command

import sys
Expand Down
13 changes: 6 additions & 7 deletions pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def rank_bootstrap(bootstrap):
return 1


class Bootstrap(object):
class Bootstrap:
'''An Android project template, containing recipe stuff for
compilation and templated fields for APK info.
'''
Expand Down Expand Up @@ -294,15 +294,15 @@ def distribute_libs(self, arch, src_dirs, wildcard='*', dest_dir="libs"):
tgt_dir = join(dest_dir, arch.arch)
ensure_dir(tgt_dir)
for src_dir in src_dirs:
for lib in glob.glob(join(src_dir, wildcard)):
shprint(sh.cp, '-a', lib, tgt_dir)
libs = glob.glob(join(src_dir, wildcard))
shprint(sh.cp, '-a', *libs, tgt_dir)

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

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

def strip_libraries(self, arch):
info('Stripping libraries')
Expand Down
2 changes: 0 additions & 2 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function

import json
from os.path import (
dirname, join, isfile, realpath,
Expand Down
61 changes: 24 additions & 37 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from os.path import (
abspath, join, realpath, dirname, expanduser, exists,
split, isdir
Expand Down Expand Up @@ -79,7 +77,7 @@ def get_available_apis(sdk_dir):
return apis


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

Expand Down Expand Up @@ -132,34 +130,33 @@ def templates_dir(self):
@property
def libs_dir(self):
# Was previously hardcoded as self.build_dir/libs
dir = join(self.build_dir, 'libs_collections',
self.bootstrap.distribution.name)
ensure_dir(dir)
return dir
directory = join(self.build_dir, 'libs_collections',
self.bootstrap.distribution.name)
ensure_dir(directory)
return directory

@property
def javaclass_dir(self):
# Was previously hardcoded as self.build_dir/java
dir = join(self.build_dir, 'javaclasses',
self.bootstrap.distribution.name)
ensure_dir(dir)
return dir
directory = join(self.build_dir, 'javaclasses',
self.bootstrap.distribution.name)
ensure_dir(directory)
return directory

@property
def aars_dir(self):
dir = join(self.build_dir, 'aars', self.bootstrap.distribution.name)
ensure_dir(dir)
return dir
directory = join(self.build_dir, 'aars', self.bootstrap.distribution.name)
ensure_dir(directory)
return directory

@property
def python_installs_dir(self):
dir = join(self.build_dir, 'python-installs')
ensure_dir(dir)
return dir
directory = join(self.build_dir, 'python-installs')
ensure_dir(directory)
return directory

def get_python_install_dir(self):
dir = join(self.python_installs_dir, self.bootstrap.distribution.name)
return dir
return join(self.python_installs_dir, self.bootstrap.distribution.name)

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

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

def __init__(self):
super().__init__()
self.include_dirs = []

self._build_env_prepared = False
Expand Down Expand Up @@ -605,23 +600,16 @@ def build_recipes(build_order, python_modules, ctx, project_dir,
ignore_setup_py=ignore_project_setup_py
)

return


def project_has_setup_py(project_dir):
if project_dir is not None and \
(os.path.exists(os.path.join(project_dir,
"setup.py")) or
os.path.exists(os.path.join(project_dir,
"pyproject.toml"))
):
return True
return False
return (project_dir is not None and
(exists(join(project_dir, "setup.py")) or
exists(join(project_dir, "pyproject.toml"))
))


def run_setuppy_install(ctx, project_dir, env=None):
if env is None:
env = dict()
env = env or {}

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

print('Copying libraries')
for lib in sofiles:
shprint(sh.cp, lib, dest)
shprint(sh.cp, *sofiles, dest)
2 changes: 1 addition & 1 deletion pythonforandroid/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from shutil import rmtree


class Distribution(object):
class Distribution:
'''State container for information about a distribution (i.e. an
Android project).

Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def obvious_conflict_checker(ctx, name_tuples, blacklist=None):
current_to_be_added = list(to_be_added)
to_be_added = []
for (added_tuple, adding_recipe) in current_to_be_added:
assert(type(added_tuple) == tuple)
assert type(added_tuple) == tuple
if len(added_tuple) > 1:
# No obvious commitment in what to add, don't check it itself
# but throw it into deps for later comparing against
Expand Down
21 changes: 4 additions & 17 deletions pythonforandroid/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
from collections import defaultdict
from colorama import Style as Colo_Style, Fore as Colo_Fore

# six import left for Python 2 compatibility during initial Python version check
import six

# This codecs change fixes a bug with log output, but crashes under python3
if not six.PY3:
import codecs
stdout = codecs.getwriter('utf8')(stdout)
stderr = codecs.getwriter('utf8')(stderr)

if six.PY2:
unistr = unicode # noqa F821
else:
unistr = str

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


class colorama_shim(object):
class colorama_shim:

def __init__(self, real):
self._dict = defaultdict(str)
Expand Down Expand Up @@ -114,12 +101,12 @@ def shorten_string(string, max_width):
return string
visible = max_width - 16 - int(log10(string_len))
# expected suffix len "...(and XXXXX more)"
if not isinstance(string, unistr):
visstring = unistr(string[:visible], errors='ignore')
if not isinstance(string, str):
visstring = str(string[:visible], errors='ignore')
else:
visstring = string[:visible]
return u''.join((visstring, u'...(and ',
unistr(string_len - visible), u' more)'))
str(string_len - visible), u' more)'))


def get_console_width():
Expand Down
31 changes: 11 additions & 20 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split
import glob
from shutil import rmtree
from six import PY2, with_metaclass
from six import with_metaclass

import hashlib
from re import match
Expand All @@ -22,26 +22,17 @@


def import_recipe(module, filename):
if PY2:
import imp
import warnings
with warnings.catch_warnings():
# ignores warnings raised by hierarchical module names
# (names containing dots) on Python 2
warnings.simplefilter("ignore", RuntimeWarning)
return imp.load_source(module, filename)
# Python 3.5+
import importlib.util
if hasattr(importlib.util, 'module_from_spec'):
spec = importlib.util.spec_from_file_location(module, filename)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
else:
# Python 3.5+
import importlib.util
if hasattr(importlib.util, 'module_from_spec'):
spec = importlib.util.spec_from_file_location(module, filename)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
else:
# Python 3.3 and 3.4:
from importlib.machinery import SourceFileLoader
return SourceFileLoader(module, filename).load_module()
# Python 3.3 and 3.4:
from importlib.machinery import SourceFileLoader
return SourceFileLoader(module, filename).load_module()


class RecipeMeta(type):
Expand Down
1 change: 0 additions & 1 deletion pythonforandroid/recipes/android/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour
from pythonforandroid.util import current_directory
from pythonforandroid import logger
Expand Down
3 changes: 1 addition & 2 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
This module defines the entry point for command line and programmatic use.
"""

from __future__ import print_function
from os import environ
from pythonforandroid import __version__
from pythonforandroid.pythonpackage import get_dep_names_of_package
Expand Down Expand Up @@ -235,7 +234,7 @@ def _get_option_tuples(self, option_string):
return []


class ToolchainCL(object):
class ToolchainCL:

def __init__(self):

Expand Down
1 change: 0 additions & 1 deletion pythonforandroid/tools/biglink
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys
import subprocess
Expand Down
26 changes: 3 additions & 23 deletions pythonforandroid/tools/liblink
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

from __future__ import print_function
import sys
import subprocess
from os import environ
Expand All @@ -22,7 +21,7 @@ while i < len(sys.argv):
i += 1
continue

if opt.startswith("-l") or opt.startswith("-L"):
if opt.startswith(("-l", "-L")):
libs.append(opt)
continue

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

if opt.startswith("-I") or opt.startswith('-isystem'):
continue

if opt.startswith("-m"):
continue

if opt.startswith("-f"):
continue

if opt.startswith("-O"):
continue

if opt.startswith("-g"):
continue

if opt.startswith("-D"):
continue

if opt.startswith("-R"):
# for -rpath, not implemented yet.
continue
if opt.startswith(
("-I", "-isystem", "-m", "-f", "-O", "-g", "-D", "-R")):

if opt.startswith("-"):
print(sys.argv)
Expand Down
6 changes: 1 addition & 5 deletions pythonforandroid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from fnmatch import fnmatch
from tempfile import mkdtemp

# This Python version workaround left for compatibility during initial version check
try: # Python 3
from urllib.request import FancyURLopener
except ImportError: # Python 2
from urllib import FancyURLopener
from urllib.request import FancyURLopener

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

Expand Down
Loading