PY4A: PyCrypto をビルド
PEP452 って知らなかったです。
py4a の pyver と abi は間違っているみたいです。
次のリリースぐらいには直そうかな
さて、 pycrypto を cross compile してみました。
wheel (pip) の platform チェックを調べる
import re
wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.whl|\.dist-info)$""",
re.VERBOSE
)
for i in ("pycrypto-2.6.1-cp36-cp36m-arm_linux_androideabi.whl",
"pycrypto-2.6.1-cpython-36m-arm_linux_androideabi.whl",
):
info = wheel_file_re.match(i)
print(info.group("ver"),
info.group("pyver"),
info.group("abi"),
info.group("plat"))
>>> 2.6.1 cp36 cp36m arm_linux_androideabi
>>> 2.6.1 cpython 36m arm_linux_androideabi
n7000 ~ # bash python3.sh
Python 3.6.0 (default, Mar 5 2017, 14:39:55)
[GCC 4.9 20140827 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from wheel import pep425tags
>>> pep425tags.supported_tags
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'wheel.pep425tags' has no attribute 'supported_tags'
>>> pep425tags.supported_tags
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'wheel.pep425tags' has no attribute 'supported_tags'
>>> from pip import pep425tags as a
WARNING:root:cert file changed, android system have no-compatibles with python:/mnt/sdcard/com.googlecode.python3forandroid/cacert.pem
>>> a.supported_tags
[('cp36', 'cp36m', 'linux_armv7l'), ('cp36', 'abi3', 'linux_armv7l'), ('cp36', 'none', 'linux_armv7l'), ('cp35', 'abi3', 'linux_armv7l'), ('cp34', 'abi3', 'linux_armv7l'), ('cp33', 'abi3', 'linux_armv7l'), ('cp32', 'abi3', 'linux_armv7l'), ('py3', 'none', 'linux_armv7l'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'), ('py3', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
出力を見ると linux_armv7l となってますね。
ファイル名を変更して install を実効してみます。:
n7000 ~ # bash python3.sh sl4a/scripts/pip_console.py install wheel
WARNING:root:cert file changed, android system have no-compatibles with python:/mnt/sdcard/com.googlecode.python3forandroid/cacert.pem
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |################################| 71kB 177kB/s
Installing collected packages: wheel
Successfully installed wheel-0.29.0
n7000 ~ # bash python3.sh sl4a/scripts/pip_console.py install pycrypto-2.6.1-cp36-cp36m-linux_armv7l.whl
WARNING:root:cert file changed, android system have no-compatibles with python:/mnt/sdcard/com.googlecode.python3forandroid/cacert.pem
Processing ./pycrypto-2.6.1-cp36-cp36m-linux_armv7l.whl
Installing collected packages: pycrypto
Successfully installed pycrypto-2.6.1
使えるかどうかテスト
n7000 ~ # bash python3.sh
Python 3.6.0 (default, Mar 5 2017, 14:39:55)
[GCC 4.9 20140827 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.Hash import SHA256
>>> SHA256.new('abc'.encode("latin-1")).hexdigest()
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
[Makefile](https://github.com/kuri65536/python-for-android/python-modules/PyCrypto/Makefile)
に落とし込んで完了
[#130](https://github.com/kuri65536/python-for-android/issues/130)
続きを読む…