Skip to content

Commit 9a6df24

Browse files
committed
Merge branch 'master' of github.com:kivy/python-for-android
2 parents 8080842 + f0265e0 commit 9a6df24

File tree

7 files changed

+126
-65
lines changed

7 files changed

+126
-65
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ to install and begin creating APK.
4848

4949
Quick instructions to start would be:
5050

51-
pip install git+https://github.com/kivy/python-for-android.git@revamp
51+
pip install git+https://github.com/kivy/python-for-android.git
5252

5353
The executable is called `python-for-android` or `p4a` (both are
5454
equivalent). To test that the installation worked, try

doc/source/quickstart.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ Installation
1717

1818
The easiest way to install is with pip. You need to have setuptools installed, then run::
1919

20-
pip install git+https://github.com/kivy/python-for-android.git@revamp
20+
pip install git+https://github.com/kivy/python-for-android.git
2121

2222
This should install python-for-android (though you may need to run as root or add --user).
2323

2424
You could also install python-for-android manually, either via git::
2525

26-
git clone -b revamp https://github.com/kivy/python-for-android.git
26+
git clone https://github.com/kivy/python-for-android.git
2727
cd python-for-android
2828
2929
Or by direct download::
3030

31-
wget https://github.com/kivy/python-for-android/archive/revamp.zip
31+
wget https://github.com/kivy/python-for-android/archive/master.zip
3232
unzip revamp.zip
3333
cd python-for-android-revamp
3434

doc/source/recipes.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ This code also manually takes care to patch only once. You can use the
139139
same strategy yourself, though a more generic solution may be provided
140140
in the future.
141141

142+
Installing libs
143+
~~~~~~~~~~~~~~~
144+
145+
Some recipes generate .so files that must be manually copied into the
146+
android project. You can use code like the following to accomplish
147+
this, copying to the correct lib cache dir::
148+
149+
def build_arch(self, arch):
150+
do_the_build() # e.g. running ./configure and make
151+
152+
import shutil
153+
shutil.copyfile('a_generated_binary.so',
154+
self.ctx.get_libs_dir(arch.arch))
155+
156+
Any libs copied to this dir will automatically be included in the
157+
appropriate libs dir of the generated android project.
158+
142159
Compiling for the Android architecture
143160
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144161

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from pythonforandroid.toolchain import (
3+
PythonRecipe,
4+
Recipe,
5+
current_directory,
6+
info,
7+
shprint,
8+
)
9+
from os.path import join
10+
import sh
11+
12+
13+
class SetuptoolsRecipe(PythonRecipe):
14+
version = '18.3.1'
15+
url = 'https://pypi.python.org/packages/source/s/setuptools/setuptools-{version}.tar.gz'
16+
17+
depends = ['python2']
18+
19+
call_hostpython_via_targetpython = False
20+
install_in_hostpython = True
21+
22+
23+
recipe = SetuptoolsRecipe()
Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,37 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchAndroid, info, Recipe
3-
from os.path import exists, join
4-
import sh
52
import glob
3+
from pythonforandroid.toolchain import (
4+
CythonRecipe,
5+
Recipe,
6+
current_directory,
7+
info,
8+
shprint,
9+
)
10+
from os.path import join
11+
import sh
612

713

814
class TwistedRecipe(CythonRecipe):
9-
# version = 'stable'
10-
version = '15.2'
11-
url = 'http://twistedmatrix.com/Releases/Twisted/{version}/Twisted-{version}.1.tar.bz2'
15+
version = '15.4.0'
16+
url = 'https://pypi.python.org/packages/source/T/Twisted/Twisted-{version}.tar.bz2'
17+
18+
depends = ['setuptools', 'zope_interface']
1219

13-
depends = ['zope']
20+
call_hostpython_via_targetpython = False
21+
install_in_hostpython = True
1422

1523
def prebuild_arch(self, arch):
1624
super(TwistedRecipe, self).prebuild_arch(arch)
17-
18-
# Need to whitelist tty.pyo and termios.so here
25+
# TODO Need to whitelist tty.pyo and termios.so here
26+
print('Should remove twisted tests etc. here, but skipping for now')
1927

2028
def get_recipe_env(self, arch):
2129
env = super(TwistedRecipe, self).get_recipe_env(arch)
22-
env['PYTHONPATH'] = ':'.join([self.ctx.get_site_packages_dir()])
23-
print('env is', env)
30+
# We add BUILDLIB_PATH to PYTHONPATH so twisted can find _io.so
31+
env['PYTHONPATH'] = ':'.join([
32+
self.ctx.get_site_packages_dir(),
33+
env['BUILDLIB_PATH'],
34+
])
2435
return env
2536

