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

🗑️ Removes Python 2 constructions #1114

Merged
merged 1 commit into from
May 18, 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
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,6 @@ Note that this tool has nothing to do with the eponymous online build service
# edit the buildozer.spec, then
buildozer android debug deploy run

## Installing Buildozer with target Python 2

- Follow the same installation and buildozer init as Python 3

- Make sure the following lines are in your buildozer.spec file.:

# Changes python3 to python2
requirements = python2,kivy

- Finally, build, deploy and run the app on your phone::

buildozer android debug deploy run


## Buildozer Docker image

Expand Down
43 changes: 10 additions & 33 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'''

__version__ = '1.1.0'
__version__ = '1.1.1.dev0'

import os
import re
Expand All @@ -26,12 +26,8 @@

from pprint import pformat

try: # Python 3
from urllib.request import FancyURLopener
from configparser import SafeConfigParser
except ImportError: # Python 2
from urllib import FancyURLopener
from ConfigParser import SafeConfigParser
from urllib.request import FancyURLopener
from configparser import SafeConfigParser
try:
import fcntl
except ImportError:
Expand Down Expand Up @@ -73,7 +69,6 @@
LOG_LEVELS_C = (RED, BLUE, BLACK)
LOG_LEVELS_T = 'EID'
SIMPLE_HTTP_SERVER_PORT = 8000
IS_PY3 = sys.version_info[0] >= 3


class ChromeDownloader(FancyURLopener):
Expand Down Expand Up @@ -101,7 +96,7 @@ class BuildozerCommandException(BuildozerException):
pass


class Buildozer(object):
class Buildozer:

ERROR = 0
INFO = 1
Expand All @@ -111,7 +106,6 @@ class Buildozer(object):
'deploy', 'run', 'serve')

def __init__(self, filename='buildozer.spec', target=None):
super(Buildozer, self).__init__()
self.log_level = 2
self.environ = {}
self.specfilename = filename
Expand All @@ -127,10 +121,7 @@ def __init__(self, filename='buildozer.spec', target=None):
self.config.getrawdefault = self._get_config_raw_default

if exists(filename):
try:
self.config.read(filename, "utf-8")
except TypeError: # python 2 has no second arg here
self.config.read(filename)
self.config.read(filename, "utf-8")
self.check_configuration_tokens()

# Check all section/tokens for env vars, and replace the
Expand Down Expand Up @@ -318,21 +309,15 @@ def cmd(self, command, **kwargs):
if get_stdout:
ret_stdout.append(chunk)
if show_output:
if IS_PY3:
stdout.write(chunk.decode('utf-8', 'replace'))
else:
stdout.write(chunk)
stdout.write(chunk.decode('utf-8', 'replace'))
if fd_stderr in readx:
chunk = process.stderr.read()
if not chunk:
break
if get_stderr:
ret_stderr.append(chunk)
if show_output:
if IS_PY3:
stderr.write(chunk.decode('utf-8', 'replace'))
else:
stderr.write(chunk)
stderr.write(chunk.decode('utf-8', 'replace'))

stdout.flush()
stderr.flush()
Expand Down Expand Up @@ -374,10 +359,7 @@ def cmd_expect(self, command, **kwargs):
show_output = kwargs.pop('show_output')

if show_output:
if IS_PY3:
kwargs['logfile'] = codecs.getwriter('utf8')(stdout.buffer)
else:
kwargs['logfile'] = codecs.getwriter('utf8')(stdout)
kwargs['logfile'] = codecs.getwriter('utf8')(stdout.buffer)

if not sensible:
self.debug('Run (expect) {0!r}'.format(command))
Expand Down Expand Up @@ -571,7 +553,7 @@ def _ensure_virtualenv(self):
return
self.venv = join(self.buildozer_dir, 'venv')
if not self.file_exists(self.venv):
self.cmd('virtualenv --python=python2.7 ./venv',
self.cmd('python3 -m venv ./venv',
cwd=self.buildozer_dir)

# read virtualenv output and parse it
Expand Down Expand Up @@ -1073,11 +1055,6 @@ def check_root(self):
'''If effective user id is 0, display a warning and require
user input to continue (or to cancel)'''

if IS_PY3:
input_func = input
else:
input_func = raw_input

warn_on_root = self.config.getdefault('buildozer', 'warn_on_root', '1')
try:
euid = os.geteuid() == 0
Expand All @@ -1090,7 +1067,7 @@ def check_root(self):
print('\033[91mThis is \033[1mnot\033[0m \033[91mrecommended, and may lead to problems later.\033[0m')
cont = None
while cont not in ('y', 'n'):
cont = input_func('Are you sure you want to continue [y/n]? ')
cont = input('Are you sure you want to continue [y/n]? ')

if cont == 'n':
sys.exit()
Expand Down
17 changes: 5 additions & 12 deletions buildozer/jsonstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Replacement for shelve, using json.
This is currently needed to correctly support db between Python 2 and 3.
This was needed to correctly support db between Python 2 and 3.
"""

__all__ = ["JsonStore"]
Expand All @@ -10,12 +10,10 @@
from json import load, dump, dumps
from os.path import exists

IS_PY3 = sys.version_info[0] >= 3

class JsonStore(object):
class JsonStore:

def __init__(self, filename):
super(JsonStore, self).__init__()
super().__init__()
self.filename = filename
self.data = {}
if exists(filename):
Expand Down Expand Up @@ -46,10 +44,5 @@ def keys(self):
return self.data.keys()

def sync(self):
# http://stackoverflow.com/questions/12309269/write-json-data-to-file-in-python/14870531#14870531
if IS_PY3:
with open(self.filename, 'w') as fd:
dump(self.data, fd, ensure_ascii=False)
else:
with io.open(self.filename, 'w', encoding='utf-8') as fd:
fd.write(unicode(dumps(self.data, ensure_ascii=False)))
with open(self.filename, 'w') as fd:
dump(self.data, fd, ensure_ascii=False)
6 changes: 2 additions & 4 deletions buildozer/libs/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function


class Infinity(object):
class Infinity:

def __repr__(self):
return "Infinity"
Expand Down Expand Up @@ -46,7 +44,7 @@ def __neg__(self):
Infinity = Infinity()


class NegativeInfinity(object):
class NegativeInfinity:

def __repr__(self):
return "-Infinity"
Expand Down
4 changes: 1 addition & 3 deletions buildozer/libs/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import collections
import itertools
import re
Expand Down Expand Up @@ -49,7 +47,7 @@ class InvalidVersion(ValueError):
"""


class _BaseVersion(object):
class _BaseVersion:

def __hash__(self):
return hash(self._key)
Expand Down
4 changes: 2 additions & 2 deletions buildozer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def no_config(f):
return f


class Target(object):
class Target:
def __init__(self, buildozer):
super(Target, self).__init__()
super().__init__()
self.buildozer = buildozer
self.build_mode = 'debug'
self.platform_update = False
Expand Down
10 changes: 5 additions & 5 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import sh
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException, USE_COLOR, IS_PY3
from buildozer import BuildozerException, USE_COLOR
from buildozer.target import Target
from os import environ
from os.path import exists, join, realpath, expanduser, basename, relpath
Expand Down Expand Up @@ -66,7 +66,7 @@ class TargetAndroid(Target):
extra_p4a_args = ''

def __init__(self, *args, **kwargs):
super(TargetAndroid, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._arch = self.buildozer.config.getdefault(
'app', 'android.arch', DEFAULT_ARCH)
self._build_dir = join(
Expand Down Expand Up @@ -287,7 +287,7 @@ def check_configuration_tokens(self):
'[app] "android.permission" contain an unknown'
' permission {0}'.format(permission))

super(TargetAndroid, self).check_configuration_tokens(errors)
super().check_configuration_tokens(errors)

def _get_available_permissions(self):
key = 'android:available_permissions'
Expand Down Expand Up @@ -917,7 +917,7 @@ def cmd_run(self, *args):
if not entrypoint:
self.buildozer.config.set('app', 'android.entrypoint', 'org.kivy.android.PythonActivity')

super(TargetAndroid, self).cmd_run(*args)
super().cmd_run(*args)

entrypoint = self.buildozer.config.getdefault(
'app', 'android.entrypoint', 'org.kivy.android.PythonActivity')
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def cmd_adb(self, *args):
self.buildozer.cmd(' '.join([self.adb_cmd] + args))

def cmd_deploy(self, *args):
super(TargetAndroid, self).cmd_deploy(*args)
super().cmd_deploy(*args)
state = self.buildozer.state
if 'android:latestapk' not in state:
self.buildozer.error('No APK built yet. Run "debug" first.')
Expand Down
22 changes: 5 additions & 17 deletions buildozer/targets/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
raise NotImplementedError('Windows platform not yet working for Android')

import plistlib
from buildozer import BuildozerCommandException, IS_PY3
from buildozer import BuildozerCommandException
from buildozer.target import Target, no_config
from os.path import join, basename, expanduser, realpath
from getpass import getpass
Expand Down Expand Up @@ -252,14 +252,12 @@ def build_package(self):
self.buildozer.state['ios:latestipa'] = ipa
self.buildozer.state['ios:latestmode'] = self.build_mode

self._create_index()

def cmd_deploy(self, *args):
super(TargetIos, self).cmd_deploy(*args)
super().cmd_deploy(*args)
self._run_ios_deploy(lldb=False)

def cmd_run(self, *args):
super(TargetIos, self).cmd_run(*args)
super().cmd_run(*args)
self._run_ios_deploy(lldb=True)

def cmd_xcode(self, *args):
Expand Down Expand Up @@ -306,10 +304,6 @@ def _create_icons(self):
self.app_project_dir, icon_fn),
cwd=self.ios_dir)

def _create_index(self):
# TODO
pass

def check_configuration_tokens(self):
errors = []
config = self.buildozer.config
Expand All @@ -331,8 +325,7 @@ def check_configuration_tokens(self):
elif identity_release not in available_identities:
errors.append('[app] identity "{}" not found. '
'Check with list_identities'.format(identity_release))

super(TargetIos, self).check_configuration_tokens(errors)
super().check_configuration_tokens(errors)

@no_config
def cmd_list_identities(self, *args):
Expand Down Expand Up @@ -396,12 +389,7 @@ def _unlock_keychain(self):

save = None
while save is None:
if IS_PY3:
input_func = input
else:
input_func = raw_input

q = input_func('Do you want to save the password (Y/n): ')
q = input('Do you want to save the password (Y/n): ')
if q in ('', 'Y'):
save = True
elif q == 'n':
Expand Down
1 change: 0 additions & 1 deletion buildozer/targets/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException
from buildozer import IS_PY3
from buildozer.target import Target
from os import environ
from os.path import (exists, join, realpath, expanduser,
Expand Down
5 changes: 1 addition & 4 deletions tests/scripts/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import unittest
from buildozer import BuildozerCommandException
from buildozer.scripts import client
from unittest import mock

try:
from unittest import mock # Python 3
except ImportError:
import mock # Python 2

class TestClient(unittest.TestCase):

Expand Down
9 changes: 1 addition & 8 deletions tests/targets/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import buildozer as buildozer_module
from buildozer import Buildozer
from buildozer.targets.android import TargetAndroid

try:
from unittest import mock # Python 3
except ImportError:
import mock # Python 2
from unittest import mock


def patch_buildozer(method):
Expand Down Expand Up @@ -95,9 +91,6 @@ def test_init(self):
assert self.target_android.p4a_apk_cmd == "apk --debug --bootstrap=sdl2"
assert self.target_android.platform_update is False

@pytest.mark.skipif(
sys.version_info < (3, 0), reason="Python 2 ex_info.value.args is different"
)
def test_init_positional_buildozer(self):
"""Positional `buildozer` argument is required."""
with pytest.raises(TypeError) as ex_info:
Expand Down
Loading