python-dataproperty: bump version to 0.17.0
[buildroot-gz.git] / package / python3 / 0016-Add-importlib-fix-for-PEP-3147-issue.patch
bloba3ab5702eab64df4b323ff6f7303f2b244a344e6
1 From 66c1baaf357f75591ee2f31966385b6eb96c8eb4 Mon Sep 17 00:00:00 2001
2 From: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
3 Date: Wed, 23 Dec 2015 11:46:14 +0100
4 Subject: [PATCH] Add importlib fix for PEP 3147 issue
6 Python 3 has a new standard for installing .pyc file, called PEP
7 3147. Unfortunately, this standard requires both the .py and .pyc
8 files to be installed for a Python module to be found. This is quite
9 annoying on space-constrained embedded systems, since the .py file is
10 technically not required for execution.
12 This patch changes cache_from_source() and source_from_cache() in
13 importlib to get rid of the "__pycache__" directory.
14 This effectively disables PEP 3147 for:
16 * The python standard library
17 * Packages built with distutils or setuptools
18 * Packages built with automake that use the `py-compile` helper
20 Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
21 ---
22 Lib/importlib/_bootstrap_external.py | 37 +++++-------------------------------
23 1 file changed, 5 insertions(+), 32 deletions(-)
25 diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
26 index 9788828..dfcc27e 100644
27 --- a/Lib/importlib/_bootstrap_external.py
28 +++ b/Lib/importlib/_bootstrap_external.py
29 @@ -258,8 +258,6 @@ def cache_from_source(path, debug_override=None, *, optimization=None):
30 a True value is the same as setting 'optimization' to the empty string
31 while a False value is equivalent to setting 'optimization' to '1'.
33 - If sys.implementation.cache_tag is None then NotImplementedError is raised.
35 """
36 if debug_override is not None:
37 _warnings.warn('the debug_override parameter is deprecated; use '
38 @@ -270,10 +268,7 @@ def cache_from_source(path, debug_override=None, *, optimization=None):
39 optimization = '' if debug_override else 1
40 head, tail = _path_split(path)
41 base, sep, rest = tail.rpartition('.')
42 - tag = sys.implementation.cache_tag
43 - if tag is None:
44 - raise NotImplementedError('sys.implementation.cache_tag is None')
45 - almost_filename = ''.join([(base if base else rest), sep, tag])
46 + almost_filename = ''.join([(base if base else rest)])
47 if optimization is None:
48 if sys.flags.optimize == 0:
49 optimization = ''
50 @@ -284,39 +279,17 @@ def cache_from_source(path, debug_override=None, *, optimization=None):
51 if not optimization.isalnum():
52 raise ValueError('{!r} is not alphanumeric'.format(optimization))
53 almost_filename = '{}.{}{}'.format(almost_filename, _OPT, optimization)
54 - return _path_join(head, _PYCACHE, almost_filename + BYTECODE_SUFFIXES[0])
55 + return _path_join(head, almost_filename + BYTECODE_SUFFIXES[0])
58 def source_from_cache(path):
59 """Given the path to a .pyc. file, return the path to its .py file.
61 The .pyc file does not need to exist; this simply returns the path to
62 - the .py file calculated to correspond to the .pyc file. If path does
63 - not conform to PEP 3147/488 format, ValueError will be raised. If
64 - sys.implementation.cache_tag is None then NotImplementedError is raised.
66 + the .py file calculated to correspond to the .pyc file.
67 """
68 - if sys.implementation.cache_tag is None:
69 - raise NotImplementedError('sys.implementation.cache_tag is None')
70 - head, pycache_filename = _path_split(path)
71 - head, pycache = _path_split(head)
72 - if pycache != _PYCACHE:
73 - raise ValueError('{} not bottom-level directory in '
74 - '{!r}'.format(_PYCACHE, path))
75 - dot_count = pycache_filename.count('.')
76 - if dot_count not in {2, 3}:
77 - raise ValueError('expected only 2 or 3 dots in '
78 - '{!r}'.format(pycache_filename))
79 - elif dot_count == 3:
80 - optimization = pycache_filename.rsplit('.', 2)[-2]
81 - if not optimization.startswith(_OPT):
82 - raise ValueError("optimization portion of filename does not start "
83 - "with {!r}".format(_OPT))
84 - opt_level = optimization[len(_OPT):]
85 - if not opt_level.isalnum():
86 - raise ValueError("optimization level {!r} is not an alphanumeric "
87 - "value".format(optimization))
88 - base_filename = pycache_filename.partition('.')[0]
89 + head, filename = _path_split(path)
90 + base_filename = filename.partition('.')[0]
91 return _path_join(head, base_filename + SOURCE_SUFFIXES[0])
94 --
95 2.7.4