26-
def build_cython_components(self, arch):
27-
info('Cythonizing anything necessary in {}'.format(self.name))
28-
env = self.get_recipe_env(arch)
29-
with current_directory(self.get_build_dir(arch.arch)):
30-
hostpython = sh.Command(self.ctx.hostpython)
31-
info('Trying first build of {} to get cython files: this is '
32-
'expected to fail'.format(self.name))
33-
try:
34-
shprint(hostpython, 'setup.py', 'build_ext', _env=env)
35-
except sh.ErrorReturnCode_1:
36-
print()
37-
info('{} first build failed (as expected)'.format(self.name))
38-
39-
info('Running cython where appropriate')
40-
shprint(sh.find, self.get_build_dir('armeabi'), '-iname', '*.pyx', '-exec',
41-
self.ctx.cython, '{}', ';', _env=env)
42-
info('ran cython')
43-
44-
# shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env)
45-
46-
print('stripping')
47-
build_lib = glob.glob('./build/lib*')
48-
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
49-
env['STRIP'], '{}', ';', _env=env)
50-
print('stripped!?')
51-
# exit(1)
52-
53-
# Here we do *not* use the normal hostpython binary in the
54-
# target python dir, because twisted tries to import
55-
# _io.so which would fail.
56-
hostpython_build = sh.Command(join(
57-
Recipe.get_recipe('hostpython2', self.ctx).get_build_dir('armeabi'),
58-
'hostpython'))
59-
shprint(hostpython_build, 'setup.py', 'install', '-O2',
60-
'--root={}'.format(self.ctx.get_python_install_dir()),
61-
'--install-lib=/lib/python2.7/site-packages', _env=env)
62-
63-
64-
def postbuild_arch(self, arch):
65-
sup
66-
6737
recipe = TwistedRecipe()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
from pythonforandroid.toolchain import PythonRecipe, shprint, current_directory
3+
from os.path import join
4+
import sh
5+
6+
7+
class ZopeRecipe(PythonRecipe):
8+
version = '4.1.2'
9+
url = 'https://pypi.python.org/packages/source/z/zope.interface/zope.interface-{version}.tar.gz'
10+
11+
depends = ['python2']
12+
13+
def build_arch(self, arch):
14+
super(ZopeRecipe, self).build_arch(arch)
15+
print('Should remove zope tests etc. here, but skipping for now')
16+
17+
recipe = ZopeRecipe()

pythonforandroid/toolchain.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ def unpack(self, arch):
16721672
info('Extracting {} at {}'.format(extraction_filename, filename))
16731673
sh.tar('xjf', extraction_filename)
16741674
root_directory = sh.tar('tjf', extraction_filename).stdout.decode(
1675-
'utf-8').split('\n')[0].strip('/')
1675+
'utf-8').split('\n')[0].split('/')[0]
16761676
if root_directory != directory_name:
16771677
shprint(sh.mv, root_directory, directory_name)
16781678
elif extraction_filename.endswith('.zip'):
@@ -1896,9 +1896,31 @@ def get_jni_dir(self):
18961896

18971897

18981898
class PythonRecipe(Recipe):
1899-
site_packages_name = None # The name of the module in
1900-
# site_packages (i.e. as a python
1901-
# module)
1899+
site_packages_name = None
1900+
'''The name of the module's folder when installed in the Python
1901+
site-packages (e.g. for pyjnius it is 'jnius')'''
1902+
1903+
call_hostpython_via_targetpython = True
1904+
'''If True, tries to install the module using the hostpython binary
1905+
copied to the target (normally arm) python build dir. However, this
1906+
will fail if the module tries to import e.g. _io.so. Set this to False
1907+
to call hostpython from its own build dir, installing the module in
1908+
the right place via arguments to setup.py. However, this may not set
1909+
the environment correctly and so False is not the default.'''
1910+
1911+
install_in_hostpython = False
1912+
'''If True, additionally installs the module in the hostpython build
1913+
dir. This will make it available to other recipes if
1914+
call_hostpython_via_targetpython is False.
1915+
'''
1916+
1917+
@property
1918+
def hostpython_location(self):
1919+
if not self.call_hostpython_via_targetpython:
1920+
return join(
1921+
Recipe.get_recipe('hostpython2', self.ctx).get_build_dir(
1922+
'armeabi'), 'hostpython')
1923+
return self.ctx.hostpython
19021924

19031925
def should_build(self):
19041926
# AND: This should be different for each arch and use some
@@ -1914,8 +1936,6 @@ def should_build(self):
19141936
info('{} apparently isn\'t already in site-packages'.format(name))
19151937
return True
19161938

1917-
1918-
19191939
def build_arch(self, arch):
19201940
'''Install the Python module by calling setup.py install with
19211941
the target Python dir.'''
@@ -1938,9 +1958,23 @@ def install_python_package(self, name=None, env=None, is_dir=True):
19381958
info('Installing {} into site-packages'.format(self.name))
19391959

19401960
with current_directory(self.get_build_dir(arch.arch)):
1941-
hostpython = sh.Command(self.ctx.hostpython)
1961+
# hostpython = sh.Command(self.ctx.hostpython)
1962+
hostpython = sh.Command(self.hostpython_location)
1963+
1964+
if self.call_hostpython_via_targetpython:
1965+
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
1966+
else:
1967+
shprint(hostpython, 'setup.py', 'install', '-O2',
1968+
'--root={}'.format(self.ctx.get_python_install_dir()),
1969+
'--install-lib=lib/python2.7/site-packages',
1970+
_env=env) # AND: Hardcoded python2.7 needs fixing
19421971

1943-
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
1972+
# If asked, also install in the hostpython build dir
1973+
if self.install_in_hostpython:
1974+
shprint(hostpython, 'setup.py', 'install', '-O2',
1975+
'--root={}'.format(dirname(self.hostpython_location)),
1976+
'--install-lib=Lib/site-packages',
1977+
_env=env)
19441978

19451979

19461980
class CompiledComponentsPythonRecipe(PythonRecipe):
@@ -2169,7 +2203,7 @@ def biglink(ctx, arch):
21692203
info('There seem to be no libraries to biglink, skipping.')
21702204
return
21712205
info('Biglinking')
2172-
info('target', join(ctx.get_libs_dir(arch.arch), 'libpymodules.so'))
2206+
info('target {}'.format(join(ctx.get_libs_dir(arch.arch), 'libpymodules.so')))
21732207
biglink_function(
21742208
join(ctx.get_libs_dir(arch.arch), 'libpymodules.so'),
21752209
obj_dir.split(' '),

0 commit comments

Comments
 (0)