Skip to content

Commit 6660b9e

Browse files
author
Jonas Thiem
committed
Fix various issues with graphs and recipes:
- fix graph depending on capitalization when pip doesn't - fix graph giving no useful errors (now it gives them sometimes) - fix graph entering infinite loop when no bootstrap is found - fix recipe not being obtainable irregardless of capitalization - fix recipe IOError-on-doesn't-exist not distinguishable from code-messes-up-and-causes-true-IOError. a non-existent recipe will now cause a ValueError - fix the bootstraps own dependencies being wrong and unused - possibly other minor fixes I forgot about
1 parent 0c4cd1d commit 6660b9e

File tree

12 files changed

+393
-61
lines changed

12 files changed

+393
-61
lines changed

pythonforandroid/bootstrap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class Bootstrap(object):
4949
dist_name = None
5050
distribution = None
5151

52-
recipe_depends = ['sdl2']
52+
# All bootstraps should include Python in some way:
53+
recipe_depends = [
54+
("python2", "python2legacy", "python3", "python3crystax"),
55+
]
5356

5457
can_be_chosen_automatically = True
5558
'''Determines whether the bootstrap can be chosen as one that
@@ -167,15 +170,15 @@ def get_bootstrap_from_recipes(cls, recipes, ctx):
167170
for recipe in recipes:
168171
try:
169172
recipe = Recipe.get_recipe(recipe, ctx)
170-
except IOError:
173+
except ValueError:
171174
conflicts = []
172175
else:
173176
conflicts = recipe.conflicts
174177
if any([conflict in possible_dependencies
175178
for conflict in conflicts]):
176179
ok = False
177180
break
178-
if ok:
181+
if ok and bs not in acceptable_bootstraps:
179182
acceptable_bootstraps.append(bs)
180183
info('Found {} acceptable bootstraps: {}'.format(
181184
len(acceptable_bootstraps),

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ def parse_args(args=None):
566566

567567
# --private is required unless for sdl2, where there's also --launcher
568568
ap.add_argument('--private', dest='private',
569-
help='the dir of user files',
569+
help='the directory with the app source code files' +
570+
' (containing your main.py entrypoint)',
570571
required=(get_bootstrap_name() != "sdl2"))
571572
ap.add_argument('--package', dest='package',
572573
help=('The name of the java package the project will be'

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
class SDL2GradleBootstrap(Bootstrap):
99
name = 'sdl2'
1010

11-
recipe_depends = ['sdl2']
11+
recipe_depends = list(
12+
set(Bootstrap.recipe_depends).union({'sdl2'})
13+
)
1214

1315
def run_distribute(self):
1416
info_main("# Creating Android project ({})".format(self.name))

pythonforandroid/bootstraps/service_only/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class ServiceOnlyBootstrap(Bootstrap):
99

1010
name = 'service_only'
1111

12-
recipe_depends = ['genericndkbuild', ('python2', 'python3', 'python3crystax')]
12+
recipe_depends = list(
13+
set(Bootstrap.recipe_depends).union({'genericndkbuild'})
14+
)
1315

1416
def run_distribute(self):
1517
info_main('# Creating Android project from build and {} bootstrap'.format(

pythonforandroid/bootstraps/webview/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
class WebViewBootstrap(Bootstrap):
88
name = 'webview'
99

10-
recipe_depends = ['genericndkbuild', ('python2', 'python3', 'python3crystax')]
10+
recipe_depends = list(
11+
set(Bootstrap.recipe_depends).union({'genericndkbuild'})
12+
)
1113

1214
def run_distribute(self):
1315
info_main('# Creating Android project from build and {} bootstrap'.format(

pythonforandroid/build.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import sh
1212
import subprocess
1313

14-
from pythonforandroid.util import (ensure_dir, current_directory, BuildInterruptingException)
14+
from pythonforandroid.util import (
15+
current_directory, ensure_dir, get_virtualenv_executable,
16+
BuildInterruptingException
17+
)
1518
from pythonforandroid.logger import (info, warning, info_notify, info_main, shprint)
1619
from pythonforandroid.archs import ArchARM, ArchARMv7_a, ArchAarch_64, Archx86, Archx86_64
1720
from pythonforandroid.recipe import CythonRecipe, Recipe
@@ -305,13 +308,7 @@ def prepare_build_environment(self,
305308

306309
check_ndk_api(ndk_api, self.android_api)
307310

308-
virtualenv = None
309-
if virtualenv is None:
310-
virtualenv = sh.which('virtualenv2')
311-
if virtualenv is None:
312-
virtualenv = sh.which('virtualenv-2.7')
313-
if virtualenv is None:
314-
virtualenv = sh.which('virtualenv')
311+
virtualenv = get_virtualenv_executable()
315312
if virtualenv is None:
316313
raise IOError('Couldn\'t find a virtualenv executable, '
317314
'you must install this to use p4a.')
@@ -509,7 +506,7 @@ def has_package(self, name, arch=None):
509506
# Try to look up recipe by name:
510507
try:
511508
recipe = Recipe.get_recipe(name, self)
512-
except IOError:
509+
except ValueError:
513510
pass
514511
else:
515512
name = getattr(recipe, 'site_packages_name', None) or name
@@ -618,14 +615,15 @@ def run_pymodules_install(ctx, modules):
618615
line = '{}\n'.format(module)
619616
fileh.write(line)
620617

618+
# Prepare base environment and upgrade pip:
621619
base_env = copy.copy(os.environ)
622620
base_env["PYTHONPATH"] = ctx.get_site_packages_dir()
623-
624621
info('Upgrade pip to latest version')
625622
shprint(sh.bash, '-c', (
626623
"source venv/bin/activate && pip install -U pip"
627624
), _env=copy.copy(base_env))
628625

626+
# Install Cython in case modules need it to build:
629627
info('Install Cython in case one of the modules needs it to build')
630628
shprint(sh.bash, '-c', (
631629
"venv/bin/pip install Cython"
@@ -648,15 +646,17 @@ def run_pymodules_install(ctx, modules):
648646
'changes / workarounds.')
649647

650648
# Make sure our build package dir is available, and the virtualenv
651-
# site packages come FIRST (for the proper pip version):
649+
# site packages come FIRST (so the proper pip version is used):
652650
env["PYTHONPATH"] += ":" + ctx.get_site_packages_dir()
653651
env["PYTHONPATH"] = os.path.abspath(join(
654652
ctx.build_dir, "venv", "lib",
655653
"python" + ctx.python_recipe.major_minor_version_string,
656654
"site-packages")) + ":" + env["PYTHONPATH"]
655+
656+
# Do actual install:
657657
shprint(sh.bash, '-c', (
658-
"source venv/bin/activate && " +
659-
"pip install -v --target '{0}' --no-deps -r requirements.txt"
658+
"venv/bin/pip " +
659+
"install -v --target '{0}' --no-deps -r requirements.txt"
660660
).format(ctx.get_site_packages_dir().replace("'", "'\"'\"'")),
661661
_env=copy.copy(env))
662662

0 commit comments

Comments
 (0)