Skip to content

Commit

Permalink
Merge pull request kivy#1118 from AndreMiras/feature/linter_fixes
Browse files Browse the repository at this point in the history
🗑️ Linter fixes and README.md update
  • Loading branch information
AndreMiras authored May 25, 2020
2 parents 4333b9c + c0ccfda commit 43214d4
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- uses: actions/checkout@v2
- name: Try Python 2 install
run: |
# we don't want to build to fail with the exit 1 so we catch with "||"
# we don't want the build to fail with the exit 1 so we catch with "||"
python2 -m pip install -e . 2> error.log || echo Failing as expected
cat error.log
grep "Unsupported Python version" error.log
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ project, and for iOS via the kivy-ios project. iOS and OSX are still under work.

For Android, buildozer will automatically download and prepare the
build dependencies. For more information, see
[Android-SDK-NDK-Information](https://github.com/kivy/kivy/wiki/Android-SDK-NDK-Information). We
recommend targeting Python 3 on Android, but you can target both
Python 3 and Python 2 regardless of which version you use with
buildozer on the desktop.
[Android-SDK-NDK-Information](https://github.com/kivy/kivy/wiki/Android-SDK-NDK-Information).
Note that only Python 3 is supported.

Note that this tool has nothing to do with the eponymous online build service
[buildozer.io](http://buildozer.io).
Expand Down
12 changes: 4 additions & 8 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,6 @@ def file_copy(self, source, target, cwd=None):

def file_extract(self, archive, cwd=None):
if archive.endswith('.tgz') or archive.endswith('.tar.gz'):
# XXX tarfile doesn't work for NDK-r8c :(
#tf = tarfile.open(archive, 'r:*')
#tf.extractall(path=cwd)
#tf.close()
self.cmd('tar xzf {0}'.format(archive), cwd=cwd)
return

Expand All @@ -631,8 +627,8 @@ def file_extract(self, archive, cwd=None):

if archive.endswith('.bin'):
# To process the bin files for linux and darwin systems
self.cmd('chmod a+x {0}'.format(archive),cwd=cwd)
self.cmd('./{0}'.format(archive),cwd=cwd)
self.cmd('chmod a+x {0}'.format(archive), cwd=cwd)
self.cmd('./{0}'.format(archive), cwd=cwd)
return

if archive.endswith('.zip'):
Expand Down Expand Up @@ -830,7 +826,6 @@ def _add_sitecustomize(self):

main_py = join(self.app_dir, 'service', 'main.py')
if not self.file_exists(main_py):
#self.error('Unable to patch main_py to add applibs directory.')
return

header = (b'import sys, os; '
Expand All @@ -847,7 +842,7 @@ def namify(self, name):
'''Return a "valid" name from a name with lot of invalid chars
(allowed characters: a-z, A-Z, 0-9, -, _)
'''
return re.sub('[^a-zA-Z0-9_\-]', '_', name)
return re.sub(r'[^a-zA-Z0-9_\-]', '_', name)

@property
def root_dir(self):
Expand Down Expand Up @@ -1249,6 +1244,7 @@ def set_config_from_envs(config):
for token in config.options(section):
set_config_token_from_env(section, token, config)


def set_config_token_from_env(section, token, config):
'''Given a config section and token, checks for an appropriate
environment variable. If the variable exists, sets the config entry to
Expand Down
5 changes: 2 additions & 3 deletions buildozer/jsonstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
__all__ = ["JsonStore"]

import io
import sys
from json import load, dump, dumps
from json import load, dump
from os.path import exists


class JsonStore:

def __init__(self, filename):
super().__init__()
self.filename = filename
self.data = {}
if exists(filename):
Expand Down
2 changes: 2 additions & 0 deletions buildozer/libs/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __ge__(self, other):
def __neg__(self):
return NegativeInfinity


Infinity = Infinity()


Expand Down Expand Up @@ -73,4 +74,5 @@ def __ge__(self, other):
def __neg__(self):
return Infinity


NegativeInfinity = NegativeInfinity()
1 change: 1 addition & 0 deletions buildozer/libs/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def _legacy_cmpkey(version):

return epoch, parts


# Deliberately not anchored to the start and end of the string, to make it
# easier for 3rd party code to reuse
VERSION_PATTERN = r"""
Expand Down
1 change: 1 addition & 0 deletions buildozer/scripts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def main():
Buildozer().error('%s' % error)
sys.exit(1)


if __name__ == '__main__':
main()
17 changes: 6 additions & 11 deletions buildozer/scripts/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ConfigParser import SafeConfigParser
try:
import termios
import tty
has_termios = True
except ImportError:
has_termios = False
Expand Down Expand Up @@ -131,7 +130,7 @@ def _ensure_buildozer(self):
self.package_full_name)
self.debug('Remote build directory: {}'.format(self.remote_build_dir))
self._ssh_mkdir(self.remote_build_dir)
self._ssh_sync(__path__[0])
self._ssh_sync(__path__[0]) # noqa: F821 undefined name

def _sync_application_sources(self):
self.info('Synchronize application sources')
Expand Down Expand Up @@ -159,7 +158,7 @@ def _do_remote_commands(self, args):
self.remote_build_dir,
'--verbose' if self.log_level == 2 else '',
' '.join(args),
)
)
self._ssh_command(cmd)

def _ssh_mkdir(self, *args):
Expand All @@ -180,7 +179,7 @@ def _ssh_sync(self, directory, mode='put'):
directory = realpath(directory)
base_strip = directory.rfind('/')
if mode == 'get':
local_dir = join(directory,'bin')
local_dir = join(directory, 'bin')
remote_dir = join(self.remote_build_dir, 'bin')
if not exists(local_dir):
makedirs(local_dir)
Expand All @@ -200,9 +199,6 @@ def _ssh_sync(self, directory, mode='put'):

def _ssh_command(self, command):
self.debug('Execute remote command {}'.format(command))
#shell = self._ssh_client.invoke_shell()
#shell.sendall(command)
#shell.sendall('\nexit\n')
transport = self._ssh_client.get_transport()
channel = transport.open_session()
try:
Expand All @@ -220,8 +216,6 @@ def _interactive_shell(self, chan):
def _posix_shell(self, chan):
oldtty = termios.tcgetattr(stdin)
try:
#tty.setraw(stdin.fileno())
#tty.setcbreak(stdin.fileno())
chan.settimeout(0.0)

while True:
Expand All @@ -234,7 +228,6 @@ def _posix_shell(self, chan):
break
stdout.write(x)
stdout.flush()
#print len(x), repr(x)
except socket.timeout:
pass
if stdin in r:
Expand All @@ -246,7 +239,7 @@ def _posix_shell(self, chan):
termios.tcsetattr(stdin, termios.TCSADRAIN, oldtty)

# thanks to Mike Looijmans for this code
def _windows_shell(self,chan):
def _windows_shell(self, chan):
import threading

stdout.write("Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n")
Expand Down Expand Up @@ -274,6 +267,7 @@ def writeall(sock):
# user hit ^Z or F6
pass


def main():
try:
BuildozerRemote().run_command(sys.argv[1:])
Expand All @@ -282,5 +276,6 @@ def main():
except BuildozerException as error:
Buildozer().error('%s' % error)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion buildozer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import os
from os.path import join


def no_config(f):
f.__no_config = True
return f


class Target:
def __init__(self, buildozer):
super().__init__()
self.buildozer = buildozer
self.build_mode = 'debug'
self.platform_update = False
Expand Down
14 changes: 7 additions & 7 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io
import re
import ast
import sh
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException, USE_COLOR
Expand Down Expand Up @@ -249,7 +248,7 @@ def check_requirements(self):
break_on_error=False)
is_debian_like = (returncode_dpkg == 0)
if is_debian_like and \
not self.buildozer.file_exists('/usr/include/zlib.h'):
not self.buildozer.file_exists('/usr/include/zlib.h'):
raise BuildozerException(
'zlib headers must be installed, '
'run: sudo apt-get install zlib1g-dev')
Expand Down Expand Up @@ -740,7 +739,7 @@ def _install_p4a(self):
try:
with open(join(self.p4a_dir, "setup.py")) as fd:
setup = fd.read()
deps = re.findall("^\s*install_reqs = (\[[^\]]*\])", setup, re.DOTALL | re.MULTILINE)[0]
deps = re.findall(r"^\s*install_reqs = (\[[^\]]*\])", setup, re.DOTALL | re.MULTILINE)[0]
deps = ast.literal_eval(deps)
except IOError:
self.buildozer.error('Failed to read python-for-android setup.py at {}'.format(
Expand Down Expand Up @@ -768,7 +767,7 @@ def compile_platform(self):
'P4A_{}_DIR'.format(name[20:]): realpath(expanduser(value))
for name, value in self.buildozer.config.items('app')
if name.startswith('requirements.source.')
}
}
if source_dirs:
self.buildozer.environ.update(source_dirs)
self.buildozer.info('Using custom source dirs:\n {}'.format(
Expand Down Expand Up @@ -1055,12 +1054,12 @@ def build_package(self):
build_cmd += [('--add-compile-option', option)]

# android.add_gradle_repositories
repos = config.getlist('app','android.add_gradle_repositories', [])
repos = config.getlist('app', 'android.add_gradle_repositories', [])
for repo in repos:
build_cmd += [('--add-gradle-repository', repo)]

# android packaging options
pkgoptions = config.getlist('app','android.add_packaging_options', [])
pkgoptions = config.getlist('app', 'android.add_packaging_options', [])
for pkgoption in pkgoptions:
build_cmd += [('--add-packaging-option', pkgoption)]

Expand Down Expand Up @@ -1114,7 +1113,7 @@ def build_package(self):
build_cmd += [("--ouya-icon", join(self.buildozer.root_dir,
ouya_icon))]

if config.getdefault('app','p4a.bootstrap','sdl2') != 'service_only':
if config.getdefault('app', 'p4a.bootstrap', 'sdl2') != 'service_only':
# add orientation
orientation = config.getdefault('app', 'orientation', 'landscape')
if orientation == 'all':
Expand Down Expand Up @@ -1360,6 +1359,7 @@ def get_target(buildozer):
buildozer.targetname = "android"
return TargetAndroid(buildozer)


def generate_dist_folder_name(base_dist_name, arch_names=None):
"""Generate the distribution folder name to use, based on a
combination of the input arguments.
Expand Down
4 changes: 3 additions & 1 deletion buildozer/targets/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</html>
'''


class TargetIos(Target):
targetname = "ios"

Expand Down Expand Up @@ -113,7 +114,7 @@ def compile_platform(self):

# we need to extract the requirements that kivy-ios knows about
available_modules = self.get_available_packages()
onlyname = lambda x: x.split('==')[0]
onlyname = lambda x: x.split('==')[0] # noqa: E731 do not assign a lambda expression, use a def
ios_requirements = [x for x in app_requirements if onlyname(x) in
available_modules]

Expand Down Expand Up @@ -401,5 +402,6 @@ def _unlock_keychain(self):
with open(password_file, 'wb') as fd:
fd.write(password.encode())


def get_target(buildozer):
return TargetIos(buildozer)
24 changes: 4 additions & 20 deletions buildozer/targets/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@
if sys.platform != 'darwin':
raise NotImplementedError('This will only work on osx')

#Global variables

#Global imports
import traceback
import os
import io
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException
from buildozer.target import Target
from os import environ
from os.path import (exists, join, realpath, expanduser,
basename, relpath, abspath, dirname)
from shutil import copyfile
from glob import glob
from os.path import exists, join, abspath, dirname
from subprocess import check_call, check_output

from buildozer.libs.version import parse


class TargetOSX(Target):
targetname = "osx"

def ensure_sdk(self):
self.buildozer.info('Check if kivy-sdk-packager exists')
if exists(
join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
self.buildozer.info(
'kivy-sdk-packager found at '
'{}'.format(self.buildozer.platform_dir))
Expand Down Expand Up @@ -122,7 +107,7 @@ def build_package(self):
author = bc.getdefault('app', 'author', '')

self.buildozer.info('Create {}.app'.format(package_name))
cwd = join(self.buildozer.platform_dir,'kivy-sdk-packager-master', 'osx')
cwd = join(self.buildozer.platform_dir, 'kivy-sdk-packager-master', 'osx')
# remove kivy from app_deps
app_deps = [a for a in app_deps.split('\n') if not a.startswith('#') and a not in ['kivy', '']]

Expand All @@ -139,7 +124,6 @@ def build_package(self):
'--bundlename={}'.format(title),
'--bundleid={}'.format(domain),
'--bundleversion={}'.format(version),
#'--deps={}'.format(','.join(app_deps)),
'--displayname={}'.format(title)
]
if icon:
Expand Down Expand Up @@ -174,7 +158,7 @@ def install_platform(self):
#
self.buildozer.environ.update({
'PACKAGES_PATH': self.buildozer.global_packages_dir,
})
})

def get_custom_commands(self):
result = []
Expand Down
1 change: 0 additions & 1 deletion tests/targets/test_android.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import pytest
import codecs
import tempfile
Expand Down
12 changes: 1 addition & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@ commands = flake8 buildozer/ tests/
ignore =
E121, # continuation line under-indented for hanging indent
E122, # continuation line missing indentation or outdented
E123, # closing bracket does not match indentation of opening bracket's line
E125, # continuation line with same indent as next logical line
E126, # continuation line over-indented for hanging indent
E127, # continuation line over-indented for visual indent
E128, # continuation line under-indented for visual indent
E131, # continuation line unaligned for hanging indent
E231, # missing whitespace after ','
E265, # block comment should start with '# '
E302, # expected 2 blank lines, found 1
E305, # expected 2 blank lines after class or function definition, found 1
E402, # module level import not at top of file
E501, # line too long
E722, # do not use bare 'except'
E731, # do not assign a lambda expression, use a def
F401, # imported but unused
F821, # undefined name
W503, # line break before binary operator
W504, # line break after binary operator
W605 # invalid escape sequence
W504 # line break after binary operator

0 comments on commit 43214d4

Please sign in to comment.