0016-Add-importlib-fix-for-PEP-3147-issue.patch 4.3 KB

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