diff options
author | Christophe Vu-Brugier <cvubrugier@fastmail.fm> | 2015-11-14 16:54:30 +0100 |
---|---|---|
committer | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2015-11-17 23:13:28 +0100 |
commit | c3d65a4dad707db83122ac082202f3e8dc70e60f (patch) | |
tree | 4e427fac30a1683744ae720fad3a1ce0f5cfb3bd /package/python3/020-importlib-no-pep3147.patch | |
parent | 5583d2dbfc15e7d4f059d7323db5d63c8b0ec5c3 (diff) | |
download | buildroot-c3d65a4dad707db83122ac082202f3e8dc70e60f.tar.gz buildroot-c3d65a4dad707db83122ac082202f3e8dc70e60f.zip |
python3: add patch to fix PEP 3147 issue with automake built packages
Packages built with automake use a `py-compile` helper to byte-compile
Python source files. This script uses the "py_compile" module from the
standard library. In turn, the compile() function in the "py_compile"
module invokes the cache_from_source() function provided by importlib.
This commit adds a new patch named "020-importlib-no-pep3147.patch"
that changes cache_from_source() and source_from_cache() in importlib
to get rid of the "__pycache__" directory.
This commit fixes the following import error in kmod when the module
is built for Python 3:
>>> from kmod import Kmod
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Kmod'
Moreover, this commit removes two patches that are no longer necessary
since modifying cache_from_source() and source_from_cache() disables
PEP 3147 for the standard library and distutils / setuptools.
* 004-old-stdlib-cache.patch
* 016-distutils-no-pep3147.patch
Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Diffstat (limited to 'package/python3/020-importlib-no-pep3147.patch')
-rw-r--r-- | package/python3/020-importlib-no-pep3147.patch | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/package/python3/020-importlib-no-pep3147.patch b/package/python3/020-importlib-no-pep3147.patch new file mode 100644 index 0000000000..779b5e27c3 --- /dev/null +++ b/package/python3/020-importlib-no-pep3147.patch @@ -0,0 +1,69 @@ +Add importlib fix for PEP 3147 issue + +Python 3 has a new standard for installing .pyc file, called PEP +3147. Unfortunately, this standard requires both the .py and .pyc +files to be installed for a Python module to be found. This is quite +annoying on space-constrained embedded systems, since the .py file is +technically not required for execution. + +This patch changes cache_from_source() and source_from_cache() in +importlib to get rid of the "__pycache__" directory. +This effectively disables PEP 3147 for: + +* The python standard library +* Packages built with distutils or setuptools +* Packages built with automake that use the `py-compile` helper + +Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm> + +diff -purN a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py +--- a/Lib/importlib/_bootstrap.py 2015-02-25 12:27:44.000000000 +0100 ++++ b/Lib/importlib/_bootstrap.py 2015-08-27 17:33:26.167191059 +0200 +@@ -444,8 +444,6 @@ def cache_from_source(path, debug_overri + If debug_override is not None, then it must be a boolean and is used in + place of sys.flags.optimize. + +- If sys.implementation.cache_tag is None then NotImplementedError is raised. +- + """ + debug = not sys.flags.optimize if debug_override is None else debug_override + if debug: +@@ -454,33 +452,19 @@ def cache_from_source(path, debug_overri + suffixes = OPTIMIZED_BYTECODE_SUFFIXES + head, tail = _path_split(path) + base, sep, rest = tail.rpartition('.') +- tag = sys.implementation.cache_tag +- if tag is None: +- raise NotImplementedError('sys.implementation.cache_tag is None') +- filename = ''.join([(base if base else rest), sep, tag, suffixes[0]]) +- return _path_join(head, _PYCACHE, filename) ++ filename = ''.join([(base if base else rest), suffixes[0]]) ++ return _path_join(head, filename) + + + def source_from_cache(path): + """Given the path to a .pyc./.pyo file, return the path to its .py file. + + The .pyc/.pyo file does not need to exist; this simply returns the path to +- the .py file calculated to correspond to the .pyc/.pyo file. If path does +- not conform to PEP 3147 format, ValueError will be raised. If +- sys.implementation.cache_tag is None then NotImplementedError is raised. ++ the .py file calculated to correspond to the .pyc/.pyo file. + + """ +- if sys.implementation.cache_tag is None: +- raise NotImplementedError('sys.implementation.cache_tag is None') +- head, pycache_filename = _path_split(path) +- head, pycache = _path_split(head) +- if pycache != _PYCACHE: +- raise ValueError('{} not bottom-level directory in ' +- '{!r}'.format(_PYCACHE, path)) +- if pycache_filename.count('.') != 2: +- raise ValueError('expected only 2 dots in ' +- '{!r}'.format(pycache_filename)) +- base_filename = pycache_filename.partition('.')[0] ++ head, filename = _path_split(path) ++ base_filename = filename.partition('.')[0] + return _path_join(head, base_filename + SOURCE_SUFFIXES[0]) + + |