Nuitka-winsvc 2.7.7__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Nuitka-winsvc might be problematic. Click here for more details.

Files changed (995) hide show
  1. nuitka/Builtins.py +259 -0
  2. nuitka/BytecodeCaching.py +184 -0
  3. nuitka/Bytecodes.py +109 -0
  4. nuitka/CacheCleanup.py +54 -0
  5. nuitka/Constants.py +425 -0
  6. nuitka/Errors.py +93 -0
  7. nuitka/HardImportRegistry.py +408 -0
  8. nuitka/MainControl.py +1201 -0
  9. nuitka/ModuleRegistry.py +364 -0
  10. nuitka/OptionParsing.py +2473 -0
  11. nuitka/Options.py +2948 -0
  12. nuitka/OutputDirectories.py +201 -0
  13. nuitka/PostProcessing.py +551 -0
  14. nuitka/Progress.py +252 -0
  15. nuitka/PythonFlavors.py +426 -0
  16. nuitka/PythonOperators.py +146 -0
  17. nuitka/PythonVersions.py +513 -0
  18. nuitka/Serialization.py +291 -0
  19. nuitka/SourceCodeReferences.py +176 -0
  20. nuitka/Tracing.py +579 -0
  21. nuitka/TreeXML.py +141 -0
  22. nuitka/Variables.py +515 -0
  23. nuitka/Version.py +88 -0
  24. nuitka/__init__.py +19 -0
  25. nuitka/__main__.py +224 -0
  26. nuitka/__past__.py +217 -0
  27. nuitka/build/Backend.scons +1111 -0
  28. nuitka/build/CCompilerVersion.scons +281 -0
  29. nuitka/build/DataComposerInterface.py +116 -0
  30. nuitka/build/Offsets.scons +626 -0
  31. nuitka/build/Onefile.scons +564 -0
  32. nuitka/build/SconsCaching.py +451 -0
  33. nuitka/build/SconsCompilerSettings.py +1133 -0
  34. nuitka/build/SconsHacks.py +215 -0
  35. nuitka/build/SconsInterface.py +664 -0
  36. nuitka/build/SconsProgress.py +100 -0
  37. nuitka/build/SconsSpawn.py +436 -0
  38. nuitka/build/SconsUtils.py +939 -0
  39. nuitka/build/__init__.py +19 -0
  40. nuitka/build/include/nuitka/allocator.h +450 -0
  41. nuitka/build/include/nuitka/builtins.h +97 -0
  42. nuitka/build/include/nuitka/calling.h +123 -0
  43. nuitka/build/include/nuitka/checkers.h +39 -0
  44. nuitka/build/include/nuitka/checksum_tools.h +28 -0
  45. nuitka/build/include/nuitka/compiled_asyncgen.h +281 -0
  46. nuitka/build/include/nuitka/compiled_cell.h +64 -0
  47. nuitka/build/include/nuitka/compiled_coroutine.h +271 -0
  48. nuitka/build/include/nuitka/compiled_frame.h +502 -0
  49. nuitka/build/include/nuitka/compiled_function.h +170 -0
  50. nuitka/build/include/nuitka/compiled_generator.h +287 -0
  51. nuitka/build/include/nuitka/compiled_method.h +54 -0
  52. nuitka/build/include/nuitka/constants.h +251 -0
  53. nuitka/build/include/nuitka/constants_blob.h +34 -0
  54. nuitka/build/include/nuitka/debug_settings.h +60 -0
  55. nuitka/build/include/nuitka/environment_variables.h +30 -0
  56. nuitka/build/include/nuitka/environment_variables_system.h +51 -0
  57. nuitka/build/include/nuitka/exception_groups.h +167 -0
  58. nuitka/build/include/nuitka/exceptions.h +1458 -0
  59. nuitka/build/include/nuitka/filesystem_paths.h +117 -0
  60. nuitka/build/include/nuitka/freelists.h +92 -0
  61. nuitka/build/include/nuitka/hedley.h +1774 -0
  62. nuitka/build/include/nuitka/helper/attributes.h +90 -0
  63. nuitka/build/include/nuitka/helper/boolean.h +86 -0
  64. nuitka/build/include/nuitka/helper/bytearrays.h +34 -0
  65. nuitka/build/include/nuitka/helper/bytes.h +28 -0
  66. nuitka/build/include/nuitka/helper/calling_generated.h +132 -0
  67. nuitka/build/include/nuitka/helper/comparisons_dual_eq.h +47 -0
  68. nuitka/build/include/nuitka/helper/comparisons_dual_ge.h +39 -0
  69. nuitka/build/include/nuitka/helper/comparisons_dual_gt.h +39 -0
  70. nuitka/build/include/nuitka/helper/comparisons_dual_le.h +47 -0
  71. nuitka/build/include/nuitka/helper/comparisons_dual_lt.h +47 -0
  72. nuitka/build/include/nuitka/helper/comparisons_dual_ne.h +39 -0
  73. nuitka/build/include/nuitka/helper/comparisons_eq.h +247 -0
  74. nuitka/build/include/nuitka/helper/comparisons_ge.h +197 -0
  75. nuitka/build/include/nuitka/helper/comparisons_gt.h +197 -0
  76. nuitka/build/include/nuitka/helper/comparisons_le.h +247 -0
  77. nuitka/build/include/nuitka/helper/comparisons_lt.h +247 -0
  78. nuitka/build/include/nuitka/helper/comparisons_ne.h +197 -0
  79. nuitka/build/include/nuitka/helper/complex.h +46 -0
  80. nuitka/build/include/nuitka/helper/dictionaries.h +481 -0
  81. nuitka/build/include/nuitka/helper/floats.h +32 -0
  82. nuitka/build/include/nuitka/helper/import_hard.h +121 -0
  83. nuitka/build/include/nuitka/helper/indexes.h +47 -0
  84. nuitka/build/include/nuitka/helper/ints.h +165 -0
  85. nuitka/build/include/nuitka/helper/iterators.h +376 -0
  86. nuitka/build/include/nuitka/helper/lists.h +94 -0
  87. nuitka/build/include/nuitka/helper/lists_generated.h +36 -0
  88. nuitka/build/include/nuitka/helper/mappings.h +39 -0
  89. nuitka/build/include/nuitka/helper/operations.h +114 -0
  90. nuitka/build/include/nuitka/helper/operations_binary_add.h +240 -0
  91. nuitka/build/include/nuitka/helper/operations_binary_bitand.h +108 -0
  92. nuitka/build/include/nuitka/helper/operations_binary_bitor.h +108 -0
  93. nuitka/build/include/nuitka/helper/operations_binary_bitxor.h +108 -0
  94. nuitka/build/include/nuitka/helper/operations_binary_divmod.h +103 -0
  95. nuitka/build/include/nuitka/helper/operations_binary_dual_add.h +34 -0
  96. nuitka/build/include/nuitka/helper/operations_binary_floordiv.h +103 -0
  97. nuitka/build/include/nuitka/helper/operations_binary_lshift.h +99 -0
  98. nuitka/build/include/nuitka/helper/operations_binary_matmult.h +60 -0
  99. nuitka/build/include/nuitka/helper/operations_binary_mod.h +304 -0
  100. nuitka/build/include/nuitka/helper/operations_binary_mult.h +247 -0
  101. nuitka/build/include/nuitka/helper/operations_binary_olddiv.h +125 -0
  102. nuitka/build/include/nuitka/helper/operations_binary_pow.h +90 -0
  103. nuitka/build/include/nuitka/helper/operations_binary_rshift.h +99 -0
  104. nuitka/build/include/nuitka/helper/operations_binary_sub.h +117 -0
  105. nuitka/build/include/nuitka/helper/operations_binary_truediv.h +103 -0
  106. nuitka/build/include/nuitka/helper/operations_builtin_types.h +247 -0
  107. nuitka/build/include/nuitka/helper/operations_inplace_add.h +173 -0
  108. nuitka/build/include/nuitka/helper/operations_inplace_bitand.h +76 -0
  109. nuitka/build/include/nuitka/helper/operations_inplace_bitor.h +76 -0
  110. nuitka/build/include/nuitka/helper/operations_inplace_bitxor.h +76 -0
  111. nuitka/build/include/nuitka/helper/operations_inplace_floordiv.h +95 -0
  112. nuitka/build/include/nuitka/helper/operations_inplace_lshift.h +62 -0
  113. nuitka/build/include/nuitka/helper/operations_inplace_matmult.h +60 -0
  114. nuitka/build/include/nuitka/helper/operations_inplace_mod.h +218 -0
  115. nuitka/build/include/nuitka/helper/operations_inplace_mult.h +184 -0
  116. nuitka/build/include/nuitka/helper/operations_inplace_olddiv.h +115 -0
  117. nuitka/build/include/nuitka/helper/operations_inplace_pow.h +87 -0
  118. nuitka/build/include/nuitka/helper/operations_inplace_rshift.h +62 -0
  119. nuitka/build/include/nuitka/helper/operations_inplace_sub.h +102 -0
  120. nuitka/build/include/nuitka/helper/operations_inplace_truediv.h +95 -0
  121. nuitka/build/include/nuitka/helper/raising.h +114 -0
  122. nuitka/build/include/nuitka/helper/rangeobjects.h +66 -0
  123. nuitka/build/include/nuitka/helper/richcomparisons.h +35 -0
  124. nuitka/build/include/nuitka/helper/sequences.h +33 -0
  125. nuitka/build/include/nuitka/helper/sets.h +25 -0
  126. nuitka/build/include/nuitka/helper/slices.h +314 -0
  127. nuitka/build/include/nuitka/helper/strings.h +30 -0
  128. nuitka/build/include/nuitka/helper/subscripts.h +390 -0
  129. nuitka/build/include/nuitka/helper/tuples.h +187 -0
  130. nuitka/build/include/nuitka/helpers.h +417 -0
  131. nuitka/build/include/nuitka/importing.h +149 -0
  132. nuitka/build/include/nuitka/incbin.h +402 -0
  133. nuitka/build/include/nuitka/jit_sources.h +25 -0
  134. nuitka/build/include/nuitka/prelude.h +626 -0
  135. nuitka/build/include/nuitka/printing.h +84 -0
  136. nuitka/build/include/nuitka/python_pgo.h +57 -0
  137. nuitka/build/include/nuitka/safe_string_ops.h +57 -0
  138. nuitka/build/include/nuitka/threading.h +142 -0
  139. nuitka/build/include/nuitka/tracing.h +82 -0
  140. nuitka/build/include/nuitka/type_aliases.h +30 -0
  141. nuitka/build/include/nuitka/unfreezing.h +91 -0
  142. nuitka/build/inline_copy/appdirs/LICENSE.txt +23 -0
  143. nuitka/build/inline_copy/appdirs/appdirs.py +611 -0
  144. nuitka/build/inline_copy/atomicwrites/LICENSE +19 -0
  145. nuitka/build/inline_copy/atomicwrites/atomicwrites.py +226 -0
  146. nuitka/build/inline_copy/bin/scons.py +58 -0
  147. nuitka/build/inline_copy/clcache/clcache/LICENSE +30 -0
  148. nuitka/build/inline_copy/clcache/clcache/__init__.py +4 -0
  149. nuitka/build/inline_copy/clcache/clcache/caching.py +2008 -0
  150. nuitka/build/inline_copy/colorama/LICENSE.txt +27 -0
  151. nuitka/build/inline_copy/colorama/colorama/__init__.py +6 -0
  152. nuitka/build/inline_copy/colorama/colorama/ansi.py +102 -0
  153. nuitka/build/inline_copy/colorama/colorama/ansitowin32.py +258 -0
  154. nuitka/build/inline_copy/colorama/colorama/initialise.py +80 -0
  155. nuitka/build/inline_copy/colorama/colorama/win32.py +152 -0
  156. nuitka/build/inline_copy/colorama/colorama/winterm.py +169 -0
  157. nuitka/build/inline_copy/glob2/LICENSE +27 -0
  158. nuitka/build/inline_copy/glob2/glob2/__init__.py +5 -0
  159. nuitka/build/inline_copy/glob2/glob2/compat.py +167 -0
  160. nuitka/build/inline_copy/glob2/glob2/fnmatch.py +141 -0
  161. nuitka/build/inline_copy/glob2/glob2/impl.py +216 -0
  162. nuitka/build/inline_copy/jinja2/LICENSE.rst +28 -0
  163. nuitka/build/inline_copy/jinja2/README.rst +2 -0
  164. nuitka/build/inline_copy/jinja2/jinja2/__init__.py +72 -0
  165. nuitka/build/inline_copy/jinja2/jinja2/_compat.py +105 -0
  166. nuitka/build/inline_copy/jinja2/jinja2/_identifier.py +2 -0
  167. nuitka/build/inline_copy/jinja2/jinja2/bccache.py +361 -0
  168. nuitka/build/inline_copy/jinja2/jinja2/compiler.py +1721 -0
  169. nuitka/build/inline_copy/jinja2/jinja2/constants.py +32 -0
  170. nuitka/build/inline_copy/jinja2/jinja2/debug.py +378 -0
  171. nuitka/build/inline_copy/jinja2/jinja2/defaults.py +56 -0
  172. nuitka/build/inline_copy/jinja2/jinja2/environment.py +1276 -0
  173. nuitka/build/inline_copy/jinja2/jinja2/exceptions.py +146 -0
  174. nuitka/build/inline_copy/jinja2/jinja2/ext.py +627 -0
  175. nuitka/build/inline_copy/jinja2/jinja2/filters.py +1190 -0
  176. nuitka/build/inline_copy/jinja2/jinja2/idtracking.py +286 -0
  177. nuitka/build/inline_copy/jinja2/jinja2/lexer.py +739 -0
  178. nuitka/build/inline_copy/jinja2/jinja2/loaders.py +483 -0
  179. nuitka/build/inline_copy/jinja2/jinja2/meta.py +106 -0
  180. nuitka/build/inline_copy/jinja2/jinja2/nativetypes.py +220 -0
  181. nuitka/build/inline_copy/jinja2/jinja2/nodes.py +999 -0
  182. nuitka/build/inline_copy/jinja2/jinja2/optimizer.py +49 -0
  183. nuitka/build/inline_copy/jinja2/jinja2/parser.py +903 -0
  184. nuitka/build/inline_copy/jinja2/jinja2/runtime.py +808 -0
  185. nuitka/build/inline_copy/jinja2/jinja2/sandbox.py +488 -0
  186. nuitka/build/inline_copy/jinja2/jinja2/tests.py +174 -0
  187. nuitka/build/inline_copy/jinja2/jinja2/utils.py +642 -0
  188. nuitka/build/inline_copy/jinja2/jinja2/visitor.py +87 -0
  189. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Action.py +1475 -0
  190. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Builder.py +905 -0
  191. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/CacheDir.py +314 -0
  192. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Conftest.py +805 -0
  193. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Debug.py +251 -0
  194. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Defaults.py +646 -0
  195. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Environment.py +2561 -0
  196. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/EnvironmentValues.py +119 -0
  197. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Errors.py +222 -0
  198. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Executor.py +660 -0
  199. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Job.py +439 -0
  200. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Memoize.py +242 -0
  201. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Node/Alias.py +176 -0
  202. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Node/FS.py +3861 -0
  203. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Node/Python.py +195 -0
  204. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Node/__init__.py +1784 -0
  205. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/PathList.py +224 -0
  206. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/__init__.py +341 -0
  207. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/aix.py +81 -0
  208. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/cygwin.py +61 -0
  209. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/darwin.py +70 -0
  210. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/hpux.py +45 -0
  211. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/irix.py +41 -0
  212. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/mingw.py +33 -0
  213. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/os2.py +55 -0
  214. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/posix.py +124 -0
  215. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/sunos.py +47 -0
  216. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/virtualenv.py +115 -0
  217. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Platform/win32.py +429 -0
  218. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/SConf.py +1119 -0
  219. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/SConsign.py +453 -0
  220. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Scanner/C.py +226 -0
  221. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Scanner/Dir.py +131 -0
  222. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Scanner/Prog.py +114 -0
  223. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Scanner/RC.py +57 -0
  224. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Scanner/__init__.py +436 -0
  225. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Script/Interactive.py +372 -0
  226. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Script/Main.py +1469 -0
  227. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Script/SConsOptions.py +1071 -0
  228. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Script/SConscript.py +686 -0
  229. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Script/__init__.py +425 -0
  230. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Subst.py +979 -0
  231. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Taskmaster.py +1062 -0
  232. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/386asm.py +61 -0
  233. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/GettextCommon.py +429 -0
  234. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/__init__.py +52 -0
  235. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/arch.py +66 -0
  236. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/common.py +371 -0
  237. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/netframework.py +83 -0
  238. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/sdk.py +411 -0
  239. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/vc.py +994 -0
  240. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/MSCommon/vs.py +608 -0
  241. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/PharLapCommon.py +116 -0
  242. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/__init__.py +882 -0
  243. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/aixc++.py +43 -0
  244. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/aixcc.py +74 -0
  245. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/aixcxx.py +77 -0
  246. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/aixlink.py +78 -0
  247. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/applelink.py +209 -0
  248. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/ar.py +63 -0
  249. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/as.py +49 -0
  250. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/asm.py +78 -0
  251. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/bcc32.py +81 -0
  252. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/c++.py +44 -0
  253. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/cc.py +105 -0
  254. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/clang.py +91 -0
  255. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/clangCommon/__init__.py +18 -0
  256. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/clangxx.py +99 -0
  257. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/cxx.py +95 -0
  258. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/cyglink.py +212 -0
  259. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/default.py +50 -0
  260. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/filesystem.py +98 -0
  261. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/g++.py +45 -0
  262. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/gas.py +56 -0
  263. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/gcc.py +110 -0
  264. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/gettext_tool.py +69 -0
  265. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/gnulink.py +70 -0
  266. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/gxx.py +78 -0
  267. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/hpc++.py +45 -0
  268. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/hpcc.py +53 -0
  269. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/hpcxx.py +88 -0
  270. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/hplink.py +72 -0
  271. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/icc.py +59 -0
  272. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/icl.py +52 -0
  273. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/ilink.py +55 -0
  274. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/ilink32.py +60 -0
  275. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/install.py +510 -0
  276. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/intelc.py +617 -0
  277. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/link.py +72 -0
  278. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/linkCommon/LoadableModule.py +131 -0
  279. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/linkCommon/SharedLibrary.py +218 -0
  280. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/linkCommon/__init__.py +171 -0
  281. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/linkloc.py +112 -0
  282. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/m4.py +63 -0
  283. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/masm.py +77 -0
  284. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mingw.py +232 -0
  285. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/msgfmt.py +132 -0
  286. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/msginit.py +137 -0
  287. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/msgmerge.py +125 -0
  288. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mslib.py +73 -0
  289. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mslink.py +339 -0
  290. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mssdk.py +50 -0
  291. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/msvc.py +325 -0
  292. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/msvs.py +2116 -0
  293. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mwcc.py +207 -0
  294. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/mwld.py +108 -0
  295. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/nasm.py +72 -0
  296. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/rmic.py +139 -0
  297. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/rpcgen.py +70 -0
  298. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sgiar.py +68 -0
  299. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sgic++.py +43 -0
  300. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sgicc.py +53 -0
  301. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sgicxx.py +61 -0
  302. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sgilink.py +59 -0
  303. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sunar.py +64 -0
  304. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sunc++.py +45 -0
  305. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/suncc.py +58 -0
  306. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/suncxx.py +153 -0
  307. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/sunlink.py +79 -0
  308. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/tar.py +73 -0
  309. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/textfile.py +198 -0
  310. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/tlib.py +53 -0
  311. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/wix.py +104 -0
  312. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/xgettext.py +337 -0
  313. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Tool/zip.py +120 -0
  314. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Util.py +2134 -0
  315. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Utilities/ConfigureCache.py +171 -0
  316. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Utilities/__init__.py +0 -0
  317. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Utilities/sconsign.py +494 -0
  318. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/BoolVariable.py +96 -0
  319. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/EnumVariable.py +110 -0
  320. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/ListVariable.py +152 -0
  321. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/PackageVariable.py +107 -0
  322. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/PathVariable.py +158 -0
  323. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Variables/__init__.py +334 -0
  324. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/Warnings.py +238 -0
  325. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/__init__.py +9 -0
  326. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/compat/__init__.py +104 -0
  327. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/compat/_scons_dbm.py +42 -0
  328. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/compat/win32.py +101 -0
  329. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/cpp.py +640 -0
  330. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/dblite.py +295 -0
  331. nuitka/build/inline_copy/lib/scons-4.3.0/SCons/exitfuncs.py +59 -0
  332. nuitka/build/inline_copy/markupsafe/LICENSE.rst +28 -0
  333. nuitka/build/inline_copy/markupsafe/markupsafe/__init__.py +327 -0
  334. nuitka/build/inline_copy/markupsafe/markupsafe/_compat.py +33 -0
  335. nuitka/build/inline_copy/markupsafe/markupsafe/_constants.py +264 -0
  336. nuitka/build/inline_copy/markupsafe/markupsafe/_native.py +69 -0
  337. nuitka/build/inline_copy/pefile/LICENSE.txt +21 -0
  338. nuitka/build/inline_copy/pefile/ordlookup/__init__.py +41 -0
  339. nuitka/build/inline_copy/pefile/ordlookup/oleaut32.py +400 -0
  340. nuitka/build/inline_copy/pefile/ordlookup/ws2_32.py +120 -0
  341. nuitka/build/inline_copy/pefile/pefile.py +8034 -0
  342. nuitka/build/inline_copy/pkg_resources/pkg_resources/__init__.py +3272 -0
  343. nuitka/build/inline_copy/pkg_resources/pkg_resources/py31compat.py +21 -0
  344. nuitka/build/inline_copy/python_hacl/LICENSE.txt +201 -0
  345. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_MD5.c +1430 -0
  346. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_MD5.h +66 -0
  347. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA1.c +463 -0
  348. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA1.h +66 -0
  349. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA2.c +1273 -0
  350. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA2.h +204 -0
  351. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA3.c +734 -0
  352. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Hash_SHA3.h +131 -0
  353. nuitka/build/inline_copy/python_hacl/hacl_312/Hacl_Streaming_Types.h +83 -0
  354. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/FStar_UInt128_Verified.h +346 -0
  355. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/FStar_UInt_8_16_32_64.h +107 -0
  356. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/fstar_uint128_struct_endianness.h +68 -0
  357. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/internal/target.h +293 -0
  358. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/lowstar_endianness.h +231 -0
  359. nuitka/build/inline_copy/python_hacl/hacl_312/include/krml/types.h +14 -0
  360. nuitka/build/inline_copy/python_hacl/hacl_312/internal/Hacl_Hash_MD5.h +56 -0
  361. nuitka/build/inline_copy/python_hacl/hacl_312/internal/Hacl_Hash_SHA1.h +56 -0
  362. nuitka/build/inline_copy/python_hacl/hacl_312/internal/Hacl_Hash_SHA2.h +164 -0
  363. nuitka/build/inline_copy/python_hacl/hacl_312/internal/Hacl_Hash_SHA3.h +65 -0
  364. nuitka/build/inline_copy/python_hacl/hacl_312/python_hacl_namespaces.h +89 -0
  365. nuitka/build/inline_copy/stubgen/astunparse.py +938 -0
  366. nuitka/build/inline_copy/stubgen/six.py +998 -0
  367. nuitka/build/inline_copy/stubgen/stubgen.py +484 -0
  368. nuitka/build/inline_copy/tqdm/tqdm/__init__.py +40 -0
  369. nuitka/build/inline_copy/tqdm/tqdm/_main.py +9 -0
  370. nuitka/build/inline_copy/tqdm/tqdm/_monitor.py +97 -0
  371. nuitka/build/inline_copy/tqdm/tqdm/_tqdm.py +9 -0
  372. nuitka/build/inline_copy/tqdm/tqdm/_tqdm_notebook.py +9 -0
  373. nuitka/build/inline_copy/tqdm/tqdm/_tqdm_pandas.py +24 -0
  374. nuitka/build/inline_copy/tqdm/tqdm/_utils.py +12 -0
  375. nuitka/build/inline_copy/tqdm/tqdm/auto.py +44 -0
  376. nuitka/build/inline_copy/tqdm/tqdm/autonotebook.py +28 -0
  377. nuitka/build/inline_copy/tqdm/tqdm/dask.py +46 -0
  378. nuitka/build/inline_copy/tqdm/tqdm/notebook.py +316 -0
  379. nuitka/build/inline_copy/tqdm/tqdm/std.py +1524 -0
  380. nuitka/build/inline_copy/tqdm/tqdm/tk.py +207 -0
  381. nuitka/build/inline_copy/tqdm/tqdm/utils.py +351 -0
  382. nuitka/build/inline_copy/tqdm/tqdm/version.py +2 -0
  383. nuitka/build/inline_copy/yaml/LICENSE +20 -0
  384. nuitka/build/inline_copy/yaml/yaml/__init__.py +427 -0
  385. nuitka/build/inline_copy/yaml/yaml/composer.py +139 -0
  386. nuitka/build/inline_copy/yaml/yaml/constructor.py +748 -0
  387. nuitka/build/inline_copy/yaml/yaml/cyaml.py +101 -0
  388. nuitka/build/inline_copy/yaml/yaml/dumper.py +62 -0
  389. nuitka/build/inline_copy/yaml/yaml/emitter.py +1137 -0
  390. nuitka/build/inline_copy/yaml/yaml/error.py +75 -0
  391. nuitka/build/inline_copy/yaml/yaml/events.py +86 -0
  392. nuitka/build/inline_copy/yaml/yaml/loader.py +63 -0
  393. nuitka/build/inline_copy/yaml/yaml/nodes.py +49 -0
  394. nuitka/build/inline_copy/yaml/yaml/parser.py +589 -0
  395. nuitka/build/inline_copy/yaml/yaml/reader.py +185 -0
  396. nuitka/build/inline_copy/yaml/yaml/representer.py +389 -0
  397. nuitka/build/inline_copy/yaml/yaml/resolver.py +227 -0
  398. nuitka/build/inline_copy/yaml/yaml/scanner.py +1435 -0
  399. nuitka/build/inline_copy/yaml/yaml/serializer.py +111 -0
  400. nuitka/build/inline_copy/yaml/yaml/tokens.py +104 -0
  401. nuitka/build/inline_copy/zlib/LICENSE +22 -0
  402. nuitka/build/inline_copy/zlib/crc32.c +1049 -0
  403. nuitka/build/inline_copy/zlib/crc32.h +9446 -0
  404. nuitka/build/inline_copy/zlib/zconf.h +551 -0
  405. nuitka/build/inline_copy/zlib/zlib.h +1938 -0
  406. nuitka/build/inline_copy/zlib/zutil.h +275 -0
  407. nuitka/build/inline_copy/zstd/LICENSE.txt +30 -0
  408. nuitka/build/inline_copy/zstd/common/bitstream.h +463 -0
  409. nuitka/build/inline_copy/zstd/common/compiler.h +288 -0
  410. nuitka/build/inline_copy/zstd/common/cpu.h +213 -0
  411. nuitka/build/inline_copy/zstd/common/debug.h +107 -0
  412. nuitka/build/inline_copy/zstd/common/entropy_common.c +360 -0
  413. nuitka/build/inline_copy/zstd/common/error_private.c +56 -0
  414. nuitka/build/inline_copy/zstd/common/error_private.h +80 -0
  415. nuitka/build/inline_copy/zstd/common/fse.h +715 -0
  416. nuitka/build/inline_copy/zstd/common/fse_decompress.c +393 -0
  417. nuitka/build/inline_copy/zstd/common/huf.h +361 -0
  418. nuitka/build/inline_copy/zstd/common/mem.h +426 -0
  419. nuitka/build/inline_copy/zstd/common/xxhash.c +826 -0
  420. nuitka/build/inline_copy/zstd/common/xxhash.h +285 -0
  421. nuitka/build/inline_copy/zstd/common/zstd_common.c +83 -0
  422. nuitka/build/inline_copy/zstd/common/zstd_deps.h +111 -0
  423. nuitka/build/inline_copy/zstd/common/zstd_errors.h +95 -0
  424. nuitka/build/inline_copy/zstd/common/zstd_internal.h +478 -0
  425. nuitka/build/inline_copy/zstd/decompress/huf_decompress.c +1350 -0
  426. nuitka/build/inline_copy/zstd/decompress/zstd_ddict.c +244 -0
  427. nuitka/build/inline_copy/zstd/decompress/zstd_ddict.h +44 -0
  428. nuitka/build/inline_copy/zstd/decompress/zstd_decompress.c +1930 -0
  429. nuitka/build/inline_copy/zstd/decompress/zstd_decompress_block.c +1540 -0
  430. nuitka/build/inline_copy/zstd/decompress/zstd_decompress_block.h +62 -0
  431. nuitka/build/inline_copy/zstd/decompress/zstd_decompress_internal.h +190 -0
  432. nuitka/build/inline_copy/zstd/zstd.h +2391 -0
  433. nuitka/build/static_src/CompiledAsyncgenType.c +2211 -0
  434. nuitka/build/static_src/CompiledCellType.c +300 -0
  435. nuitka/build/static_src/CompiledCodeHelpers.c +2160 -0
  436. nuitka/build/static_src/CompiledCoroutineType.c +1946 -0
  437. nuitka/build/static_src/CompiledFrameType.c +1337 -0
  438. nuitka/build/static_src/CompiledFunctionType.c +3320 -0
  439. nuitka/build/static_src/CompiledGeneratorType.c +1997 -0
  440. nuitka/build/static_src/CompiledGeneratorTypeUncompiledIntegration.c +2117 -0
  441. nuitka/build/static_src/CompiledMethodType.c +614 -0
  442. nuitka/build/static_src/GenerateHeadersMain.c +30 -0
  443. nuitka/build/static_src/HelpersAllocator.c +939 -0
  444. nuitka/build/static_src/HelpersAttributes.c +1241 -0
  445. nuitka/build/static_src/HelpersBuiltin.c +901 -0
  446. nuitka/build/static_src/HelpersBuiltinTypeMethods.c +3594 -0
  447. nuitka/build/static_src/HelpersBytes.c +107 -0
  448. nuitka/build/static_src/HelpersCalling.c +397 -0
  449. nuitka/build/static_src/HelpersCallingGenerated.c +14361 -0
  450. nuitka/build/static_src/HelpersChecksumTools.c +59 -0
  451. nuitka/build/static_src/HelpersClasses.c +91 -0
  452. nuitka/build/static_src/HelpersComparisonDualEq.c +183 -0
  453. nuitka/build/static_src/HelpersComparisonDualGe.c +121 -0
  454. nuitka/build/static_src/HelpersComparisonDualGt.c +121 -0
  455. nuitka/build/static_src/HelpersComparisonDualLe.c +183 -0
  456. nuitka/build/static_src/HelpersComparisonDualLt.c +183 -0
  457. nuitka/build/static_src/HelpersComparisonDualNe.c +121 -0
  458. nuitka/build/static_src/HelpersComparisonEq.c +12070 -0
  459. nuitka/build/static_src/HelpersComparisonEqUtils.c +169 -0
  460. nuitka/build/static_src/HelpersComparisonGe.c +11871 -0
  461. nuitka/build/static_src/HelpersComparisonGt.c +11855 -0
  462. nuitka/build/static_src/HelpersComparisonLe.c +11957 -0
  463. nuitka/build/static_src/HelpersComparisonLt.c +11941 -0
  464. nuitka/build/static_src/HelpersComparisonNe.c +11979 -0
  465. nuitka/build/static_src/HelpersConsole.c +124 -0
  466. nuitka/build/static_src/HelpersConstantsBlob.c +1487 -0
  467. nuitka/build/static_src/HelpersDeepcopy.c +636 -0
  468. nuitka/build/static_src/HelpersDictionaries.c +1739 -0
  469. nuitka/build/static_src/HelpersDictionariesGenerated.c +738 -0
  470. nuitka/build/static_src/HelpersDumpBacktraces.c +63 -0
  471. nuitka/build/static_src/HelpersEnvironmentVariables.c +65 -0
  472. nuitka/build/static_src/HelpersEnvironmentVariablesSystem.c +97 -0
  473. nuitka/build/static_src/HelpersExceptions.c +298 -0
  474. nuitka/build/static_src/HelpersFiles.c +353 -0
  475. nuitka/build/static_src/HelpersFilesystemPaths.c +1322 -0
  476. nuitka/build/static_src/HelpersFloats.c +92 -0
  477. nuitka/build/static_src/HelpersHeapStorage.c +68 -0
  478. nuitka/build/static_src/HelpersImport.c +506 -0
  479. nuitka/build/static_src/HelpersImportHard.c +526 -0
  480. nuitka/build/static_src/HelpersJitSources.c +48 -0
  481. nuitka/build/static_src/HelpersLists.c +899 -0
  482. nuitka/build/static_src/HelpersListsGenerated.c +564 -0
  483. nuitka/build/static_src/HelpersMappings.c +46 -0
  484. nuitka/build/static_src/HelpersMatching.c +192 -0
  485. nuitka/build/static_src/HelpersOperationBinaryAdd.c +6477 -0
  486. nuitka/build/static_src/HelpersOperationBinaryAddUtils.c +703 -0
  487. nuitka/build/static_src/HelpersOperationBinaryBitand.c +2738 -0
  488. nuitka/build/static_src/HelpersOperationBinaryBitor.c +2738 -0
  489. nuitka/build/static_src/HelpersOperationBinaryBitxor.c +2738 -0
  490. nuitka/build/static_src/HelpersOperationBinaryDivmod.c +2406 -0
  491. nuitka/build/static_src/HelpersOperationBinaryDivmodUtils.c +33 -0
  492. nuitka/build/static_src/HelpersOperationBinaryDualAdd.c +172 -0
  493. nuitka/build/static_src/HelpersOperationBinaryFloordiv.c +2422 -0
  494. nuitka/build/static_src/HelpersOperationBinaryInplaceAdd.c +220 -0
  495. nuitka/build/static_src/HelpersOperationBinaryLshift.c +2846 -0
  496. nuitka/build/static_src/HelpersOperationBinaryMatmult.c +453 -0
  497. nuitka/build/static_src/HelpersOperationBinaryMod.c +6549 -0
  498. nuitka/build/static_src/HelpersOperationBinaryMult.c +6438 -0
  499. nuitka/build/static_src/HelpersOperationBinaryMultUtils.c +125 -0
  500. nuitka/build/static_src/HelpersOperationBinaryOlddiv.c +2355 -0
  501. nuitka/build/static_src/HelpersOperationBinaryPow.c +2743 -0
  502. nuitka/build/static_src/HelpersOperationBinaryPowUtils.c +26 -0
  503. nuitka/build/static_src/HelpersOperationBinaryRshift.c +2706 -0
  504. nuitka/build/static_src/HelpersOperationBinarySub.c +2649 -0
  505. nuitka/build/static_src/HelpersOperationBinaryTruediv.c +2415 -0
  506. nuitka/build/static_src/HelpersOperationInplaceAdd.c +5211 -0
  507. nuitka/build/static_src/HelpersOperationInplaceAddUtils.c +144 -0
  508. nuitka/build/static_src/HelpersOperationInplaceBitand.c +1826 -0
  509. nuitka/build/static_src/HelpersOperationInplaceBitor.c +1826 -0
  510. nuitka/build/static_src/HelpersOperationInplaceBitxor.c +1826 -0
  511. nuitka/build/static_src/HelpersOperationInplaceFloordiv.c +2605 -0
  512. nuitka/build/static_src/HelpersOperationInplaceLshift.c +1594 -0
  513. nuitka/build/static_src/HelpersOperationInplaceMatmult.c +603 -0
  514. nuitka/build/static_src/HelpersOperationInplaceMod.c +4762 -0
  515. nuitka/build/static_src/HelpersOperationInplaceMult.c +4689 -0
  516. nuitka/build/static_src/HelpersOperationInplaceOlddiv.c +2553 -0
  517. nuitka/build/static_src/HelpersOperationInplacePow.c +2807 -0
  518. nuitka/build/static_src/HelpersOperationInplaceRshift.c +1534 -0
  519. nuitka/build/static_src/HelpersOperationInplaceSub.c +2894 -0
  520. nuitka/build/static_src/HelpersOperationInplaceTruediv.c +2612 -0
  521. nuitka/build/static_src/HelpersProfiling.c +104 -0
  522. nuitka/build/static_src/HelpersPythonPgo.c +113 -0
  523. nuitka/build/static_src/HelpersRaising.c +447 -0
  524. nuitka/build/static_src/HelpersSafeStrings.c +185 -0
  525. nuitka/build/static_src/HelpersSequences.c +134 -0
  526. nuitka/build/static_src/HelpersSlices.c +73 -0
  527. nuitka/build/static_src/HelpersStrings.c +998 -0
  528. nuitka/build/static_src/HelpersTuples.c +148 -0
  529. nuitka/build/static_src/HelpersTypes.c +329 -0
  530. nuitka/build/static_src/InspectPatcher.c +439 -0
  531. nuitka/build/static_src/MainProgram.c +2060 -0
  532. nuitka/build/static_src/MetaPathBasedLoader.c +2290 -0
  533. nuitka/build/static_src/MetaPathBasedLoaderImportlibMetadataDistribution.c +125 -0
  534. nuitka/build/static_src/MetaPathBasedLoaderResourceReader.c +158 -0
  535. nuitka/build/static_src/MetaPathBasedLoaderResourceReaderFiles.c +785 -0
  536. nuitka/build/static_src/OnefileBootstrap.c +1580 -0
  537. nuitka/build/static_src/OnefileSplashScreen.cpp +275 -0
  538. nuitka/code_generation/AsyncgenCodes.py +186 -0
  539. nuitka/code_generation/AttributeCodes.py +357 -0
  540. nuitka/code_generation/BinaryOperationHelperDefinitions.py +720 -0
  541. nuitka/code_generation/BranchCodes.py +67 -0
  542. nuitka/code_generation/BuiltinCodes.py +529 -0
  543. nuitka/code_generation/CallCodes.py +1186 -0
  544. nuitka/code_generation/ClassCodes.py +156 -0
  545. nuitka/code_generation/CodeGeneration.py +1078 -0
  546. nuitka/code_generation/CodeHelperSelection.py +81 -0
  547. nuitka/code_generation/CodeHelpers.py +455 -0
  548. nuitka/code_generation/CodeObjectCodes.py +165 -0
  549. nuitka/code_generation/ComparisonCodes.py +569 -0
  550. nuitka/code_generation/ComparisonHelperDefinitions.py +146 -0
  551. nuitka/code_generation/ConditionalCodes.py +236 -0
  552. nuitka/code_generation/ConstantCodes.py +243 -0
  553. nuitka/code_generation/Contexts.py +1248 -0
  554. nuitka/code_generation/CoroutineCodes.py +253 -0
  555. nuitka/code_generation/CtypesCodes.py +46 -0
  556. nuitka/code_generation/DictCodes.py +918 -0
  557. nuitka/code_generation/Emission.py +75 -0
  558. nuitka/code_generation/ErrorCodes.py +281 -0
  559. nuitka/code_generation/EvalCodes.py +444 -0
  560. nuitka/code_generation/ExceptionCodes.py +337 -0
  561. nuitka/code_generation/ExpressionCTypeSelectionHelpers.py +227 -0
  562. nuitka/code_generation/ExpressionCodes.py +61 -0
  563. nuitka/code_generation/FrameCodes.py +518 -0
  564. nuitka/code_generation/FunctionCodes.py +858 -0
  565. nuitka/code_generation/GeneratorCodes.py +218 -0
  566. nuitka/code_generation/GlobalConstants.py +249 -0
  567. nuitka/code_generation/GlobalsLocalsCodes.py +211 -0
  568. nuitka/code_generation/IdCodes.py +53 -0
  569. nuitka/code_generation/ImportCodes.py +468 -0
  570. nuitka/code_generation/Indentation.py +45 -0
  571. nuitka/code_generation/IndexCodes.py +50 -0
  572. nuitka/code_generation/InjectCCodes.py +28 -0
  573. nuitka/code_generation/IntegerCodes.py +110 -0
  574. nuitka/code_generation/IteratorCodes.py +378 -0
  575. nuitka/code_generation/JitCodes.py +44 -0
  576. nuitka/code_generation/LabelCodes.py +68 -0
  577. nuitka/code_generation/LineNumberCodes.py +91 -0
  578. nuitka/code_generation/ListCodes.py +502 -0
  579. nuitka/code_generation/LoaderCodes.py +193 -0
  580. nuitka/code_generation/LocalsDictCodes.py +359 -0
  581. nuitka/code_generation/LoopCodes.py +88 -0
  582. nuitka/code_generation/MatchCodes.py +67 -0
  583. nuitka/code_generation/ModuleCodes.py +247 -0
  584. nuitka/code_generation/Namify.py +260 -0
  585. nuitka/code_generation/NetworkxCodes.py +51 -0
  586. nuitka/code_generation/OperationCodes.py +398 -0
  587. nuitka/code_generation/PackageResourceCodes.py +986 -0
  588. nuitka/code_generation/PrintCodes.py +93 -0
  589. nuitka/code_generation/PythonAPICodes.py +215 -0
  590. nuitka/code_generation/RaisingCodes.py +481 -0
  591. nuitka/code_generation/Reports.py +115 -0
  592. nuitka/code_generation/ReturnCodes.py +143 -0
  593. nuitka/code_generation/SetCodes.py +196 -0
  594. nuitka/code_generation/SliceCodes.py +465 -0
  595. nuitka/code_generation/StringCodes.py +303 -0
  596. nuitka/code_generation/SubscriptCodes.py +263 -0
  597. nuitka/code_generation/TensorflowCodes.py +54 -0
  598. nuitka/code_generation/TryCodes.py +326 -0
  599. nuitka/code_generation/TupleCodes.py +115 -0
  600. nuitka/code_generation/TypeAliasCodes.py +120 -0
  601. nuitka/code_generation/VariableCodes.py +519 -0
  602. nuitka/code_generation/VariableDeclarations.py +279 -0
  603. nuitka/code_generation/YieldCodes.py +253 -0
  604. nuitka/code_generation/__init__.py +19 -0
  605. nuitka/code_generation/c_types/CTypeBases.py +177 -0
  606. nuitka/code_generation/c_types/CTypeBooleans.py +104 -0
  607. nuitka/code_generation/c_types/CTypeCFloats.py +57 -0
  608. nuitka/code_generation/c_types/CTypeCLongs.py +45 -0
  609. nuitka/code_generation/c_types/CTypeModuleDictVariables.py +109 -0
  610. nuitka/code_generation/c_types/CTypeNuitkaBooleans.py +150 -0
  611. nuitka/code_generation/c_types/CTypeNuitkaInts.py +200 -0
  612. nuitka/code_generation/c_types/CTypeNuitkaVoids.py +107 -0
  613. nuitka/code_generation/c_types/CTypePyObjectPointers.py +572 -0
  614. nuitka/code_generation/c_types/CTypeVoids.py +92 -0
  615. nuitka/code_generation/c_types/__init__.py +19 -0
  616. nuitka/code_generation/templates/CodeTemplatesAsyncgens.py +106 -0
  617. nuitka/code_generation/templates/CodeTemplatesConstants.py +296 -0
  618. nuitka/code_generation/templates/CodeTemplatesCoroutines.py +109 -0
  619. nuitka/code_generation/templates/CodeTemplatesExceptions.py +84 -0
  620. nuitka/code_generation/templates/CodeTemplatesFrames.py +235 -0
  621. nuitka/code_generation/templates/CodeTemplatesFunction.py +117 -0
  622. nuitka/code_generation/templates/CodeTemplatesGeneratorFunction.py +130 -0
  623. nuitka/code_generation/templates/CodeTemplatesIterators.py +40 -0
  624. nuitka/code_generation/templates/CodeTemplatesLoader.py +180 -0
  625. nuitka/code_generation/templates/CodeTemplatesModules.py +710 -0
  626. nuitka/code_generation/templates/CodeTemplatesVariables.py +388 -0
  627. nuitka/code_generation/templates/TemplateDebugWrapper.py +80 -0
  628. nuitka/code_generation/templates/__init__.py +19 -0
  629. nuitka/code_generation/templates_c/CodeTemplateCallsMethodPositional.c.j2 +321 -0
  630. nuitka/code_generation/templates_c/CodeTemplateCallsMixed.c.j2 +143 -0
  631. nuitka/code_generation/templates_c/CodeTemplateCallsPositional.c.j2 +677 -0
  632. nuitka/code_generation/templates_c/CodeTemplateCallsPositionalMethodDescr.c.j2 +165 -0
  633. nuitka/code_generation/templates_c/CodeTemplateMakeListHinted.c.j2 +38 -0
  634. nuitka/code_generation/templates_c/CodeTemplateMakeListSmall.c.j2 +41 -0
  635. nuitka/code_generation/templates_c/HelperBuiltinMethodOperation.c.j2 +53 -0
  636. nuitka/code_generation/templates_c/HelperDictionaryCopy.c.j2 +364 -0
  637. nuitka/code_generation/templates_c/HelperImportHard.c.j2 +37 -0
  638. nuitka/code_generation/templates_c/HelperLongTools.c.j2 +53 -0
  639. nuitka/code_generation/templates_c/HelperObjectTools.c.j2 +20 -0
  640. nuitka/code_generation/templates_c/HelperOperationBinary.c.j2 +148 -0
  641. nuitka/code_generation/templates_c/HelperOperationBinaryDual.c.j2 +115 -0
  642. nuitka/code_generation/templates_c/HelperOperationComparison.c.j2 +352 -0
  643. nuitka/code_generation/templates_c/HelperOperationComparisonBytes.c.j2 +115 -0
  644. nuitka/code_generation/templates_c/HelperOperationComparisonDual.c.j2 +86 -0
  645. nuitka/code_generation/templates_c/HelperOperationComparisonFloat.c.j2 +31 -0
  646. nuitka/code_generation/templates_c/HelperOperationComparisonInt.c.j2 +32 -0
  647. nuitka/code_generation/templates_c/HelperOperationComparisonList.c.j2 +112 -0
  648. nuitka/code_generation/templates_c/HelperOperationComparisonLong.c.j2 +157 -0
  649. nuitka/code_generation/templates_c/HelperOperationComparisonStr.c.j2 +115 -0
  650. nuitka/code_generation/templates_c/HelperOperationComparisonTuple.c.j2 +99 -0
  651. nuitka/code_generation/templates_c/HelperOperationComparisonUnicode.c.j2 +115 -0
  652. nuitka/code_generation/templates_c/HelperOperationInplace.c.j2 +281 -0
  653. nuitka/code_generation/templates_c/HelperSlotsBinary.c.j2 +420 -0
  654. nuitka/code_generation/templates_c/HelperSlotsBytes.c.j2 +51 -0
  655. nuitka/code_generation/templates_c/HelperSlotsCommon.c.j2 +71 -0
  656. nuitka/code_generation/templates_c/HelperSlotsFloat.c.j2 +327 -0
  657. nuitka/code_generation/templates_c/HelperSlotsInt.c.j2 +411 -0
  658. nuitka/code_generation/templates_c/HelperSlotsList.c.j2 +59 -0
  659. nuitka/code_generation/templates_c/HelperSlotsLong.c.j2 +229 -0
  660. nuitka/code_generation/templates_c/HelperSlotsSet.c.j2 +47 -0
  661. nuitka/code_generation/templates_c/HelperSlotsStr.c.j2 +55 -0
  662. nuitka/code_generation/templates_c/HelperSlotsTuple.c.j2 +58 -0
  663. nuitka/code_generation/templates_c/HelperSlotsUnicode.c.j2 +62 -0
  664. nuitka/containers/Namedtuples.py +51 -0
  665. nuitka/containers/OrderedDicts.py +191 -0
  666. nuitka/containers/OrderedSets.py +123 -0
  667. nuitka/containers/OrderedSetsFallback.py +139 -0
  668. nuitka/containers/__init__.py +19 -0
  669. nuitka/distutils/Build.py +76 -0
  670. nuitka/distutils/DistutilCommands.py +438 -0
  671. nuitka/distutils/__init__.py +19 -0
  672. nuitka/finalizations/Finalization.py +35 -0
  673. nuitka/finalizations/FinalizeMarkups.py +136 -0
  674. nuitka/finalizations/__init__.py +19 -0
  675. nuitka/freezer/DependsExe.py +257 -0
  676. nuitka/freezer/DllDependenciesCommon.py +97 -0
  677. nuitka/freezer/DllDependenciesMacOS.py +444 -0
  678. nuitka/freezer/DllDependenciesPosix.py +242 -0
  679. nuitka/freezer/DllDependenciesWin32.py +315 -0
  680. nuitka/freezer/ImportDetection.py +359 -0
  681. nuitka/freezer/IncludedDataFiles.py +689 -0
  682. nuitka/freezer/IncludedEntryPoints.py +376 -0
  683. nuitka/freezer/Onefile.py +296 -0
  684. nuitka/freezer/Standalone.py +520 -0
  685. nuitka/freezer/__init__.py +19 -0
  686. nuitka/importing/IgnoreListing.py +449 -0
  687. nuitka/importing/ImportCache.py +95 -0
  688. nuitka/importing/ImportResolving.py +186 -0
  689. nuitka/importing/Importing.py +1200 -0
  690. nuitka/importing/PreloadedPackages.py +164 -0
  691. nuitka/importing/Recursion.py +611 -0
  692. nuitka/importing/StandardLibrary.py +429 -0
  693. nuitka/importing/__init__.py +19 -0
  694. nuitka/nodes/AsyncgenNodes.py +107 -0
  695. nuitka/nodes/AttributeLookupNodes.py +124 -0
  696. nuitka/nodes/AttributeNodes.py +386 -0
  697. nuitka/nodes/AttributeNodesGenerated.py +10734 -0
  698. nuitka/nodes/BuiltinAllNodes.py +115 -0
  699. nuitka/nodes/BuiltinAnyNodes.py +124 -0
  700. nuitka/nodes/BuiltinComplexNodes.py +83 -0
  701. nuitka/nodes/BuiltinDecodingNodes.py +52 -0
  702. nuitka/nodes/BuiltinDecoratorNodes.py +85 -0
  703. nuitka/nodes/BuiltinDictNodes.py +140 -0
  704. nuitka/nodes/BuiltinFormatNodes.py +159 -0
  705. nuitka/nodes/BuiltinHashNodes.py +63 -0
  706. nuitka/nodes/BuiltinInputNodes.py +39 -0
  707. nuitka/nodes/BuiltinIntegerNodes.py +170 -0
  708. nuitka/nodes/BuiltinIteratorNodes.py +391 -0
  709. nuitka/nodes/BuiltinLenNodes.py +61 -0
  710. nuitka/nodes/BuiltinNextNodes.py +111 -0
  711. nuitka/nodes/BuiltinOpenNodes.py +148 -0
  712. nuitka/nodes/BuiltinOperationNodeBasesGenerated.py +7367 -0
  713. nuitka/nodes/BuiltinRangeNodes.py +690 -0
  714. nuitka/nodes/BuiltinRefNodes.py +314 -0
  715. nuitka/nodes/BuiltinSumNodes.py +104 -0
  716. nuitka/nodes/BuiltinTypeNodes.py +454 -0
  717. nuitka/nodes/BuiltinVarsNodes.py +44 -0
  718. nuitka/nodes/BytesNodes.py +829 -0
  719. nuitka/nodes/CallNodes.py +217 -0
  720. nuitka/nodes/Checkers.py +55 -0
  721. nuitka/nodes/ChildrenHavingMixins.py +21576 -0
  722. nuitka/nodes/ClassNodes.py +286 -0
  723. nuitka/nodes/CodeObjectSpecs.py +230 -0
  724. nuitka/nodes/ComparisonNodes.py +687 -0
  725. nuitka/nodes/ConditionalNodes.py +884 -0
  726. nuitka/nodes/ConstantRefNodes.py +1717 -0
  727. nuitka/nodes/ContainerMakingNodes.py +408 -0
  728. nuitka/nodes/ContainerOperationNodes.py +87 -0
  729. nuitka/nodes/CoroutineNodes.py +144 -0
  730. nuitka/nodes/CtypesNodes.py +51 -0
  731. nuitka/nodes/DictionaryNodes.py +1513 -0
  732. nuitka/nodes/ExceptionNodes.py +393 -0
  733. nuitka/nodes/ExecEvalNodes.py +229 -0
  734. nuitka/nodes/ExpressionBases.py +1301 -0
  735. nuitka/nodes/ExpressionBasesGenerated.py +2103 -0
  736. nuitka/nodes/ExpressionShapeMixins.py +886 -0
  737. nuitka/nodes/FrameNodes.py +413 -0
  738. nuitka/nodes/FunctionAttributeNodes.py +102 -0
  739. nuitka/nodes/FunctionNodes.py +1303 -0
  740. nuitka/nodes/FutureSpecs.py +224 -0
  741. nuitka/nodes/GeneratorNodes.py +201 -0
  742. nuitka/nodes/GlobalsLocalsNodes.py +209 -0
  743. nuitka/nodes/HardImportNodesGenerated.py +3599 -0
  744. nuitka/nodes/ImportHardNodes.py +185 -0
  745. nuitka/nodes/ImportNodes.py +1366 -0
  746. nuitka/nodes/IndicatorMixins.py +79 -0
  747. nuitka/nodes/InjectCNodes.py +51 -0
  748. nuitka/nodes/IterationHandles.py +407 -0
  749. nuitka/nodes/KeyValuePairNodes.py +378 -0
  750. nuitka/nodes/ListOperationNodes.py +525 -0
  751. nuitka/nodes/LocalsDictNodes.py +717 -0
  752. nuitka/nodes/LocalsScopes.py +505 -0
  753. nuitka/nodes/LoopNodes.py +445 -0
  754. nuitka/nodes/MatchNodes.py +60 -0
  755. nuitka/nodes/ModuleAttributeNodes.py +180 -0
  756. nuitka/nodes/ModuleNodes.py +1137 -0
  757. nuitka/nodes/NetworkxNodes.py +45 -0
  758. nuitka/nodes/NodeBases.py +890 -0
  759. nuitka/nodes/NodeMakingHelpers.py +481 -0
  760. nuitka/nodes/NodeMetaClasses.py +172 -0
  761. nuitka/nodes/OperatorNodes.py +944 -0
  762. nuitka/nodes/OperatorNodesUnary.py +403 -0
  763. nuitka/nodes/OsSysNodes.py +215 -0
  764. nuitka/nodes/OutlineNodes.py +372 -0
  765. nuitka/nodes/PackageMetadataNodes.py +982 -0
  766. nuitka/nodes/PackageResourceNodes.py +424 -0
  767. nuitka/nodes/PrintNodes.py +105 -0
  768. nuitka/nodes/ReturnNodes.py +255 -0
  769. nuitka/nodes/SideEffectNodes.py +139 -0
  770. nuitka/nodes/SliceNodes.py +386 -0
  771. nuitka/nodes/StatementBasesGenerated.py +3419 -0
  772. nuitka/nodes/StatementNodes.py +316 -0
  773. nuitka/nodes/StrNodes.py +919 -0
  774. nuitka/nodes/StringConcatenationNodes.py +103 -0
  775. nuitka/nodes/SubscriptNodes.py +245 -0
  776. nuitka/nodes/TensorflowNodes.py +38 -0
  777. nuitka/nodes/TryNodes.py +519 -0
  778. nuitka/nodes/TypeMatchNodes.py +65 -0
  779. nuitka/nodes/TypeNodes.py +390 -0
  780. nuitka/nodes/VariableAssignNodes.py +1177 -0
  781. nuitka/nodes/VariableDelNodes.py +320 -0
  782. nuitka/nodes/VariableNameNodes.py +153 -0
  783. nuitka/nodes/VariableRefNodes.py +895 -0
  784. nuitka/nodes/VariableReleaseNodes.py +153 -0
  785. nuitka/nodes/YieldNodes.py +121 -0
  786. nuitka/nodes/__init__.py +19 -0
  787. nuitka/nodes/shapes/BuiltinTypeShapes.py +4290 -0
  788. nuitka/nodes/shapes/ControlFlowDescriptions.py +199 -0
  789. nuitka/nodes/shapes/IteratorShapes.py +71 -0
  790. nuitka/nodes/shapes/ShapeMixins.py +255 -0
  791. nuitka/nodes/shapes/StandardShapes.py +1384 -0
  792. nuitka/nodes/shapes/__init__.py +19 -0
  793. nuitka/optimizations/BytecodeDemotion.py +105 -0
  794. nuitka/optimizations/FunctionInlining.py +110 -0
  795. nuitka/optimizations/Graphs.py +70 -0
  796. nuitka/optimizations/Optimization.py +363 -0
  797. nuitka/optimizations/OptimizeBuiltinCalls.py +1582 -0
  798. nuitka/optimizations/Tags.py +76 -0
  799. nuitka/optimizations/TraceCollections.py +1257 -0
  800. nuitka/optimizations/ValueTraces.py +980 -0
  801. nuitka/optimizations/__init__.py +19 -0
  802. nuitka/pgo/PGO.py +160 -0
  803. nuitka/pgo/__init__.py +19 -0
  804. nuitka/plugins/PluginBase.py +1924 -0
  805. nuitka/plugins/Plugins.py +2007 -0
  806. nuitka/plugins/YamlPluginBase.py +121 -0
  807. nuitka/plugins/__init__.py +19 -0
  808. nuitka/plugins/standard/AntiBloatPlugin.py +1024 -0
  809. nuitka/plugins/standard/ConsiderPyLintAnnotationsPlugin.py +95 -0
  810. nuitka/plugins/standard/DataFilesPlugin.py +311 -0
  811. nuitka/plugins/standard/DelvewheelPlugin.py +150 -0
  812. nuitka/plugins/standard/DillPlugin/DillPlugin.c +37 -0
  813. nuitka/plugins/standard/DillPlugin/cloudpickle-postLoad.py +67 -0
  814. nuitka/plugins/standard/DillPlugin/dill-postLoad.py +223 -0
  815. nuitka/plugins/standard/DillPlugin.py +137 -0
  816. nuitka/plugins/standard/DllFilesPlugin.py +527 -0
  817. nuitka/plugins/standard/EnumPlugin.py +64 -0
  818. nuitka/plugins/standard/EventletPlugin.py +57 -0
  819. nuitka/plugins/standard/GeventPlugin.py +64 -0
  820. nuitka/plugins/standard/GiPlugin.py +118 -0
  821. nuitka/plugins/standard/GlfwPlugin.py +138 -0
  822. nuitka/plugins/standard/ImplicitImports.py +845 -0
  823. nuitka/plugins/standard/KivyPlugin.py +141 -0
  824. nuitka/plugins/standard/MatplotlibPlugin.py +256 -0
  825. nuitka/plugins/standard/MultiprocessingPlugin.py +199 -0
  826. nuitka/plugins/standard/NumpyPlugin.py +35 -0
  827. nuitka/plugins/standard/OptionsNannyPlugin.py +158 -0
  828. nuitka/plugins/standard/PbrPlugin.py +62 -0
  829. nuitka/plugins/standard/PkgResourcesPlugin.py +162 -0
  830. nuitka/plugins/standard/PlaywrightPlugin.py +179 -0
  831. nuitka/plugins/standard/PmwPlugin.py +248 -0
  832. nuitka/plugins/standard/PySidePyQtPlugin.py +1666 -0
  833. nuitka/plugins/standard/PywebViewPlugin.py +81 -0
  834. nuitka/plugins/standard/SpacyPlugin.py +137 -0
  835. nuitka/plugins/standard/TensorflowPlugin.py +35 -0
  836. nuitka/plugins/standard/TkinterPlugin.py +416 -0
  837. nuitka/plugins/standard/TorchPlugin.py +35 -0
  838. nuitka/plugins/standard/TransformersPlugin.py +121 -0
  839. nuitka/plugins/standard/TrioPlugin.py +33 -0
  840. nuitka/plugins/standard/UpxPlugin.py +174 -0
  841. nuitka/plugins/standard/__init__.py +19 -0
  842. nuitka/plugins/standard/standard.nuitka-package.config.yml +9313 -0
  843. nuitka/plugins/standard/stdlib2.nuitka-package.config.yml +78 -0
  844. nuitka/plugins/standard/stdlib3.nuitka-package.config.yml +468 -0
  845. nuitka/reports/CompilationReportReader.py +83 -0
  846. nuitka/reports/LicenseReport.rst.j2 +41 -0
  847. nuitka/reports/Reports.py +961 -0
  848. nuitka/reports/__init__.py +19 -0
  849. nuitka/specs/BuiltinBytesOperationSpecs.py +180 -0
  850. nuitka/specs/BuiltinDictOperationSpecs.py +82 -0
  851. nuitka/specs/BuiltinListOperationSpecs.py +80 -0
  852. nuitka/specs/BuiltinParameterSpecs.py +831 -0
  853. nuitka/specs/BuiltinStrOperationSpecs.py +181 -0
  854. nuitka/specs/BuiltinTypeOperationSpecs.py +34 -0
  855. nuitka/specs/BuiltinUnicodeOperationSpecs.py +123 -0
  856. nuitka/specs/HardImportSpecs.py +236 -0
  857. nuitka/specs/ParameterSpecs.py +630 -0
  858. nuitka/specs/__init__.py +19 -0
  859. nuitka/tools/Basics.py +55 -0
  860. nuitka/tools/__init__.py +19 -0
  861. nuitka/tools/commercial/__init__.py +21 -0
  862. nuitka/tools/data_composer/DataComposer.py +593 -0
  863. nuitka/tools/data_composer/__init__.py +19 -0
  864. nuitka/tools/data_composer/__main__.py +41 -0
  865. nuitka/tools/environments/CreateEnvironment.py +69 -0
  866. nuitka/tools/environments/Virtualenv.py +158 -0
  867. nuitka/tools/environments/__init__.py +19 -0
  868. nuitka/tools/general/__init__.py +19 -0
  869. nuitka/tools/general/dll_report/__init__.py +19 -0
  870. nuitka/tools/general/dll_report/__main__.py +83 -0
  871. nuitka/tools/general/find_module/FindModuleCode.py +127 -0
  872. nuitka/tools/general/find_module/__init__.py +19 -0
  873. nuitka/tools/general/generate_header/GenerateHeader.py +73 -0
  874. nuitka/tools/general/generate_header/__init__.py +19 -0
  875. nuitka/tools/onefile_compressor/OnefileCompressor.py +390 -0
  876. nuitka/tools/onefile_compressor/__init__.py +19 -0
  877. nuitka/tools/onefile_compressor/__main__.py +41 -0
  878. nuitka/tools/podman/Podman.py +55 -0
  879. nuitka/tools/podman/__init__.py +19 -0
  880. nuitka/tools/podman/__main__.py +425 -0
  881. nuitka/tools/profiler/__init__.py +19 -0
  882. nuitka/tools/profiler/__main__.py +93 -0
  883. nuitka/tools/scanning/DisplayDistributions.py +39 -0
  884. nuitka/tools/scanning/DisplayPackageDLLs.py +151 -0
  885. nuitka/tools/scanning/DisplayPackageData.py +73 -0
  886. nuitka/tools/scanning/__init__.py +19 -0
  887. nuitka/tools/specialize/CTypeDescriptions.py +1928 -0
  888. nuitka/tools/specialize/Common.py +380 -0
  889. nuitka/tools/specialize/SpecializeC.py +1483 -0
  890. nuitka/tools/specialize/SpecializePython.py +1151 -0
  891. nuitka/tools/specialize/__init__.py +19 -0
  892. nuitka/tools/testing/Common.py +2007 -0
  893. nuitka/tools/testing/Constructs.py +53 -0
  894. nuitka/tools/testing/DocTests.py +156 -0
  895. nuitka/tools/testing/OutputComparison.py +313 -0
  896. nuitka/tools/testing/Pythons.py +34 -0
  897. nuitka/tools/testing/RuntimeTracing.py +260 -0
  898. nuitka/tools/testing/SearchModes.py +208 -0
  899. nuitka/tools/testing/Valgrind.py +103 -0
  900. nuitka/tools/testing/__init__.py +19 -0
  901. nuitka/tools/testing/check_reference_counts/__init__.py +19 -0
  902. nuitka/tools/testing/check_reference_counts/__main__.py +107 -0
  903. nuitka/tools/testing/compare_with_cpython/__init__.py +19 -0
  904. nuitka/tools/testing/compare_with_cpython/__main__.py +942 -0
  905. nuitka/tools/testing/find_sxs_modules/__init__.py +19 -0
  906. nuitka/tools/testing/find_sxs_modules/__main__.py +73 -0
  907. nuitka/tools/testing/measure_construct_performance/__init__.py +19 -0
  908. nuitka/tools/testing/measure_construct_performance/__main__.py +288 -0
  909. nuitka/tools/testing/run_nuitka_tests/__init__.py +19 -0
  910. nuitka/tools/testing/run_nuitka_tests/__main__.py +1091 -0
  911. nuitka/tools/watch/AutoStage.py +145 -0
  912. nuitka/tools/watch/Common.py +55 -0
  913. nuitka/tools/watch/Conda.py +125 -0
  914. nuitka/tools/watch/GitHub.py +113 -0
  915. nuitka/tools/watch/Pacman.py +73 -0
  916. nuitka/tools/watch/Pipenv.py +145 -0
  917. nuitka/tools/watch/__init__.py +19 -0
  918. nuitka/tools/watch/__main__.py +615 -0
  919. nuitka/tree/Building.py +1459 -0
  920. nuitka/tree/ComplexCallHelperFunctions.py +2150 -0
  921. nuitka/tree/Extractions.py +48 -0
  922. nuitka/tree/FutureSpecState.py +71 -0
  923. nuitka/tree/InternalModule.py +96 -0
  924. nuitka/tree/Operations.py +45 -0
  925. nuitka/tree/ReformulationAssertStatements.py +97 -0
  926. nuitka/tree/ReformulationAssignmentStatements.py +1260 -0
  927. nuitka/tree/ReformulationBooleanExpressions.py +97 -0
  928. nuitka/tree/ReformulationCallExpressions.py +314 -0
  929. nuitka/tree/ReformulationClasses.py +407 -0
  930. nuitka/tree/ReformulationClasses3.py +1149 -0
  931. nuitka/tree/ReformulationComparisonExpressions.py +174 -0
  932. nuitka/tree/ReformulationContractionExpressions.py +676 -0
  933. nuitka/tree/ReformulationDictionaryCreation.py +304 -0
  934. nuitka/tree/ReformulationExecStatements.py +386 -0
  935. nuitka/tree/ReformulationForLoopStatements.py +215 -0
  936. nuitka/tree/ReformulationFunctionStatements.py +931 -0
  937. nuitka/tree/ReformulationImportStatements.py +333 -0
  938. nuitka/tree/ReformulationLambdaExpressions.py +185 -0
  939. nuitka/tree/ReformulationMatchStatements.py +797 -0
  940. nuitka/tree/ReformulationMultidist.py +80 -0
  941. nuitka/tree/ReformulationNamespacePackages.py +239 -0
  942. nuitka/tree/ReformulationPrintStatements.py +127 -0
  943. nuitka/tree/ReformulationSequenceCreation.py +438 -0
  944. nuitka/tree/ReformulationSubscriptExpressions.py +123 -0
  945. nuitka/tree/ReformulationTryExceptStatements.py +418 -0
  946. nuitka/tree/ReformulationTryFinallyStatements.py +239 -0
  947. nuitka/tree/ReformulationWhileLoopStatements.py +160 -0
  948. nuitka/tree/ReformulationWithStatements.py +382 -0
  949. nuitka/tree/ReformulationYieldExpressions.py +133 -0
  950. nuitka/tree/SourceHandling.py +476 -0
  951. nuitka/tree/SyntaxErrors.py +143 -0
  952. nuitka/tree/TreeHelpers.py +720 -0
  953. nuitka/tree/VariableClosure.py +483 -0
  954. nuitka/tree/__init__.py +19 -0
  955. nuitka/utils/AppDirs.py +104 -0
  956. nuitka/utils/CStrings.py +208 -0
  957. nuitka/utils/CommandLineOptions.py +207 -0
  958. nuitka/utils/Distributions.py +728 -0
  959. nuitka/utils/Download.py +217 -0
  960. nuitka/utils/Execution.py +517 -0
  961. nuitka/utils/FileOperations.py +1587 -0
  962. nuitka/utils/Hashing.py +137 -0
  963. nuitka/utils/Images.py +79 -0
  964. nuitka/utils/Importing.py +335 -0
  965. nuitka/utils/InlineCopies.py +52 -0
  966. nuitka/utils/InstalledPythons.py +254 -0
  967. nuitka/utils/InstanceCounters.py +86 -0
  968. nuitka/utils/Jinja2.py +158 -0
  969. nuitka/utils/Json.py +40 -0
  970. nuitka/utils/MacOSApp.py +134 -0
  971. nuitka/utils/MemoryUsage.py +165 -0
  972. nuitka/utils/ModuleNames.py +317 -0
  973. nuitka/utils/PackageResources.py +44 -0
  974. nuitka/utils/ReExecute.py +152 -0
  975. nuitka/utils/Rest.py +60 -0
  976. nuitka/utils/SharedLibraries.py +1014 -0
  977. nuitka/utils/Shebang.py +113 -0
  978. nuitka/utils/Signing.py +144 -0
  979. nuitka/utils/SlotMetaClasses.py +57 -0
  980. nuitka/utils/StaticLibraries.py +260 -0
  981. nuitka/utils/ThreadedExecutor.py +87 -0
  982. nuitka/utils/Timing.py +102 -0
  983. nuitka/utils/Utils.py +483 -0
  984. nuitka/utils/WindowsFileUsage.py +337 -0
  985. nuitka/utils/WindowsResources.py +652 -0
  986. nuitka/utils/Yaml.py +247 -0
  987. nuitka/utils/__init__.py +19 -0
  988. nuitka_winsvc-2.7.7.data/scripts/nuitka-run.cmd +24 -0
  989. nuitka_winsvc-2.7.7.data/scripts/nuitka.cmd +30 -0
  990. nuitka_winsvc-2.7.7.dist-info/METADATA +115 -0
  991. nuitka_winsvc-2.7.7.dist-info/RECORD +995 -0
  992. nuitka_winsvc-2.7.7.dist-info/WHEEL +5 -0
  993. nuitka_winsvc-2.7.7.dist-info/entry_points.txt +7 -0
  994. nuitka_winsvc-2.7.7.dist-info/licenses/LICENSE.txt +202 -0
  995. nuitka_winsvc-2.7.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,3272 @@
1
+ # coding: utf-8
2
+ """
3
+ Package resource API
4
+ --------------------
5
+
6
+ A resource is a logical file contained within a package, or a logical
7
+ subdirectory thereof. The package resource API expects resource names
8
+ to have their path parts separated with ``/``, *not* whatever the local
9
+ path separator is. Do not use os.path operations to manipulate resource
10
+ names being passed into the API.
11
+
12
+ The package resource API is designed to work with normal filesystem packages,
13
+ .egg files, and unpacked .egg files. It can also work in a limited way with
14
+ .zip files and with custom PEP 302 loaders that support the ``get_data()``
15
+ method.
16
+ """
17
+
18
+ from __future__ import absolute_import
19
+
20
+ import sys
21
+ import os
22
+ import io
23
+ import time
24
+ import re
25
+ import types
26
+ import zipfile
27
+ import zipimport
28
+ import warnings
29
+ import stat
30
+ import functools
31
+ import pkgutil
32
+ import operator
33
+ import platform
34
+ import collections
35
+ import plistlib
36
+ import email.parser
37
+ import errno
38
+ import tempfile
39
+ import textwrap
40
+ import itertools
41
+ import inspect
42
+ import ntpath
43
+ import posixpath
44
+ from pkgutil import get_importer
45
+
46
+ try:
47
+ import _imp
48
+ except ImportError:
49
+ # Python 3.2 compatibility
50
+ import imp as _imp
51
+
52
+ try:
53
+ FileExistsError
54
+ except NameError:
55
+ FileExistsError = OSError
56
+
57
+ # Nuitka: Do not use six, we don't have these extern
58
+ # packages included.
59
+ # from pkg_resources.extern import six
60
+ # from pkg_resources.extern.six.moves import urllib, map, filter
61
+
62
+ # capture these to bypass sandboxing
63
+ from os import utime
64
+ try:
65
+ from os import mkdir, rename, unlink
66
+ WRITE_SUPPORT = True
67
+ except ImportError:
68
+ # no write support, probably under GAE
69
+ WRITE_SUPPORT = False
70
+
71
+ from os import open as os_open
72
+ from os.path import isdir, split
73
+
74
+ try:
75
+ import importlib.machinery as importlib_machinery
76
+ # access attribute to force import under delayed import mechanisms.
77
+ importlib_machinery.__name__
78
+ except ImportError:
79
+ importlib_machinery = None
80
+
81
+ from . import py31compat
82
+ # Nuitka: Do not use extern, we don't have these extern
83
+ # packages included.
84
+ # from pkg_resources.extern import appdirs
85
+ # from pkg_resources.extern import packaging
86
+ # __import__('pkg_resources.extern.packaging.version')
87
+ # __import__('pkg_resources.extern.packaging.specifiers')
88
+ # __import__('pkg_resources.extern.packaging.requirements')
89
+ # __import__('pkg_resources.extern.packaging.markers')
90
+
91
+
92
+
93
+ __metaclass__ = type
94
+
95
+
96
+ # Nuitka: For our Jinja2 purposes, 3.3 seems to work just fine.
97
+ if (3, 0) < sys.version_info < (3, 3):
98
+ raise RuntimeError("Python 3.4 or later is required")
99
+
100
+ if str is bytes:
101
+ # Those builtin exceptions are only defined in Python 3
102
+ PermissionError = None
103
+ NotADirectoryError = None
104
+
105
+ # declare some globals that will be defined later to
106
+ # satisfy the linters.
107
+ require = None
108
+ working_set = None
109
+ add_activation_listener = None
110
+ resources_stream = None
111
+ cleanup_resources = None
112
+ resource_dir = None
113
+ resource_stream = None
114
+ set_extraction_path = None
115
+ resource_isdir = None
116
+ resource_string = None
117
+ iter_entry_points = None
118
+ resource_listdir = None
119
+ resource_filename = None
120
+ resource_exists = None
121
+ _distribution_finders = None
122
+ _namespace_handlers = None
123
+ _namespace_packages = None
124
+
125
+
126
+ class PEP440Warning(RuntimeWarning):
127
+ """
128
+ Used when there is an issue with a version or specifier not complying with
129
+ PEP 440.
130
+ """
131
+
132
+
133
+ def parse_version(v):
134
+ try:
135
+ return packaging.version.Version(v)
136
+ except packaging.version.InvalidVersion:
137
+ return packaging.version.LegacyVersion(v)
138
+
139
+
140
+ _state_vars = {}
141
+
142
+
143
+ def _declare_state(vartype, **kw):
144
+ assert "sys" not in kw
145
+
146
+ globals().update(kw)
147
+ _state_vars.update(dict.fromkeys(kw, vartype))
148
+
149
+
150
+ def __getstate__():
151
+ state = {}
152
+ g = globals()
153
+ for k, v in _state_vars.items():
154
+ state[k] = g['_sget_' + v](g[k])
155
+ return state
156
+
157
+
158
+ def __setstate__(state):
159
+ g = globals()
160
+ for k, v in state.items():
161
+ g['_sset_' + _state_vars[k]](k, g[k], v)
162
+ return state
163
+
164
+
165
+ def _sget_dict(val):
166
+ return val.copy()
167
+
168
+
169
+ def _sset_dict(key, ob, state):
170
+ ob.clear()
171
+ ob.update(state)
172
+
173
+
174
+ def _sget_object(val):
175
+ return val.__getstate__()
176
+
177
+
178
+ def _sset_object(key, ob, state):
179
+ ob.__setstate__(state)
180
+
181
+
182
+ _sget_none = _sset_none = lambda *args: None
183
+
184
+
185
+ def get_supported_platform():
186
+ """Return this platform's maximum compatible version.
187
+
188
+ distutils.util.get_platform() normally reports the minimum version
189
+ of Mac OS X that would be required to *use* extensions produced by
190
+ distutils. But what we want when checking compatibility is to know the
191
+ version of Mac OS X that we are *running*. To allow usage of packages that
192
+ explicitly require a newer version of Mac OS X, we must also know the
193
+ current version of the OS.
194
+
195
+ If this condition occurs for any other platform with a version in its
196
+ platform strings, this function should be extended accordingly.
197
+ """
198
+ plat = get_build_platform()
199
+ m = macosVersionString.match(plat)
200
+ if m is not None and sys.platform == "darwin":
201
+ try:
202
+ plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
203
+ except ValueError:
204
+ # not Mac OS X
205
+ pass
206
+ return plat
207
+
208
+
209
+ __all__ = [
210
+ # Basic resource access and distribution/entry point discovery
211
+ 'require', 'run_script', 'get_provider', 'get_distribution',
212
+ 'load_entry_point', 'get_entry_map', 'get_entry_info',
213
+ 'iter_entry_points',
214
+ 'resource_string', 'resource_stream', 'resource_filename',
215
+ 'resource_listdir', 'resource_exists', 'resource_isdir',
216
+
217
+ # Environmental control
218
+ 'declare_namespace', 'working_set', 'add_activation_listener',
219
+ 'find_distributions', 'set_extraction_path', 'cleanup_resources',
220
+ 'get_default_cache',
221
+
222
+ # Primary implementation classes
223
+ 'Environment', 'WorkingSet', 'ResourceManager',
224
+ 'Distribution', 'Requirement', 'EntryPoint',
225
+
226
+ # Exceptions
227
+ 'ResolutionError', 'VersionConflict', 'DistributionNotFound',
228
+ 'UnknownExtra', 'ExtractionError',
229
+
230
+ # Warnings
231
+ 'PEP440Warning',
232
+
233
+ # Parsing functions and string utilities
234
+ 'parse_requirements', 'parse_version', 'safe_name', 'safe_version',
235
+ 'get_platform', 'compatible_platforms', 'yield_lines', 'split_sections',
236
+ 'safe_extra', 'to_filename', 'invalid_marker', 'evaluate_marker',
237
+
238
+ # filesystem utilities
239
+ 'ensure_directory', 'normalize_path',
240
+
241
+ # Distribution "precedence" constants
242
+ 'EGG_DIST', 'BINARY_DIST', 'SOURCE_DIST', 'CHECKOUT_DIST', 'DEVELOP_DIST',
243
+
244
+ # "Provider" interfaces, implementations, and registration/lookup APIs
245
+ 'IMetadataProvider', 'IResourceProvider', 'FileMetadata',
246
+ 'PathMetadata', 'EggMetadata', 'EmptyProvider', 'empty_provider',
247
+ 'NullProvider', 'EggProvider', 'DefaultProvider', 'ZipProvider',
248
+ 'register_finder', 'register_namespace_handler', 'register_loader_type',
249
+ 'fixup_namespace_packages', 'get_importer',
250
+
251
+ # Warnings
252
+ 'PkgResourcesDeprecationWarning',
253
+
254
+ # Deprecated/backward compatibility only
255
+ 'run_main', 'AvailableDistributions',
256
+ ]
257
+
258
+
259
+ class ResolutionError(Exception):
260
+ """Abstract base for dependency resolution errors"""
261
+
262
+ def __repr__(self):
263
+ return self.__class__.__name__ + repr(self.args)
264
+
265
+
266
+ class VersionConflict(ResolutionError):
267
+ """
268
+ An already-installed version conflicts with the requested version.
269
+
270
+ Should be initialized with the installed Distribution and the requested
271
+ Requirement.
272
+ """
273
+
274
+ _template = "{self.dist} is installed but {self.req} is required"
275
+
276
+ @property
277
+ def dist(self):
278
+ return self.args[0]
279
+
280
+ @property
281
+ def req(self):
282
+ return self.args[1]
283
+
284
+ def report(self):
285
+ return self._template.format(**locals())
286
+
287
+ def with_context(self, required_by):
288
+ """
289
+ If required_by is non-empty, return a version of self that is a
290
+ ContextualVersionConflict.
291
+ """
292
+ if not required_by:
293
+ return self
294
+ args = self.args + (required_by,)
295
+ return ContextualVersionConflict(*args)
296
+
297
+
298
+ class ContextualVersionConflict(VersionConflict):
299
+ """
300
+ A VersionConflict that accepts a third parameter, the set of the
301
+ requirements that required the installed Distribution.
302
+ """
303
+
304
+ _template = VersionConflict._template + ' by {self.required_by}'
305
+
306
+ @property
307
+ def required_by(self):
308
+ return self.args[2]
309
+
310
+
311
+ class DistributionNotFound(ResolutionError):
312
+ """A requested distribution was not found"""
313
+
314
+ _template = ("The '{self.req}' distribution was not found "
315
+ "and is required by {self.requirers_str}")
316
+
317
+ @property
318
+ def req(self):
319
+ return self.args[0]
320
+
321
+ @property
322
+ def requirers(self):
323
+ return self.args[1]
324
+
325
+ @property
326
+ def requirers_str(self):
327
+ if not self.requirers:
328
+ return 'the application'
329
+ return ', '.join(self.requirers)
330
+
331
+ def report(self):
332
+ return self._template.format(**locals())
333
+
334
+ def __str__(self):
335
+ return self.report()
336
+
337
+
338
+ class UnknownExtra(ResolutionError):
339
+ """Distribution doesn't have an "extra feature" of the given name"""
340
+
341
+
342
+ _provider_factories = {}
343
+
344
+ # Nuitka: That is to make it 2.6 compatible.
345
+ try:
346
+ PY_MAJOR = '{}.{}'.format(*sys.version_info)
347
+ except ValueError:
348
+ PY_MAHOR = '2.6'
349
+
350
+ EGG_DIST = 3
351
+ BINARY_DIST = 2
352
+ SOURCE_DIST = 1
353
+ CHECKOUT_DIST = 0
354
+ DEVELOP_DIST = -1
355
+
356
+
357
+ def register_loader_type(loader_type, provider_factory):
358
+ """Register `provider_factory` to make providers for `loader_type`
359
+
360
+ `loader_type` is the type or class of a PEP 302 ``module.__loader__``,
361
+ and `provider_factory` is a function that, passed a *module* object,
362
+ returns an ``IResourceProvider`` for that module.
363
+ """
364
+ _provider_factories[loader_type] = provider_factory
365
+
366
+
367
+ def get_provider(moduleOrReq):
368
+ """Return an IResourceProvider for the named module or requirement"""
369
+ # Nuitka: We don't need that
370
+ # if isinstance(moduleOrReq, Requirement):
371
+ # return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
372
+
373
+ # Nuitka: No idea why, but something can erase the globals sys.
374
+ import sys
375
+ try:
376
+ module = sys.modules[moduleOrReq]
377
+ except KeyError:
378
+ __import__(moduleOrReq)
379
+ module = sys.modules[moduleOrReq]
380
+ except AttributeError:
381
+ # For debugging
382
+ print(sys)
383
+ raise
384
+ loader = getattr(module, '__loader__', None)
385
+ return _find_adapter(_provider_factories, loader)(module)
386
+
387
+
388
+ def _macosx_vers(_cache=[]):
389
+ if not _cache:
390
+ version = platform.mac_ver()[0]
391
+ # fallback for MacPorts
392
+ if version == '':
393
+ plist = '/System/Library/CoreServices/SystemVersion.plist'
394
+ if os.path.exists(plist):
395
+ if hasattr(plistlib, 'readPlist'):
396
+ plist_content = plistlib.readPlist(plist)
397
+ if 'ProductVersion' in plist_content:
398
+ version = plist_content['ProductVersion']
399
+
400
+ _cache.append(version.split('.'))
401
+ return _cache[0]
402
+
403
+
404
+ def _macosx_arch(machine):
405
+ return {'PowerPC': 'ppc', 'Power_Macintosh': 'ppc'}.get(machine, machine)
406
+
407
+
408
+ def get_build_platform():
409
+ """Return this platform's string for platform-specific distributions
410
+
411
+ XXX Currently this is the same as ``distutils.util.get_platform()``, but it
412
+ needs some hacks for Linux and Mac OS X.
413
+ """
414
+ from sysconfig import get_platform
415
+
416
+ plat = get_platform()
417
+ if sys.platform == "darwin" and not plat.startswith('macosx-'):
418
+ try:
419
+ version = _macosx_vers()
420
+ machine = os.uname()[4].replace(" ", "_")
421
+ return "macosx-%d.%d-%s" % (
422
+ int(version[0]), int(version[1]),
423
+ _macosx_arch(machine),
424
+ )
425
+ except ValueError:
426
+ # if someone is running a non-Mac darwin system, this will fall
427
+ # through to the default implementation
428
+ pass
429
+ return plat
430
+
431
+
432
+ macosVersionString = re.compile(r"macosx-(\d+)\.(\d+)-(.*)")
433
+ darwinVersionString = re.compile(r"darwin-(\d+)\.(\d+)\.(\d+)-(.*)")
434
+ # XXX backward compat
435
+ get_platform = get_build_platform
436
+
437
+
438
+ def compatible_platforms(provided, required):
439
+ """Can code for the `provided` platform run on the `required` platform?
440
+
441
+ Returns true if either platform is ``None``, or the platforms are equal.
442
+
443
+ XXX Needs compatibility checks for Linux and other unixy OSes.
444
+ """
445
+ if provided is None or required is None or provided == required:
446
+ # easy case
447
+ return True
448
+
449
+ # Mac OS X special cases
450
+ reqMac = macosVersionString.match(required)
451
+ if reqMac:
452
+ provMac = macosVersionString.match(provided)
453
+
454
+ # is this a Mac package?
455
+ if not provMac:
456
+ # this is backwards compatibility for packages built before
457
+ # setuptools 0.6. All packages built after this point will
458
+ # use the new macosx designation.
459
+ provDarwin = darwinVersionString.match(provided)
460
+ if provDarwin:
461
+ dversion = int(provDarwin.group(1))
462
+ macosversion = "%s.%s" % (reqMac.group(1), reqMac.group(2))
463
+ if dversion == 7 and macosversion >= "10.3" or \
464
+ dversion == 8 and macosversion >= "10.4":
465
+ return True
466
+ # egg isn't macosx or legacy darwin
467
+ return False
468
+
469
+ # are they the same major version and machine type?
470
+ if provMac.group(1) != reqMac.group(1) or \
471
+ provMac.group(3) != reqMac.group(3):
472
+ return False
473
+
474
+ # is the required OS major update >= the provided one?
475
+ if int(provMac.group(2)) > int(reqMac.group(2)):
476
+ return False
477
+
478
+ return True
479
+
480
+ # XXX Linux and other platforms' special cases should go here
481
+ return False
482
+
483
+
484
+ def run_script(dist_spec, script_name):
485
+ """Locate distribution `dist_spec` and run its `script_name` script"""
486
+ # Nuitka: This seems to pollute globals
487
+ assert False
488
+
489
+ ns = sys._getframe(1).f_globals
490
+ name = ns['__name__']
491
+ ns.clear()
492
+ ns['__name__'] = name
493
+ require(dist_spec)[0].run_script(script_name, ns)
494
+
495
+
496
+ # backward compatibility
497
+ run_main = run_script
498
+
499
+
500
+ def get_distribution(dist):
501
+ """Return a current distribution object for a Requirement or string"""
502
+ if isinstance(dist, six.string_types):
503
+ dist = Requirement.parse(dist)
504
+ if isinstance(dist, Requirement):
505
+ dist = get_provider(dist)
506
+ if not isinstance(dist, Distribution):
507
+ raise TypeError("Expected string, Requirement, or Distribution", dist)
508
+ return dist
509
+
510
+
511
+ def load_entry_point(dist, group, name):
512
+ """Return `name` entry point of `group` for `dist` or raise ImportError"""
513
+ return get_distribution(dist).load_entry_point(group, name)
514
+
515
+
516
+ def get_entry_map(dist, group=None):
517
+ """Return the entry point map for `group`, or the full entry map"""
518
+ return get_distribution(dist).get_entry_map(group)
519
+
520
+
521
+ def get_entry_info(dist, group, name):
522
+ """Return the EntryPoint object for `group`+`name`, or ``None``"""
523
+ return get_distribution(dist).get_entry_info(group, name)
524
+
525
+
526
+ class IMetadataProvider:
527
+ def has_metadata(name):
528
+ """Does the package's distribution contain the named metadata?"""
529
+
530
+ def get_metadata(name):
531
+ """The named metadata resource as a string"""
532
+
533
+ def get_metadata_lines(name):
534
+ """Yield named metadata resource as list of non-blank non-comment lines
535
+
536
+ Leading and trailing whitespace is stripped from each line, and lines
537
+ with ``#`` as the first non-blank character are omitted."""
538
+
539
+ def metadata_isdir(name):
540
+ """Is the named metadata a directory? (like ``os.path.isdir()``)"""
541
+
542
+ def metadata_listdir(name):
543
+ """List of metadata names in the directory (like ``os.listdir()``)"""
544
+
545
+ def run_script(script_name, namespace):
546
+ """Execute the named script in the supplied namespace dictionary"""
547
+
548
+
549
+ class IResourceProvider(IMetadataProvider):
550
+ """An object that provides access to package resources"""
551
+
552
+ def get_resource_filename(manager, resource_name):
553
+ """Return a true filesystem path for `resource_name`
554
+
555
+ `manager` must be an ``IResourceManager``"""
556
+
557
+ def get_resource_stream(manager, resource_name):
558
+ """Return a readable file-like object for `resource_name`
559
+
560
+ `manager` must be an ``IResourceManager``"""
561
+
562
+ def get_resource_string(manager, resource_name):
563
+ """Return a string containing the contents of `resource_name`
564
+
565
+ `manager` must be an ``IResourceManager``"""
566
+
567
+ def has_resource(resource_name):
568
+ """Does the package contain the named resource?"""
569
+
570
+ def resource_isdir(resource_name):
571
+ """Is the named resource a directory? (like ``os.path.isdir()``)"""
572
+
573
+ def resource_listdir(resource_name):
574
+ """List of resource names in the directory (like ``os.listdir()``)"""
575
+
576
+
577
+ class WorkingSet:
578
+ """A collection of active distributions on sys.path (or a similar list)"""
579
+
580
+ def __init__(self, entries=None):
581
+ """Create working set from list of path entries (default=sys.path)"""
582
+ self.entries = []
583
+ self.entry_keys = {}
584
+ self.by_key = {}
585
+ self.callbacks = []
586
+
587
+ if entries is None:
588
+ entries = sys.path
589
+
590
+ for entry in entries:
591
+ self.add_entry(entry)
592
+
593
+ @classmethod
594
+ def _build_master(cls):
595
+ """
596
+ Prepare the master working set.
597
+ """
598
+ ws = cls()
599
+ try:
600
+ from __main__ import __requires__
601
+ except ImportError:
602
+ # The main program does not list any requirements
603
+ return ws
604
+
605
+ # ensure the requirements are met
606
+ try:
607
+ ws.require(__requires__)
608
+ except VersionConflict:
609
+ return cls._build_from_requirements(__requires__)
610
+
611
+ return ws
612
+
613
+ @classmethod
614
+ def _build_from_requirements(cls, req_spec):
615
+ """
616
+ Build a working set from a requirement spec. Rewrites sys.path.
617
+ """
618
+ # try it without defaults already on sys.path
619
+ # by starting with an empty path
620
+ ws = cls([])
621
+ reqs = parse_requirements(req_spec)
622
+ dists = ws.resolve(reqs, Environment())
623
+ for dist in dists:
624
+ ws.add(dist)
625
+
626
+ # add any missing entries from sys.path
627
+ for entry in sys.path:
628
+ if entry not in ws.entries:
629
+ ws.add_entry(entry)
630
+
631
+ # then copy back to sys.path
632
+ sys.path[:] = ws.entries
633
+ return ws
634
+
635
+ def add_entry(self, entry):
636
+ """Add a path item to ``.entries``, finding any distributions on it
637
+
638
+ ``find_distributions(entry, True)`` is used to find distributions
639
+ corresponding to the path entry, and they are added. `entry` is
640
+ always appended to ``.entries``, even if it is already present.
641
+ (This is because ``sys.path`` can contain the same value more than
642
+ once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
643
+ equal ``sys.path``.)
644
+ """
645
+ self.entry_keys.setdefault(entry, [])
646
+ self.entries.append(entry)
647
+ for dist in find_distributions(entry, True):
648
+ self.add(dist, entry, False)
649
+
650
+ def __contains__(self, dist):
651
+ """True if `dist` is the active distribution for its project"""
652
+ return self.by_key.get(dist.key) == dist
653
+
654
+ def find(self, req):
655
+ """Find a distribution matching requirement `req`
656
+
657
+ If there is an active distribution for the requested project, this
658
+ returns it as long as it meets the version requirement specified by
659
+ `req`. But, if there is an active distribution for the project and it
660
+ does *not* meet the `req` requirement, ``VersionConflict`` is raised.
661
+ If there is no active distribution for the requested project, ``None``
662
+ is returned.
663
+ """
664
+ dist = self.by_key.get(req.key)
665
+ if dist is not None and dist not in req:
666
+ # XXX add more info
667
+ raise VersionConflict(dist, req)
668
+ return dist
669
+
670
+ def iter_entry_points(self, group, name=None):
671
+ """Yield entry point objects from `group` matching `name`
672
+
673
+ If `name` is None, yields all entry points in `group` from all
674
+ distributions in the working set, otherwise only ones matching
675
+ both `group` and `name` are yielded (in distribution order).
676
+ """
677
+ return (
678
+ entry
679
+ for dist in self
680
+ for entry in dist.get_entry_map(group).values()
681
+ if name is None or name == entry.name
682
+ )
683
+
684
+ def run_script(self, requires, script_name):
685
+ """Locate distribution for `requires` and run `script_name` script"""
686
+ # Nuitka: This seems to pollute globals
687
+ assert False
688
+
689
+ ns = sys._getframe(1).f_globals
690
+ name = ns['__name__']
691
+ ns.clear()
692
+ ns['__name__'] = name
693
+ self.require(requires)[0].run_script(script_name, ns)
694
+
695
+ def __iter__(self):
696
+ """Yield distributions for non-duplicate projects in the working set
697
+
698
+ The yield order is the order in which the items' path entries were
699
+ added to the working set.
700
+ """
701
+ seen = {}
702
+ for item in self.entries:
703
+ if item not in self.entry_keys:
704
+ # workaround a cache issue
705
+ continue
706
+
707
+ for key in self.entry_keys[item]:
708
+ if key not in seen:
709
+ seen[key] = 1
710
+ yield self.by_key[key]
711
+
712
+ def add(self, dist, entry=None, insert=True, replace=False):
713
+ """Add `dist` to working set, associated with `entry`
714
+
715
+ If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
716
+ On exit from this routine, `entry` is added to the end of the working
717
+ set's ``.entries`` (if it wasn't already present).
718
+
719
+ `dist` is only added to the working set if it's for a project that
720
+ doesn't already have a distribution in the set, unless `replace=True`.
721
+ If it's added, any callbacks registered with the ``subscribe()`` method
722
+ will be called.
723
+ """
724
+ if insert:
725
+ dist.insert_on(self.entries, entry, replace=replace)
726
+
727
+ if entry is None:
728
+ entry = dist.location
729
+ keys = self.entry_keys.setdefault(entry, [])
730
+ keys2 = self.entry_keys.setdefault(dist.location, [])
731
+ if not replace and dist.key in self.by_key:
732
+ # ignore hidden distros
733
+ return
734
+
735
+ self.by_key[dist.key] = dist
736
+ if dist.key not in keys:
737
+ keys.append(dist.key)
738
+ if dist.key not in keys2:
739
+ keys2.append(dist.key)
740
+ self._added_new(dist)
741
+
742
+ def resolve(self, requirements, env=None, installer=None,
743
+ replace_conflicting=False, extras=None):
744
+ """List all distributions needed to (recursively) meet `requirements`
745
+
746
+ `requirements` must be a sequence of ``Requirement`` objects. `env`,
747
+ if supplied, should be an ``Environment`` instance. If
748
+ not supplied, it defaults to all distributions available within any
749
+ entry or distribution in the working set. `installer`, if supplied,
750
+ will be invoked with each requirement that cannot be met by an
751
+ already-installed distribution; it should return a ``Distribution`` or
752
+ ``None``.
753
+
754
+ Unless `replace_conflicting=True`, raises a VersionConflict exception
755
+ if
756
+ any requirements are found on the path that have the correct name but
757
+ the wrong version. Otherwise, if an `installer` is supplied it will be
758
+ invoked to obtain the correct version of the requirement and activate
759
+ it.
760
+
761
+ `extras` is a list of the extras to be used with these requirements.
762
+ This is important because extra requirements may look like `my_req;
763
+ extra = "my_extra"`, which would otherwise be interpreted as a purely
764
+ optional requirement. Instead, we want to be able to assert that these
765
+ requirements are truly required.
766
+ """
767
+
768
+ # set up the stack
769
+ requirements = list(requirements)[::-1]
770
+ # set of processed requirements
771
+ processed = {}
772
+ # key -> dist
773
+ best = {}
774
+ to_activate = []
775
+
776
+ req_extras = _ReqExtras()
777
+
778
+ # Mapping of requirement to set of distributions that required it;
779
+ # useful for reporting info about conflicts.
780
+ required_by = collections.defaultdict(set)
781
+
782
+ while requirements:
783
+ # process dependencies breadth-first
784
+ req = requirements.pop(0)
785
+ if req in processed:
786
+ # Ignore cyclic or redundant dependencies
787
+ continue
788
+
789
+ if not req_extras.markers_pass(req, extras):
790
+ continue
791
+
792
+ dist = best.get(req.key)
793
+ if dist is None:
794
+ # Find the best distribution and add it to the map
795
+ dist = self.by_key.get(req.key)
796
+ if dist is None or (dist not in req and replace_conflicting):
797
+ ws = self
798
+ if env is None:
799
+ if dist is None:
800
+ env = Environment(self.entries)
801
+ else:
802
+ # Use an empty environment and workingset to avoid
803
+ # any further conflicts with the conflicting
804
+ # distribution
805
+ env = Environment([])
806
+ ws = WorkingSet([])
807
+ dist = best[req.key] = env.best_match(
808
+ req, ws, installer,
809
+ replace_conflicting=replace_conflicting
810
+ )
811
+ if dist is None:
812
+ requirers = required_by.get(req, None)
813
+ raise DistributionNotFound(req, requirers)
814
+ to_activate.append(dist)
815
+ if dist not in req:
816
+ # Oops, the "best" so far conflicts with a dependency
817
+ dependent_req = required_by[req]
818
+ raise VersionConflict(dist, req).with_context(dependent_req)
819
+
820
+ # push the new requirements onto the stack
821
+ new_requirements = dist.requires(req.extras)[::-1]
822
+ requirements.extend(new_requirements)
823
+
824
+ # Register the new requirements needed by req
825
+ for new_requirement in new_requirements:
826
+ required_by[new_requirement].add(req.project_name)
827
+ req_extras[new_requirement] = req.extras
828
+
829
+ processed[req] = True
830
+
831
+ # return list of distros to activate
832
+ return to_activate
833
+
834
+ def find_plugins(
835
+ self, plugin_env, full_env=None, installer=None, fallback=True):
836
+ """Find all activatable distributions in `plugin_env`
837
+
838
+ Example usage::
839
+
840
+ distributions, errors = working_set.find_plugins(
841
+ Environment(plugin_dirlist)
842
+ )
843
+ # add plugins+libs to sys.path
844
+ map(working_set.add, distributions)
845
+ # display errors
846
+ print('Could not load', errors)
847
+
848
+ The `plugin_env` should be an ``Environment`` instance that contains
849
+ only distributions that are in the project's "plugin directory" or
850
+ directories. The `full_env`, if supplied, should be an ``Environment``
851
+ contains all currently-available distributions. If `full_env` is not
852
+ supplied, one is created automatically from the ``WorkingSet`` this
853
+ method is called on, which will typically mean that every directory on
854
+ ``sys.path`` will be scanned for distributions.
855
+
856
+ `installer` is a standard installer callback as used by the
857
+ ``resolve()`` method. The `fallback` flag indicates whether we should
858
+ attempt to resolve older versions of a plugin if the newest version
859
+ cannot be resolved.
860
+
861
+ This method returns a 2-tuple: (`distributions`, `error_info`), where
862
+ `distributions` is a list of the distributions found in `plugin_env`
863
+ that were loadable, along with any other distributions that are needed
864
+ to resolve their dependencies. `error_info` is a dictionary mapping
865
+ unloadable plugin distributions to an exception instance describing the
866
+ error that occurred. Usually this will be a ``DistributionNotFound`` or
867
+ ``VersionConflict`` instance.
868
+ """
869
+
870
+ plugin_projects = list(plugin_env)
871
+ # scan project names in alphabetic order
872
+ plugin_projects.sort()
873
+
874
+ error_info = {}
875
+ distributions = {}
876
+
877
+ if full_env is None:
878
+ env = Environment(self.entries)
879
+ env += plugin_env
880
+ else:
881
+ env = full_env + plugin_env
882
+
883
+ shadow_set = self.__class__([])
884
+ # put all our entries in shadow_set
885
+ list(map(shadow_set.add, self))
886
+
887
+ for project_name in plugin_projects:
888
+
889
+ for dist in plugin_env[project_name]:
890
+
891
+ req = [dist.as_requirement()]
892
+
893
+ try:
894
+ resolvees = shadow_set.resolve(req, env, installer)
895
+
896
+ except ResolutionError as v:
897
+ # save error info
898
+ error_info[dist] = v
899
+ if fallback:
900
+ # try the next older version of project
901
+ continue
902
+ else:
903
+ # give up on this project, keep going
904
+ break
905
+
906
+ else:
907
+ list(map(shadow_set.add, resolvees))
908
+ distributions.update(dict.fromkeys(resolvees))
909
+
910
+ # success, no need to try any more versions of this project
911
+ break
912
+
913
+ distributions = list(distributions)
914
+ distributions.sort()
915
+
916
+ return distributions, error_info
917
+
918
+ def require(self, *requirements):
919
+ """Ensure that distributions matching `requirements` are activated
920
+
921
+ `requirements` must be a string or a (possibly-nested) sequence
922
+ thereof, specifying the distributions and versions required. The
923
+ return value is a sequence of the distributions that needed to be
924
+ activated to fulfill the requirements; all relevant distributions are
925
+ included, even if they were already activated in this working set.
926
+ """
927
+ needed = self.resolve(parse_requirements(requirements))
928
+
929
+ for dist in needed:
930
+ self.add(dist)
931
+
932
+ return needed
933
+
934
+ def subscribe(self, callback, existing=True):
935
+ """Invoke `callback` for all distributions
936
+
937
+ If `existing=True` (default),
938
+ call on all existing ones, as well.
939
+ """
940
+ if callback in self.callbacks:
941
+ return
942
+ self.callbacks.append(callback)
943
+ if not existing:
944
+ return
945
+ for dist in self:
946
+ callback(dist)
947
+
948
+ def _added_new(self, dist):
949
+ for callback in self.callbacks:
950
+ callback(dist)
951
+
952
+ def __getstate__(self):
953
+ return (
954
+ self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
955
+ self.callbacks[:]
956
+ )
957
+
958
+ def __setstate__(self, e_k_b_c):
959
+ entries, keys, by_key, callbacks = e_k_b_c
960
+ self.entries = entries[:]
961
+ self.entry_keys = keys.copy()
962
+ self.by_key = by_key.copy()
963
+ self.callbacks = callbacks[:]
964
+
965
+
966
+ class _ReqExtras(dict):
967
+ """
968
+ Map each requirement to the extras that demanded it.
969
+ """
970
+
971
+ def markers_pass(self, req, extras=None):
972
+ """
973
+ Evaluate markers for req against each extra that
974
+ demanded it.
975
+
976
+ Return False if the req has a marker and fails
977
+ evaluation. Otherwise, return True.
978
+ """
979
+ extra_evals = (
980
+ req.marker.evaluate({'extra': extra})
981
+ for extra in self.get(req, ()) + (extras or (None,))
982
+ )
983
+ return not req.marker or any(extra_evals)
984
+
985
+
986
+ class Environment:
987
+ """Searchable snapshot of distributions on a search path"""
988
+
989
+ def __init__(
990
+ self, search_path=None, platform=get_supported_platform(),
991
+ python=PY_MAJOR):
992
+ """Snapshot distributions available on a search path
993
+
994
+ Any distributions found on `search_path` are added to the environment.
995
+ `search_path` should be a sequence of ``sys.path`` items. If not
996
+ supplied, ``sys.path`` is used.
997
+
998
+ `platform` is an optional string specifying the name of the platform
999
+ that platform-specific distributions must be compatible with. If
1000
+ unspecified, it defaults to the current platform. `python` is an
1001
+ optional string naming the desired version of Python (e.g. ``'3.6'``);
1002
+ it defaults to the current version.
1003
+
1004
+ You may explicitly set `platform` (and/or `python`) to ``None`` if you
1005
+ wish to map *all* distributions, not just those compatible with the
1006
+ running platform or Python version.
1007
+ """
1008
+ self._distmap = {}
1009
+ self.platform = platform
1010
+ self.python = python
1011
+ self.scan(search_path)
1012
+
1013
+ def can_add(self, dist):
1014
+ """Is distribution `dist` acceptable for this environment?
1015
+
1016
+ The distribution must match the platform and python version
1017
+ requirements specified when this environment was created, or False
1018
+ is returned.
1019
+ """
1020
+ py_compat = (
1021
+ self.python is None
1022
+ or dist.py_version is None
1023
+ or dist.py_version == self.python
1024
+ )
1025
+ return py_compat and compatible_platforms(dist.platform, self.platform)
1026
+
1027
+ def remove(self, dist):
1028
+ """Remove `dist` from the environment"""
1029
+ self._distmap[dist.key].remove(dist)
1030
+
1031
+ def scan(self, search_path=None):
1032
+ """Scan `search_path` for distributions usable in this environment
1033
+
1034
+ Any distributions found are added to the environment.
1035
+ `search_path` should be a sequence of ``sys.path`` items. If not
1036
+ supplied, ``sys.path`` is used. Only distributions conforming to
1037
+ the platform/python version defined at initialization are added.
1038
+ """
1039
+ if search_path is None:
1040
+ search_path = sys.path
1041
+
1042
+ for item in search_path:
1043
+ for dist in find_distributions(item):
1044
+ self.add(dist)
1045
+
1046
+ def __getitem__(self, project_name):
1047
+ """Return a newest-to-oldest list of distributions for `project_name`
1048
+
1049
+ Uses case-insensitive `project_name` comparison, assuming all the
1050
+ project's distributions use their project's name converted to all
1051
+ lowercase as their key.
1052
+
1053
+ """
1054
+ distribution_key = project_name.lower()
1055
+ return self._distmap.get(distribution_key, [])
1056
+
1057
+ def add(self, dist):
1058
+ """Add `dist` if we ``can_add()`` it and it has not already been added
1059
+ """
1060
+ if self.can_add(dist) and dist.has_version():
1061
+ dists = self._distmap.setdefault(dist.key, [])
1062
+ if dist not in dists:
1063
+ dists.append(dist)
1064
+ dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
1065
+
1066
+ def best_match(
1067
+ self, req, working_set, installer=None, replace_conflicting=False):
1068
+ """Find distribution best matching `req` and usable on `working_set`
1069
+
1070
+ This calls the ``find(req)`` method of the `working_set` to see if a
1071
+ suitable distribution is already active. (This may raise
1072
+ ``VersionConflict`` if an unsuitable version of the project is already
1073
+ active in the specified `working_set`.) If a suitable distribution
1074
+ isn't active, this method returns the newest distribution in the
1075
+ environment that meets the ``Requirement`` in `req`. If no suitable
1076
+ distribution is found, and `installer` is supplied, then the result of
1077
+ calling the environment's ``obtain(req, installer)`` method will be
1078
+ returned.
1079
+ """
1080
+ try:
1081
+ dist = working_set.find(req)
1082
+ except VersionConflict:
1083
+ if not replace_conflicting:
1084
+ raise
1085
+ dist = None
1086
+ if dist is not None:
1087
+ return dist
1088
+ for dist in self[req.key]:
1089
+ if dist in req:
1090
+ return dist
1091
+ # try to download/install
1092
+ return self.obtain(req, installer)
1093
+
1094
+ def obtain(self, requirement, installer=None):
1095
+ """Obtain a distribution matching `requirement` (e.g. via download)
1096
+
1097
+ Obtain a distro that matches requirement (e.g. via download). In the
1098
+ base ``Environment`` class, this routine just returns
1099
+ ``installer(requirement)``, unless `installer` is None, in which case
1100
+ None is returned instead. This method is a hook that allows subclasses
1101
+ to attempt other ways of obtaining a distribution before falling back
1102
+ to the `installer` argument."""
1103
+ if installer is not None:
1104
+ return installer(requirement)
1105
+
1106
+ def __iter__(self):
1107
+ """Yield the unique project names of the available distributions"""
1108
+ for key in self._distmap.keys():
1109
+ if self[key]:
1110
+ yield key
1111
+
1112
+ def __iadd__(self, other):
1113
+ """In-place addition of a distribution or environment"""
1114
+ if isinstance(other, Distribution):
1115
+ self.add(other)
1116
+ elif isinstance(other, Environment):
1117
+ for project in other:
1118
+ for dist in other[project]:
1119
+ self.add(dist)
1120
+ else:
1121
+ raise TypeError("Can't add %r to environment" % (other,))
1122
+ return self
1123
+
1124
+ def __add__(self, other):
1125
+ """Add an environment or distribution to an environment"""
1126
+ new = self.__class__([], platform=None, python=None)
1127
+ for env in self, other:
1128
+ new += env
1129
+ return new
1130
+
1131
+
1132
+ # XXX backward compatibility
1133
+ AvailableDistributions = Environment
1134
+
1135
+
1136
+ class ExtractionError(RuntimeError):
1137
+ """An error occurred extracting a resource
1138
+
1139
+ The following attributes are available from instances of this exception:
1140
+
1141
+ manager
1142
+ The resource manager that raised this exception
1143
+
1144
+ cache_path
1145
+ The base directory for resource extraction
1146
+
1147
+ original_error
1148
+ The exception instance that caused extraction to fail
1149
+ """
1150
+
1151
+
1152
+ class ResourceManager:
1153
+ """Manage resource extraction and packages"""
1154
+ extraction_path = None
1155
+
1156
+ def __init__(self):
1157
+ self.cached_files = {}
1158
+
1159
+ def resource_exists(self, package_or_requirement, resource_name):
1160
+ """Does the named resource exist?"""
1161
+ return get_provider(package_or_requirement).has_resource(resource_name)
1162
+
1163
+ def resource_isdir(self, package_or_requirement, resource_name):
1164
+ """Is the named resource an existing directory?"""
1165
+ return get_provider(package_or_requirement).resource_isdir(
1166
+ resource_name
1167
+ )
1168
+
1169
+ def resource_filename(self, package_or_requirement, resource_name):
1170
+ """Return a true filesystem path for specified resource"""
1171
+ return get_provider(package_or_requirement).get_resource_filename(
1172
+ self, resource_name
1173
+ )
1174
+
1175
+ def resource_stream(self, package_or_requirement, resource_name):
1176
+ """Return a readable file-like object for specified resource"""
1177
+ return get_provider(package_or_requirement).get_resource_stream(
1178
+ self, resource_name
1179
+ )
1180
+
1181
+ def resource_string(self, package_or_requirement, resource_name):
1182
+ """Return specified resource as a string"""
1183
+ return get_provider(package_or_requirement).get_resource_string(
1184
+ self, resource_name
1185
+ )
1186
+
1187
+ def resource_listdir(self, package_or_requirement, resource_name):
1188
+ """List the contents of the named resource directory"""
1189
+ return get_provider(package_or_requirement).resource_listdir(
1190
+ resource_name
1191
+ )
1192
+
1193
+ def extraction_error(self):
1194
+ """Give an error message for problems extracting file(s)"""
1195
+
1196
+ old_exc = sys.exc_info()[1]
1197
+ cache_path = self.extraction_path or get_default_cache()
1198
+
1199
+ tmpl = textwrap.dedent("""
1200
+ Can't extract file(s) to egg cache
1201
+
1202
+ The following error occurred while trying to extract file(s)
1203
+ to the Python egg cache:
1204
+
1205
+ {old_exc}
1206
+
1207
+ The Python egg cache directory is currently set to:
1208
+
1209
+ {cache_path}
1210
+
1211
+ Perhaps your account does not have write access to this directory?
1212
+ You can change the cache directory by setting the PYTHON_EGG_CACHE
1213
+ environment variable to point to an accessible directory.
1214
+ """).lstrip()
1215
+ err = ExtractionError(tmpl.format(**locals()))
1216
+ err.manager = self
1217
+ err.cache_path = cache_path
1218
+ err.original_error = old_exc
1219
+ raise err
1220
+
1221
+ def get_cache_path(self, archive_name, names=()):
1222
+ """Return absolute location in cache for `archive_name` and `names`
1223
+
1224
+ The parent directory of the resulting path will be created if it does
1225
+ not already exist. `archive_name` should be the base filename of the
1226
+ enclosing egg (which may not be the name of the enclosing zipfile!),
1227
+ including its ".egg" extension. `names`, if provided, should be a
1228
+ sequence of path name parts "under" the egg's extraction location.
1229
+
1230
+ This method should only be called by resource providers that need to
1231
+ obtain an extraction location, and only for names they intend to
1232
+ extract, as it tracks the generated names for possible cleanup later.
1233
+ """
1234
+ extract_path = self.extraction_path or get_default_cache()
1235
+ target_path = os.path.join(extract_path, archive_name + '-tmp', *names)
1236
+ try:
1237
+ _bypass_ensure_directory(target_path)
1238
+ except Exception:
1239
+ self.extraction_error()
1240
+
1241
+ self._warn_unsafe_extraction_path(extract_path)
1242
+
1243
+ self.cached_files[target_path] = 1
1244
+ return target_path
1245
+
1246
+ @staticmethod
1247
+ def _warn_unsafe_extraction_path(path):
1248
+ """
1249
+ If the default extraction path is overridden and set to an insecure
1250
+ location, such as /tmp, it opens up an opportunity for an attacker to
1251
+ replace an extracted file with an unauthorized payload. Warn the user
1252
+ if a known insecure location is used.
1253
+
1254
+ See Distribute #375 for more details.
1255
+ """
1256
+ if os.name == 'nt' and not path.startswith(os.environ['windir']):
1257
+ # On Windows, permissions are generally restrictive by default
1258
+ # and temp directories are not writable by other users, so
1259
+ # bypass the warning.
1260
+ return
1261
+ mode = os.stat(path).st_mode
1262
+ if mode & stat.S_IWOTH or mode & stat.S_IWGRP:
1263
+ msg = (
1264
+ "%s is writable by group/others and vulnerable to attack "
1265
+ "when "
1266
+ "used with get_resource_filename. Consider a more secure "
1267
+ "location (set with .set_extraction_path or the "
1268
+ "PYTHON_EGG_CACHE environment variable)." % path
1269
+ )
1270
+ warnings.warn(msg, UserWarning)
1271
+
1272
+ def postprocess(self, tempname, filename):
1273
+ """Perform any platform-specific postprocessing of `tempname`
1274
+
1275
+ This is where Mac header rewrites should be done; other platforms don't
1276
+ have anything special they should do.
1277
+
1278
+ Resource providers should call this method ONLY after successfully
1279
+ extracting a compressed resource. They must NOT call it on resources
1280
+ that are already in the filesystem.
1281
+
1282
+ `tempname` is the current (temporary) name of the file, and `filename`
1283
+ is the name it will be renamed to by the caller after this routine
1284
+ returns.
1285
+ """
1286
+
1287
+ if os.name == 'posix':
1288
+ # Make the resource executable
1289
+ mode = ((os.stat(tempname).st_mode) | 0o555) & 0o7777
1290
+ os.chmod(tempname, mode)
1291
+
1292
+ def set_extraction_path(self, path):
1293
+ """Set the base path where resources will be extracted to, if needed.
1294
+
1295
+ If you do not call this routine before any extractions take place, the
1296
+ path defaults to the return value of ``get_default_cache()``. (Which
1297
+ is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
1298
+ platform-specific fallbacks. See that routine's documentation for more
1299
+ details.)
1300
+
1301
+ Resources are extracted to subdirectories of this path based upon
1302
+ information given by the ``IResourceProvider``. You may set this to a
1303
+ temporary directory, but then you must call ``cleanup_resources()`` to
1304
+ delete the extracted files when done. There is no guarantee that
1305
+ ``cleanup_resources()`` will be able to remove all extracted files.
1306
+
1307
+ (Note: you may not change the extraction path for a given resource
1308
+ manager once resources have been extracted, unless you first call
1309
+ ``cleanup_resources()``.)
1310
+ """
1311
+ if self.cached_files:
1312
+ raise ValueError(
1313
+ "Can't change extraction path, files already extracted"
1314
+ )
1315
+
1316
+ self.extraction_path = path
1317
+
1318
+ def cleanup_resources(self, force=False):
1319
+ """
1320
+ Delete all extracted resource files and directories, returning a list
1321
+ of the file and directory names that could not be successfully removed.
1322
+ This function does not have any concurrency protection, so it should
1323
+ generally only be called when the extraction path is a temporary
1324
+ directory exclusive to a single process. This method is not
1325
+ automatically called; you must call it explicitly or register it as an
1326
+ ``atexit`` function if you wish to ensure cleanup of a temporary
1327
+ directory used for extractions.
1328
+ """
1329
+ # XXX
1330
+
1331
+
1332
+ def get_default_cache():
1333
+ """
1334
+ Return the ``PYTHON_EGG_CACHE`` environment variable
1335
+ or a platform-relevant user cache dir for an app
1336
+ named "Python-Eggs".
1337
+ """
1338
+ return (
1339
+ os.environ.get('PYTHON_EGG_CACHE')
1340
+ or appdirs.user_cache_dir(appname='Python-Eggs')
1341
+ )
1342
+
1343
+
1344
+ def safe_name(name):
1345
+ """Convert an arbitrary string to a standard distribution name
1346
+
1347
+ Any runs of non-alphanumeric/. characters are replaced with a single '-'.
1348
+ """
1349
+ return re.sub('[^A-Za-z0-9.]+', '-', name)
1350
+
1351
+
1352
+ def safe_version(version):
1353
+ """
1354
+ Convert an arbitrary string to a standard version string
1355
+ """
1356
+ try:
1357
+ # normalize the version
1358
+ return str(packaging.version.Version(version))
1359
+ except packaging.version.InvalidVersion:
1360
+ version = version.replace(' ', '.')
1361
+ return re.sub('[^A-Za-z0-9.]+', '-', version)
1362
+
1363
+
1364
+ def safe_extra(extra):
1365
+ """Convert an arbitrary string to a standard 'extra' name
1366
+
1367
+ Any runs of non-alphanumeric characters are replaced with a single '_',
1368
+ and the result is always lowercased.
1369
+ """
1370
+ return re.sub('[^A-Za-z0-9.-]+', '_', extra).lower()
1371
+
1372
+
1373
+ def to_filename(name):
1374
+ """Convert a project or version name to its filename-escaped form
1375
+
1376
+ Any '-' characters are currently replaced with '_'.
1377
+ """
1378
+ return name.replace('-', '_')
1379
+
1380
+
1381
+ def invalid_marker(text):
1382
+ """
1383
+ Validate text as a PEP 508 environment marker; return an exception
1384
+ if invalid or False otherwise.
1385
+ """
1386
+ try:
1387
+ evaluate_marker(text)
1388
+ except SyntaxError as e:
1389
+ e.filename = None
1390
+ e.lineno = None
1391
+ return e
1392
+ return False
1393
+
1394
+
1395
+ def evaluate_marker(text, extra=None):
1396
+ """
1397
+ Evaluate a PEP 508 environment marker.
1398
+ Return a boolean indicating the marker result in this environment.
1399
+ Raise SyntaxError if marker is invalid.
1400
+
1401
+ This implementation uses the 'pyparsing' module.
1402
+ """
1403
+ try:
1404
+ marker = packaging.markers.Marker(text)
1405
+ return marker.evaluate()
1406
+ except packaging.markers.InvalidMarker as e:
1407
+ raise SyntaxError(e)
1408
+
1409
+
1410
+ class NullProvider:
1411
+ """Try to implement resources and metadata for arbitrary PEP 302 loaders"""
1412
+
1413
+ egg_name = None
1414
+ egg_info = None
1415
+ loader = None
1416
+
1417
+ def __init__(self, module):
1418
+ self.loader = getattr(module, '__loader__', None)
1419
+ self.module_path = os.path.dirname(getattr(module, '__file__', ''))
1420
+
1421
+ def get_resource_filename(self, manager, resource_name):
1422
+ return self._fn(self.module_path, resource_name)
1423
+
1424
+ def get_resource_stream(self, manager, resource_name):
1425
+ return io.BytesIO(self.get_resource_string(manager, resource_name))
1426
+
1427
+ def get_resource_string(self, manager, resource_name):
1428
+ return self._get(self._fn(self.module_path, resource_name))
1429
+
1430
+ def has_resource(self, resource_name):
1431
+ return self._has(self._fn(self.module_path, resource_name))
1432
+
1433
+ def _get_metadata_path(self, name):
1434
+ return self._fn(self.egg_info, name)
1435
+
1436
+ def has_metadata(self, name):
1437
+ if not self.egg_info:
1438
+ return self.egg_info
1439
+
1440
+ path = self._get_metadata_path(name)
1441
+ return self._has(path)
1442
+
1443
+ def get_metadata(self, name):
1444
+ if not self.egg_info:
1445
+ return ""
1446
+ path = self._get_metadata_path(name)
1447
+ value = self._get(path)
1448
+ if six.PY2:
1449
+ return value
1450
+ try:
1451
+ return value.decode('utf-8')
1452
+ except UnicodeDecodeError as exc:
1453
+ # Include the path in the error message to simplify
1454
+ # troubleshooting, and without changing the exception type.
1455
+ exc.reason += ' in {} file at path: {}'.format(name, path)
1456
+ raise
1457
+
1458
+ def get_metadata_lines(self, name):
1459
+ return yield_lines(self.get_metadata(name))
1460
+
1461
+ def resource_isdir(self, resource_name):
1462
+ return self._isdir(self._fn(self.module_path, resource_name))
1463
+
1464
+ def metadata_isdir(self, name):
1465
+ return self.egg_info and self._isdir(self._fn(self.egg_info, name))
1466
+
1467
+ def resource_listdir(self, resource_name):
1468
+ return self._listdir(self._fn(self.module_path, resource_name))
1469
+
1470
+ def metadata_listdir(self, name):
1471
+ if self.egg_info:
1472
+ return self._listdir(self._fn(self.egg_info, name))
1473
+ return []
1474
+
1475
+ def run_script(self, script_name, namespace):
1476
+ script = 'scripts/' + script_name
1477
+ if not self.has_metadata(script):
1478
+ raise ResolutionError(
1479
+ "Script {script!r} not found in metadata at {self.egg_info!r}"
1480
+ .format(**locals()),
1481
+ )
1482
+ script_text = self.get_metadata(script).replace('\r\n', '\n')
1483
+ script_text = script_text.replace('\r', '\n')
1484
+ script_filename = self._fn(self.egg_info, script)
1485
+ namespace['__file__'] = script_filename
1486
+ if os.path.exists(script_filename):
1487
+ source = open(script_filename).read()
1488
+ code = compile(source, script_filename, 'exec')
1489
+ exec(code, namespace, namespace)
1490
+ else:
1491
+ from linecache import cache
1492
+ cache[script_filename] = (
1493
+ len(script_text), 0, script_text.split('\n'), script_filename
1494
+ )
1495
+ script_code = compile(script_text, script_filename, 'exec')
1496
+ exec(script_code, namespace, namespace)
1497
+
1498
+ def _has(self, path):
1499
+ raise NotImplementedError(
1500
+ "Can't perform this operation for unregistered loader type"
1501
+ )
1502
+
1503
+ def _isdir(self, path):
1504
+ raise NotImplementedError(
1505
+ "Can't perform this operation for unregistered loader type"
1506
+ )
1507
+
1508
+ def _listdir(self, path):
1509
+ raise NotImplementedError(
1510
+ "Can't perform this operation for unregistered loader type"
1511
+ )
1512
+
1513
+ def _fn(self, base, resource_name):
1514
+ self._validate_resource_path(resource_name)
1515
+ if resource_name:
1516
+ return os.path.join(base, *resource_name.split('/'))
1517
+ return base
1518
+
1519
+ @staticmethod
1520
+ def _validate_resource_path(path):
1521
+ """
1522
+ Validate the resource paths according to the docs.
1523
+ https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access
1524
+
1525
+ >>> warned = getfixture('recwarn')
1526
+ >>> warnings.simplefilter('always')
1527
+ >>> vrp = NullProvider._validate_resource_path
1528
+ >>> vrp('foo/bar.txt')
1529
+ >>> bool(warned)
1530
+ False
1531
+ >>> vrp('../foo/bar.txt')
1532
+ >>> bool(warned)
1533
+ True
1534
+ >>> warned.clear()
1535
+ >>> vrp('/foo/bar.txt')
1536
+ >>> bool(warned)
1537
+ True
1538
+ >>> vrp('foo/../../bar.txt')
1539
+ >>> bool(warned)
1540
+ True
1541
+ >>> warned.clear()
1542
+ >>> vrp('foo/f../bar.txt')
1543
+ >>> bool(warned)
1544
+ False
1545
+
1546
+ Windows path separators are straight-up disallowed.
1547
+ >>> vrp(r'\\foo/bar.txt')
1548
+ Traceback (most recent call last):
1549
+ ...
1550
+ ValueError: Use of .. or absolute path in a resource path \
1551
+ is not allowed.
1552
+
1553
+ >>> vrp(r'C:\\foo/bar.txt')
1554
+ Traceback (most recent call last):
1555
+ ...
1556
+ ValueError: Use of .. or absolute path in a resource path \
1557
+ is not allowed.
1558
+
1559
+ Blank values are allowed
1560
+
1561
+ >>> vrp('')
1562
+ >>> bool(warned)
1563
+ False
1564
+
1565
+ Non-string values are not.
1566
+
1567
+ >>> vrp(None)
1568
+ Traceback (most recent call last):
1569
+ ...
1570
+ AttributeError: ...
1571
+ """
1572
+ invalid = (
1573
+ os.path.pardir in path.split(posixpath.sep) or
1574
+ posixpath.isabs(path) or
1575
+ ntpath.isabs(path)
1576
+ )
1577
+ if not invalid:
1578
+ return
1579
+
1580
+ msg = "Use of .. or absolute path in a resource path is not allowed."
1581
+
1582
+ # Aggressively disallow Windows absolute paths
1583
+ if ntpath.isabs(path) and not posixpath.isabs(path):
1584
+ raise ValueError(msg)
1585
+
1586
+ # for compatibility, warn; in future
1587
+ # raise ValueError(msg)
1588
+ warnings.warn(
1589
+ msg[:-1] + " and will raise exceptions in a future release.",
1590
+ DeprecationWarning,
1591
+ stacklevel=4,
1592
+ )
1593
+
1594
+ def _get(self, path):
1595
+ if hasattr(self.loader, 'get_data'):
1596
+ return self.loader.get_data(path)
1597
+ raise NotImplementedError(
1598
+ "Can't perform this operation for loaders without 'get_data()'"
1599
+ )
1600
+
1601
+
1602
+ register_loader_type(object, NullProvider)
1603
+
1604
+
1605
+ class EggProvider(NullProvider):
1606
+ """Provider based on a virtual filesystem"""
1607
+
1608
+ def __init__(self, module):
1609
+ NullProvider.__init__(self, module)
1610
+ self._setup_prefix()
1611
+
1612
+ def _setup_prefix(self):
1613
+ # we assume here that our metadata may be nested inside a "basket"
1614
+ # of multiple eggs; that's why we use module_path instead of .archive
1615
+ path = self.module_path
1616
+ old = None
1617
+ while path != old:
1618
+ if _is_egg_path(path):
1619
+ self.egg_name = os.path.basename(path)
1620
+ self.egg_info = os.path.join(path, 'EGG-INFO')
1621
+ self.egg_root = path
1622
+ break
1623
+ old = path
1624
+ path, base = os.path.split(path)
1625
+
1626
+
1627
+ class DefaultProvider(EggProvider):
1628
+ """Provides access to package resources in the filesystem"""
1629
+
1630
+ def _has(self, path):
1631
+ return os.path.exists(path)
1632
+
1633
+ def _isdir(self, path):
1634
+ return os.path.isdir(path)
1635
+
1636
+ def _listdir(self, path):
1637
+ return os.listdir(path)
1638
+
1639
+ def get_resource_stream(self, manager, resource_name):
1640
+ return open(self._fn(self.module_path, resource_name), 'rb')
1641
+
1642
+ def _get(self, path):
1643
+ with open(path, 'rb') as stream:
1644
+ return stream.read()
1645
+
1646
+ @classmethod
1647
+ def _register(cls):
1648
+ loader_names = 'SourceFileLoader', 'SourcelessFileLoader',
1649
+ for name in loader_names:
1650
+ loader_cls = getattr(importlib_machinery, name, type(None))
1651
+ register_loader_type(loader_cls, cls)
1652
+
1653
+
1654
+ DefaultProvider._register()
1655
+
1656
+
1657
+ class EmptyProvider(NullProvider):
1658
+ """Provider that returns nothing for all requests"""
1659
+
1660
+ module_path = None
1661
+
1662
+ _isdir = _has = lambda self, path: False
1663
+
1664
+ def _get(self, path):
1665
+ return ''
1666
+
1667
+ def _listdir(self, path):
1668
+ return []
1669
+
1670
+ def __init__(self):
1671
+ pass
1672
+
1673
+
1674
+ empty_provider = EmptyProvider()
1675
+
1676
+
1677
+ class ZipManifests(dict):
1678
+ """
1679
+ zip manifest builder
1680
+ """
1681
+
1682
+ @classmethod
1683
+ def build(cls, path):
1684
+ """
1685
+ Build a dictionary similar to the zipimport directory
1686
+ caches, except instead of tuples, store ZipInfo objects.
1687
+
1688
+ Use a platform-specific path separator (os.sep) for the path keys
1689
+ for compatibility with pypy on Windows.
1690
+ """
1691
+ with zipfile.ZipFile(path) as zfile:
1692
+ items = (
1693
+ (
1694
+ name.replace('/', os.sep),
1695
+ zfile.getinfo(name),
1696
+ )
1697
+ for name in zfile.namelist()
1698
+ )
1699
+ return dict(items)
1700
+
1701
+ load = build
1702
+
1703
+
1704
+ class MemoizedZipManifests(ZipManifests):
1705
+ """
1706
+ Memoized zipfile manifests.
1707
+ """
1708
+ manifest_mod = collections.namedtuple('manifest_mod', 'manifest mtime')
1709
+
1710
+ def load(self, path):
1711
+ """
1712
+ Load a manifest at path or return a suitable manifest already loaded.
1713
+ """
1714
+ path = os.path.normpath(path)
1715
+ mtime = os.stat(path).st_mtime
1716
+
1717
+ if path not in self or self[path].mtime != mtime:
1718
+ manifest = self.build(path)
1719
+ self[path] = self.manifest_mod(manifest, mtime)
1720
+
1721
+ return self[path].manifest
1722
+
1723
+
1724
+ class ZipProvider(EggProvider):
1725
+ """Resource support for zips and eggs"""
1726
+
1727
+ eagers = None
1728
+ _zip_manifests = MemoizedZipManifests()
1729
+
1730
+ def __init__(self, module):
1731
+ EggProvider.__init__(self, module)
1732
+ self.zip_pre = self.loader.archive + os.sep
1733
+
1734
+ def _zipinfo_name(self, fspath):
1735
+ # Convert a virtual filename (full path to file) into a zipfile subpath
1736
+ # usable with the zipimport directory cache for our target archive
1737
+ fspath = fspath.rstrip(os.sep)
1738
+ if fspath == self.loader.archive:
1739
+ return ''
1740
+ if fspath.startswith(self.zip_pre):
1741
+ return fspath[len(self.zip_pre):]
1742
+ raise AssertionError(
1743
+ "%s is not a subpath of %s" % (fspath, self.zip_pre)
1744
+ )
1745
+
1746
+ def _parts(self, zip_path):
1747
+ # Convert a zipfile subpath into an egg-relative path part list.
1748
+ # pseudo-fs path
1749
+ fspath = self.zip_pre + zip_path
1750
+ if fspath.startswith(self.egg_root + os.sep):
1751
+ return fspath[len(self.egg_root) + 1:].split(os.sep)
1752
+ raise AssertionError(
1753
+ "%s is not a subpath of %s" % (fspath, self.egg_root)
1754
+ )
1755
+
1756
+ @property
1757
+ def zipinfo(self):
1758
+ return self._zip_manifests.load(self.loader.archive)
1759
+
1760
+ def get_resource_filename(self, manager, resource_name):
1761
+ if not self.egg_name:
1762
+ raise NotImplementedError(
1763
+ "resource_filename() only supported for .egg, not .zip"
1764
+ )
1765
+ # no need to lock for extraction, since we use temp names
1766
+ zip_path = self._resource_to_zip(resource_name)
1767
+ eagers = self._get_eager_resources()
1768
+ if '/'.join(self._parts(zip_path)) in eagers:
1769
+ for name in eagers:
1770
+ self._extract_resource(manager, self._eager_to_zip(name))
1771
+ return self._extract_resource(manager, zip_path)
1772
+
1773
+ @staticmethod
1774
+ def _get_date_and_size(zip_stat):
1775
+ size = zip_stat.file_size
1776
+ # ymdhms+wday, yday, dst
1777
+ date_time = zip_stat.date_time + (0, 0, -1)
1778
+ # 1980 offset already done
1779
+ timestamp = time.mktime(date_time)
1780
+ return timestamp, size
1781
+
1782
+ def _extract_resource(self, manager, zip_path):
1783
+
1784
+ if zip_path in self._index():
1785
+ for name in self._index()[zip_path]:
1786
+ last = self._extract_resource(
1787
+ manager, os.path.join(zip_path, name)
1788
+ )
1789
+ # return the extracted directory name
1790
+ return os.path.dirname(last)
1791
+
1792
+ timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
1793
+
1794
+ if not WRITE_SUPPORT:
1795
+ raise IOError('"os.rename" and "os.unlink" are not supported '
1796
+ 'on this platform')
1797
+ try:
1798
+
1799
+ real_path = manager.get_cache_path(
1800
+ self.egg_name, self._parts(zip_path)
1801
+ )
1802
+
1803
+ if self._is_current(real_path, zip_path):
1804
+ return real_path
1805
+
1806
+ outf, tmpnam = _mkstemp(
1807
+ ".$extract",
1808
+ dir=os.path.dirname(real_path),
1809
+ )
1810
+ os.write(outf, self.loader.get_data(zip_path))
1811
+ os.close(outf)
1812
+ utime(tmpnam, (timestamp, timestamp))
1813
+ manager.postprocess(tmpnam, real_path)
1814
+
1815
+ try:
1816
+ rename(tmpnam, real_path)
1817
+
1818
+ except os.error:
1819
+ if os.path.isfile(real_path):
1820
+ if self._is_current(real_path, zip_path):
1821
+ # the file became current since it was checked above,
1822
+ # so proceed.
1823
+ return real_path
1824
+ # Windows, del old file and retry
1825
+ elif os.name == 'nt':
1826
+ unlink(real_path)
1827
+ rename(tmpnam, real_path)
1828
+ return real_path
1829
+ raise
1830
+
1831
+ except os.error:
1832
+ # report a user-friendly error
1833
+ manager.extraction_error()
1834
+
1835
+ return real_path
1836
+
1837
+ def _is_current(self, file_path, zip_path):
1838
+ """
1839
+ Return True if the file_path is current for this zip_path
1840
+ """
1841
+ timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
1842
+ if not os.path.isfile(file_path):
1843
+ return False
1844
+ stat = os.stat(file_path)
1845
+ if stat.st_size != size or stat.st_mtime != timestamp:
1846
+ return False
1847
+ # check that the contents match
1848
+ zip_contents = self.loader.get_data(zip_path)
1849
+ with open(file_path, 'rb') as f:
1850
+ file_contents = f.read()
1851
+ return zip_contents == file_contents
1852
+
1853
+ def _get_eager_resources(self):
1854
+ if self.eagers is None:
1855
+ eagers = []
1856
+ for name in ('native_libs.txt', 'eager_resources.txt'):
1857
+ if self.has_metadata(name):
1858
+ eagers.extend(self.get_metadata_lines(name))
1859
+ self.eagers = eagers
1860
+ return self.eagers
1861
+
1862
+ def _index(self):
1863
+ try:
1864
+ return self._dirindex
1865
+ except AttributeError:
1866
+ ind = {}
1867
+ for path in self.zipinfo:
1868
+ parts = path.split(os.sep)
1869
+ while parts:
1870
+ parent = os.sep.join(parts[:-1])
1871
+ if parent in ind:
1872
+ ind[parent].append(parts[-1])
1873
+ break
1874
+ else:
1875
+ ind[parent] = [parts.pop()]
1876
+ self._dirindex = ind
1877
+ return ind
1878
+
1879
+ def _has(self, fspath):
1880
+ zip_path = self._zipinfo_name(fspath)
1881
+ return zip_path in self.zipinfo or zip_path in self._index()
1882
+
1883
+ def _isdir(self, fspath):
1884
+ return self._zipinfo_name(fspath) in self._index()
1885
+
1886
+ def _listdir(self, fspath):
1887
+ return list(self._index().get(self._zipinfo_name(fspath), ()))
1888
+
1889
+ def _eager_to_zip(self, resource_name):
1890
+ return self._zipinfo_name(self._fn(self.egg_root, resource_name))
1891
+
1892
+ def _resource_to_zip(self, resource_name):
1893
+ return self._zipinfo_name(self._fn(self.module_path, resource_name))
1894
+
1895
+
1896
+ register_loader_type(zipimport.zipimporter, ZipProvider)
1897
+
1898
+
1899
+ class FileMetadata(EmptyProvider):
1900
+ """Metadata handler for standalone PKG-INFO files
1901
+
1902
+ Usage::
1903
+
1904
+ metadata = FileMetadata("/path/to/PKG-INFO")
1905
+
1906
+ This provider rejects all data and metadata requests except for PKG-INFO,
1907
+ which is treated as existing, and will be the contents of the file at
1908
+ the provided location.
1909
+ """
1910
+
1911
+ def __init__(self, path):
1912
+ self.path = path
1913
+
1914
+ def _get_metadata_path(self, name):
1915
+ return self.path
1916
+
1917
+ def has_metadata(self, name):
1918
+ return name == 'PKG-INFO' and os.path.isfile(self.path)
1919
+
1920
+ def get_metadata(self, name):
1921
+ if name != 'PKG-INFO':
1922
+ raise KeyError("No metadata except PKG-INFO is available")
1923
+
1924
+ with io.open(self.path, encoding='utf-8', errors="replace") as f:
1925
+ metadata = f.read()
1926
+ self._warn_on_replacement(metadata)
1927
+ return metadata
1928
+
1929
+ def _warn_on_replacement(self, metadata):
1930
+ # Python 2.7 compat for: replacement_char = '�'
1931
+ replacement_char = b'\xef\xbf\xbd'.decode('utf-8')
1932
+ if replacement_char in metadata:
1933
+ tmpl = "{self.path} could not be properly decoded in UTF-8"
1934
+ msg = tmpl.format(**locals())
1935
+ warnings.warn(msg)
1936
+
1937
+ def get_metadata_lines(self, name):
1938
+ return yield_lines(self.get_metadata(name))
1939
+
1940
+
1941
+ class PathMetadata(DefaultProvider):
1942
+ """Metadata provider for egg directories
1943
+
1944
+ Usage::
1945
+
1946
+ # Development eggs:
1947
+
1948
+ egg_info = "/path/to/PackageName.egg-info"
1949
+ base_dir = os.path.dirname(egg_info)
1950
+ metadata = PathMetadata(base_dir, egg_info)
1951
+ dist_name = os.path.splitext(os.path.basename(egg_info))[0]
1952
+ dist = Distribution(basedir, project_name=dist_name, metadata=metadata)
1953
+
1954
+ # Unpacked egg directories:
1955
+
1956
+ egg_path = "/path/to/PackageName-ver-pyver-etc.egg"
1957
+ metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO'))
1958
+ dist = Distribution.from_filename(egg_path, metadata=metadata)
1959
+ """
1960
+
1961
+ def __init__(self, path, egg_info):
1962
+ self.module_path = path
1963
+ self.egg_info = egg_info
1964
+
1965
+
1966
+ class EggMetadata(ZipProvider):
1967
+ """Metadata provider for .egg files"""
1968
+
1969
+ def __init__(self, importer):
1970
+ """Create a metadata provider from a zipimporter"""
1971
+
1972
+ self.zip_pre = importer.archive + os.sep
1973
+ self.loader = importer
1974
+ if importer.prefix:
1975
+ self.module_path = os.path.join(importer.archive, importer.prefix)
1976
+ else:
1977
+ self.module_path = importer.archive
1978
+ self._setup_prefix()
1979
+
1980
+
1981
+ _declare_state('dict', _distribution_finders={})
1982
+
1983
+
1984
+ def register_finder(importer_type, distribution_finder):
1985
+ """Register `distribution_finder` to find distributions in sys.path items
1986
+
1987
+ `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
1988
+ handler), and `distribution_finder` is a callable that, passed a path
1989
+ item and the importer instance, yields ``Distribution`` instances found on
1990
+ that path item. See ``pkg_resources.find_on_path`` for an example."""
1991
+ _distribution_finders[importer_type] = distribution_finder
1992
+
1993
+
1994
+ def find_distributions(path_item, only=False):
1995
+ """Yield distributions accessible via `path_item`"""
1996
+ importer = get_importer(path_item)
1997
+ finder = _find_adapter(_distribution_finders, importer)
1998
+ return finder(importer, path_item, only)
1999
+
2000
+
2001
+ def find_eggs_in_zip(importer, path_item, only=False):
2002
+ """
2003
+ Find eggs in zip files; possibly multiple nested eggs.
2004
+ """
2005
+ if importer.archive.endswith('.whl'):
2006
+ # wheels are not supported with this finder
2007
+ # they don't have PKG-INFO metadata, and won't ever contain eggs
2008
+ return
2009
+ metadata = EggMetadata(importer)
2010
+ if metadata.has_metadata('PKG-INFO'):
2011
+ yield Distribution.from_filename(path_item, metadata=metadata)
2012
+ if only:
2013
+ # don't yield nested distros
2014
+ return
2015
+ for subitem in metadata.resource_listdir(''):
2016
+ if _is_egg_path(subitem):
2017
+ subpath = os.path.join(path_item, subitem)
2018
+ dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
2019
+ for dist in dists:
2020
+ yield dist
2021
+ elif subitem.lower().endswith('.dist-info'):
2022
+ subpath = os.path.join(path_item, subitem)
2023
+ submeta = EggMetadata(zipimport.zipimporter(subpath))
2024
+ submeta.egg_info = subpath
2025
+ yield Distribution.from_location(path_item, subitem, submeta)
2026
+
2027
+
2028
+ register_finder(zipimport.zipimporter, find_eggs_in_zip)
2029
+
2030
+
2031
+ def find_nothing(importer, path_item, only=False):
2032
+ return ()
2033
+
2034
+
2035
+ register_finder(object, find_nothing)
2036
+
2037
+
2038
+ def _by_version_descending(names):
2039
+ """
2040
+ Given a list of filenames, return them in descending order
2041
+ by version number.
2042
+
2043
+ >>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg'
2044
+ >>> _by_version_descending(names)
2045
+ ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'foo', 'bar']
2046
+ >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg'
2047
+ >>> _by_version_descending(names)
2048
+ ['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg']
2049
+ >>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.post1.egg'
2050
+ >>> _by_version_descending(names)
2051
+ ['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg']
2052
+ """
2053
+ def _by_version(name):
2054
+ """
2055
+ Parse each component of the filename
2056
+ """
2057
+ name, ext = os.path.splitext(name)
2058
+ parts = itertools.chain(name.split('-'), [ext])
2059
+ return [packaging.version.parse(part) for part in parts]
2060
+
2061
+ return sorted(names, key=_by_version, reverse=True)
2062
+
2063
+
2064
+ def find_on_path(importer, path_item, only=False):
2065
+ """Yield distributions accessible on a sys.path directory"""
2066
+ path_item = _normalize_cached(path_item)
2067
+
2068
+ if _is_unpacked_egg(path_item):
2069
+ yield Distribution.from_filename(
2070
+ path_item, metadata=PathMetadata(
2071
+ path_item, os.path.join(path_item, 'EGG-INFO')
2072
+ )
2073
+ )
2074
+ return
2075
+
2076
+ entries = safe_listdir(path_item)
2077
+
2078
+ # for performance, before sorting by version,
2079
+ # screen entries for only those that will yield
2080
+ # distributions
2081
+ filtered = (
2082
+ entry
2083
+ for entry in entries
2084
+ if dist_factory(path_item, entry, only)
2085
+ )
2086
+
2087
+ # scan for .egg and .egg-info in directory
2088
+ path_item_entries = _by_version_descending(filtered)
2089
+ for entry in path_item_entries:
2090
+ fullpath = os.path.join(path_item, entry)
2091
+ factory = dist_factory(path_item, entry, only)
2092
+ for dist in factory(fullpath):
2093
+ yield dist
2094
+
2095
+
2096
+ def dist_factory(path_item, entry, only):
2097
+ """
2098
+ Return a dist_factory for a path_item and entry
2099
+ """
2100
+ lower = entry.lower()
2101
+ is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info')))
2102
+ return (
2103
+ distributions_from_metadata
2104
+ if is_meta else
2105
+ find_distributions
2106
+ if not only and _is_egg_path(entry) else
2107
+ resolve_egg_link
2108
+ if not only and lower.endswith('.egg-link') else
2109
+ NoDists()
2110
+ )
2111
+
2112
+
2113
+ class NoDists:
2114
+ """
2115
+ >>> bool(NoDists())
2116
+ False
2117
+
2118
+ >>> list(NoDists()('anything'))
2119
+ []
2120
+ """
2121
+ def __bool__(self):
2122
+ return False
2123
+ if str is bytes:
2124
+ __nonzero__ = __bool__
2125
+
2126
+ def __call__(self, fullpath):
2127
+ return iter(())
2128
+
2129
+
2130
+ def safe_listdir(path):
2131
+ """
2132
+ Attempt to list contents of path, but suppress some exceptions.
2133
+ """
2134
+ try:
2135
+ return os.listdir(path)
2136
+ except (PermissionError, NotADirectoryError):
2137
+ pass
2138
+ except OSError as e:
2139
+ # Ignore the directory if does not exist, not a directory or
2140
+ # permission denied
2141
+ ignorable = (
2142
+ e.errno in (errno.ENOTDIR, errno.EACCES, errno.ENOENT)
2143
+ # Python 2 on Windows needs to be handled this way :(
2144
+ or getattr(e, "winerror", None) == 267
2145
+ )
2146
+ if not ignorable:
2147
+ raise
2148
+ return ()
2149
+
2150
+
2151
+ def distributions_from_metadata(path):
2152
+ root = os.path.dirname(path)
2153
+ if os.path.isdir(path):
2154
+ if len(os.listdir(path)) == 0:
2155
+ # empty metadata dir; skip
2156
+ return
2157
+ metadata = PathMetadata(root, path)
2158
+ else:
2159
+ metadata = FileMetadata(path)
2160
+ entry = os.path.basename(path)
2161
+ yield Distribution.from_location(
2162
+ root, entry, metadata, precedence=DEVELOP_DIST,
2163
+ )
2164
+
2165
+
2166
+ def non_empty_lines(path):
2167
+ """
2168
+ Yield non-empty lines from file at path
2169
+ """
2170
+ with open(path) as f:
2171
+ for line in f:
2172
+ line = line.strip()
2173
+ if line:
2174
+ yield line
2175
+
2176
+
2177
+ def resolve_egg_link(path):
2178
+ """
2179
+ Given a path to an .egg-link, resolve distributions
2180
+ present in the referenced path.
2181
+ """
2182
+ referenced_paths = non_empty_lines(path)
2183
+ resolved_paths = (
2184
+ os.path.join(os.path.dirname(path), ref)
2185
+ for ref in referenced_paths
2186
+ )
2187
+ dist_groups = map(find_distributions, resolved_paths)
2188
+ return next(dist_groups, ())
2189
+
2190
+
2191
+ if hasattr(importlib_machinery, 'FileFinder'):
2192
+ register_finder(importlib_machinery.FileFinder, find_on_path)
2193
+
2194
+ _declare_state('dict', _namespace_handlers={})
2195
+ _declare_state('dict', _namespace_packages={})
2196
+
2197
+
2198
+ def register_namespace_handler(importer_type, namespace_handler):
2199
+ """Register `namespace_handler` to declare namespace packages
2200
+
2201
+ `importer_type` is the type or class of a PEP 302 "Importer" (sys.path item
2202
+ handler), and `namespace_handler` is a callable like this::
2203
+
2204
+ def namespace_handler(importer, path_entry, moduleName, module):
2205
+ # return a path_entry to use for child packages
2206
+
2207
+ Namespace handlers are only called if the importer object has already
2208
+ agreed that it can handle the relevant path item, and they should only
2209
+ return a subpath if the module __path__ does not already contain an
2210
+ equivalent subpath. For an example namespace handler, see
2211
+ ``pkg_resources.file_ns_handler``.
2212
+ """
2213
+ _namespace_handlers[importer_type] = namespace_handler
2214
+
2215
+
2216
+ def _handle_ns(packageName, path_item):
2217
+ """Ensure that named package includes a subpath of path_item (if needed)"""
2218
+
2219
+ importer = get_importer(path_item)
2220
+ if importer is None:
2221
+ return None
2222
+
2223
+ # capture warnings due to #1111
2224
+ with warnings.catch_warnings():
2225
+ warnings.simplefilter("ignore")
2226
+ loader = importer.find_module(packageName)
2227
+
2228
+ if loader is None:
2229
+ return None
2230
+ module = sys.modules.get(packageName)
2231
+ if module is None:
2232
+ module = sys.modules[packageName] = types.ModuleType(packageName)
2233
+ module.__path__ = []
2234
+ _set_parent_ns(packageName)
2235
+ elif not hasattr(module, '__path__'):
2236
+ raise TypeError("Not a package:", packageName)
2237
+ handler = _find_adapter(_namespace_handlers, importer)
2238
+ subpath = handler(importer, path_item, packageName, module)
2239
+ if subpath is not None:
2240
+ path = module.__path__
2241
+ path.append(subpath)
2242
+ loader.load_module(packageName)
2243
+ _rebuild_mod_path(path, packageName, module)
2244
+ return subpath
2245
+
2246
+
2247
+ def _rebuild_mod_path(orig_path, package_name, module):
2248
+ """
2249
+ Rebuild module.__path__ ensuring that all entries are ordered
2250
+ corresponding to their sys.path order
2251
+ """
2252
+ sys_path = [_normalize_cached(p) for p in sys.path]
2253
+
2254
+ def safe_sys_path_index(entry):
2255
+ """
2256
+ Workaround for #520 and #513.
2257
+ """
2258
+ try:
2259
+ return sys_path.index(entry)
2260
+ except ValueError:
2261
+ return float('inf')
2262
+
2263
+ def position_in_sys_path(path):
2264
+ """
2265
+ Return the ordinal of the path based on its position in sys.path
2266
+ """
2267
+ path_parts = path.split(os.sep)
2268
+ module_parts = package_name.count('.') + 1
2269
+ parts = path_parts[:-module_parts]
2270
+ return safe_sys_path_index(_normalize_cached(os.sep.join(parts)))
2271
+
2272
+ new_path = sorted(orig_path, key=position_in_sys_path)
2273
+ new_path = [_normalize_cached(p) for p in new_path]
2274
+
2275
+ if isinstance(module.__path__, list):
2276
+ module.__path__[:] = new_path
2277
+ else:
2278
+ module.__path__ = new_path
2279
+
2280
+
2281
+ def declare_namespace(packageName):
2282
+ """Declare that package 'packageName' is a namespace package"""
2283
+
2284
+ _imp.acquire_lock()
2285
+ try:
2286
+ if packageName in _namespace_packages:
2287
+ return
2288
+
2289
+ path = sys.path
2290
+ parent, _, _ = packageName.rpartition('.')
2291
+
2292
+ if parent:
2293
+ declare_namespace(parent)
2294
+ if parent not in _namespace_packages:
2295
+ __import__(parent)
2296
+ try:
2297
+ path = sys.modules[parent].__path__
2298
+ except AttributeError:
2299
+ raise TypeError("Not a package:", parent)
2300
+
2301
+ # Track what packages are namespaces, so when new path items are added,
2302
+ # they can be updated
2303
+ _namespace_packages.setdefault(parent or None, []).append(packageName)
2304
+ _namespace_packages.setdefault(packageName, [])
2305
+
2306
+ for path_item in path:
2307
+ # Ensure all the parent's path items are reflected in the child,
2308
+ # if they apply
2309
+ _handle_ns(packageName, path_item)
2310
+
2311
+ finally:
2312
+ _imp.release_lock()
2313
+
2314
+
2315
+ def fixup_namespace_packages(path_item, parent=None):
2316
+ """Ensure that previously-declared namespace packages include path_item"""
2317
+ _imp.acquire_lock()
2318
+ try:
2319
+ for package in _namespace_packages.get(parent, ()):
2320
+ subpath = _handle_ns(package, path_item)
2321
+ if subpath:
2322
+ fixup_namespace_packages(subpath, package)
2323
+ finally:
2324
+ _imp.release_lock()
2325
+
2326
+
2327
+ def file_ns_handler(importer, path_item, packageName, module):
2328
+ """Compute an ns-package subpath for a filesystem or zipfile importer"""
2329
+
2330
+ subpath = os.path.join(path_item, packageName.split('.')[-1])
2331
+ normalized = _normalize_cached(subpath)
2332
+ for item in module.__path__:
2333
+ if _normalize_cached(item) == normalized:
2334
+ break
2335
+ else:
2336
+ # Only return the path if it's not already there
2337
+ return subpath
2338
+
2339
+
2340
+ register_namespace_handler(zipimport.zipimporter, file_ns_handler)
2341
+
2342
+ if hasattr(importlib_machinery, 'FileFinder'):
2343
+ register_namespace_handler(importlib_machinery.FileFinder, file_ns_handler)
2344
+
2345
+
2346
+ def null_ns_handler(importer, path_item, packageName, module):
2347
+ return None
2348
+
2349
+
2350
+ register_namespace_handler(object, null_ns_handler)
2351
+
2352
+
2353
+ def normalize_path(filename):
2354
+ """Normalize a file/dir name for comparison purposes"""
2355
+ return os.path.normcase(os.path.realpath(os.path.normpath(_cygwin_patch(filename))))
2356
+
2357
+
2358
+ def _cygwin_patch(filename): # pragma: nocover
2359
+ """
2360
+ Contrary to POSIX 2008, on Cygwin, getcwd (3) contains
2361
+ symlink components. Using
2362
+ os.path.abspath() works around this limitation. A fix in os.getcwd()
2363
+ would probably better, in Cygwin even more so, except
2364
+ that this seems to be by design...
2365
+ """
2366
+ return os.path.abspath(filename) if sys.platform == 'cygwin' else filename
2367
+
2368
+
2369
+ def _normalize_cached(filename, _cache={}):
2370
+ try:
2371
+ return _cache[filename]
2372
+ except KeyError:
2373
+ _cache[filename] = result = normalize_path(filename)
2374
+ return result
2375
+
2376
+
2377
+ def _is_egg_path(path):
2378
+ """
2379
+ Determine if given path appears to be an egg.
2380
+ """
2381
+ return path.lower().endswith('.egg')
2382
+
2383
+
2384
+ def _is_unpacked_egg(path):
2385
+ """
2386
+ Determine if given path appears to be an unpacked egg.
2387
+ """
2388
+ return (
2389
+ _is_egg_path(path) and
2390
+ os.path.isfile(os.path.join(path, 'EGG-INFO', 'PKG-INFO'))
2391
+ )
2392
+
2393
+
2394
+ def _set_parent_ns(packageName):
2395
+ parts = packageName.split('.')
2396
+ name = parts.pop()
2397
+ if parts:
2398
+ parent = '.'.join(parts)
2399
+ setattr(sys.modules[parent], name, sys.modules[packageName])
2400
+
2401
+
2402
+ def yield_lines(strs):
2403
+ """Yield non-empty/non-comment lines of a string or sequence"""
2404
+ if isinstance(strs, six.string_types):
2405
+ for s in strs.splitlines():
2406
+ s = s.strip()
2407
+ # skip blank lines/comments
2408
+ if s and not s.startswith('#'):
2409
+ yield s
2410
+ else:
2411
+ for ss in strs:
2412
+ for s in yield_lines(ss):
2413
+ yield s
2414
+
2415
+
2416
+ MODULE = re.compile(r"\w+(\.\w+)*$").match
2417
+ EGG_NAME = re.compile(
2418
+ r"""
2419
+ (?P<name>[^-]+) (
2420
+ -(?P<ver>[^-]+) (
2421
+ -py(?P<pyver>[^-]+) (
2422
+ -(?P<plat>.+)
2423
+ )?
2424
+ )?
2425
+ )?
2426
+ """,
2427
+ re.VERBOSE | re.IGNORECASE,
2428
+ ).match
2429
+
2430
+
2431
+ class EntryPoint:
2432
+ """Object representing an advertised importable object"""
2433
+
2434
+ def __init__(self, name, module_name, attrs=(), extras=(), dist=None):
2435
+ if not MODULE(module_name):
2436
+ raise ValueError("Invalid module name", module_name)
2437
+ self.name = name
2438
+ self.module_name = module_name
2439
+ self.attrs = tuple(attrs)
2440
+ self.extras = tuple(extras)
2441
+ self.dist = dist
2442
+
2443
+ def __str__(self):
2444
+ s = "%s = %s" % (self.name, self.module_name)
2445
+ if self.attrs:
2446
+ s += ':' + '.'.join(self.attrs)
2447
+ if self.extras:
2448
+ s += ' [%s]' % ','.join(self.extras)
2449
+ return s
2450
+
2451
+ def __repr__(self):
2452
+ return "EntryPoint.parse(%r)" % str(self)
2453
+
2454
+ def load(self, require=True, *args, **kwargs):
2455
+ """
2456
+ Require packages for this EntryPoint, then resolve it.
2457
+ """
2458
+ if not require or args or kwargs:
2459
+ warnings.warn(
2460
+ "Parameters to load are deprecated. Call .resolve and "
2461
+ ".require separately.",
2462
+ PkgResourcesDeprecationWarning,
2463
+ stacklevel=2,
2464
+ )
2465
+ if require:
2466
+ self.require(*args, **kwargs)
2467
+ return self.resolve()
2468
+
2469
+ def resolve(self):
2470
+ """
2471
+ Resolve the entry point from its module and attrs.
2472
+ """
2473
+ module = __import__(self.module_name, fromlist=['__name__'], level=0)
2474
+ try:
2475
+ return functools.reduce(getattr, self.attrs, module)
2476
+ except AttributeError as exc:
2477
+ raise ImportError(str(exc))
2478
+
2479
+ def require(self, env=None, installer=None):
2480
+ if self.extras and not self.dist:
2481
+ raise UnknownExtra("Can't require() without a distribution", self)
2482
+
2483
+ # Get the requirements for this entry point with all its extras and
2484
+ # then resolve them. We have to pass `extras` along when resolving so
2485
+ # that the working set knows what extras we want. Otherwise, for
2486
+ # dist-info distributions, the working set will assume that the
2487
+ # requirements for that extra are purely optional and skip over them.
2488
+ reqs = self.dist.requires(self.extras)
2489
+ items = working_set.resolve(reqs, env, installer, extras=self.extras)
2490
+ list(map(working_set.add, items))
2491
+
2492
+ pattern = re.compile(
2493
+ r'\s*'
2494
+ r'(?P<name>.+?)\s*'
2495
+ r'=\s*'
2496
+ r'(?P<module>[\w.]+)\s*'
2497
+ r'(:\s*(?P<attr>[\w.]+))?\s*'
2498
+ r'(?P<extras>\[.*\])?\s*$'
2499
+ )
2500
+
2501
+ @classmethod
2502
+ def parse(cls, src, dist=None):
2503
+ """Parse a single entry point from string `src`
2504
+
2505
+ Entry point syntax follows the form::
2506
+
2507
+ name = some.module:some.attr [extra1, extra2]
2508
+
2509
+ The entry name and module name are required, but the ``:attrs`` and
2510
+ ``[extras]`` parts are optional
2511
+ """
2512
+ m = cls.pattern.match(src)
2513
+ if not m:
2514
+ msg = "EntryPoint must be in 'name=module:attrs [extras]' format"
2515
+ raise ValueError(msg, src)
2516
+ res = m.groupdict()
2517
+ extras = cls._parse_extras(res['extras'])
2518
+ attrs = res['attr'].split('.') if res['attr'] else ()
2519
+ return cls(res['name'], res['module'], attrs, extras, dist)
2520
+
2521
+ @classmethod
2522
+ def _parse_extras(cls, extras_spec):
2523
+ if not extras_spec:
2524
+ return ()
2525
+ req = Requirement.parse('x' + extras_spec)
2526
+ if req.specs:
2527
+ raise ValueError()
2528
+ return req.extras
2529
+
2530
+ @classmethod
2531
+ def parse_group(cls, group, lines, dist=None):
2532
+ """Parse an entry point group"""
2533
+ if not MODULE(group):
2534
+ raise ValueError("Invalid group name", group)
2535
+ this = {}
2536
+ for line in yield_lines(lines):
2537
+ ep = cls.parse(line, dist)
2538
+ if ep.name in this:
2539
+ raise ValueError("Duplicate entry point", group, ep.name)
2540
+ this[ep.name] = ep
2541
+ return this
2542
+
2543
+ @classmethod
2544
+ def parse_map(cls, data, dist=None):
2545
+ """Parse a map of entry point groups"""
2546
+ if isinstance(data, dict):
2547
+ data = data.items()
2548
+ else:
2549
+ data = split_sections(data)
2550
+ maps = {}
2551
+ for group, lines in data:
2552
+ if group is None:
2553
+ if not lines:
2554
+ continue
2555
+ raise ValueError("Entry points must be listed in groups")
2556
+ group = group.strip()
2557
+ if group in maps:
2558
+ raise ValueError("Duplicate group name", group)
2559
+ maps[group] = cls.parse_group(group, lines, dist)
2560
+ return maps
2561
+
2562
+
2563
+ def _remove_md5_fragment(location):
2564
+ if not location:
2565
+ return ''
2566
+ parsed = urllib.parse.urlparse(location)
2567
+ if parsed[-1].startswith('md5='):
2568
+ return urllib.parse.urlunparse(parsed[:-1] + ('',))
2569
+ return location
2570
+
2571
+
2572
+ def _version_from_file(lines):
2573
+ """
2574
+ Given an iterable of lines from a Metadata file, return
2575
+ the value of the Version field, if present, or None otherwise.
2576
+ """
2577
+ def is_version_line(line):
2578
+ return line.lower().startswith('version:')
2579
+ version_lines = filter(is_version_line, lines)
2580
+ line = next(iter(version_lines), '')
2581
+ _, _, value = line.partition(':')
2582
+ return safe_version(value.strip()) or None
2583
+
2584
+
2585
+ class Distribution:
2586
+ """Wrap an actual or potential sys.path entry w/metadata"""
2587
+ PKG_INFO = 'PKG-INFO'
2588
+
2589
+ def __init__(
2590
+ self, location=None, metadata=None, project_name=None,
2591
+ version=None, py_version=PY_MAJOR, platform=None,
2592
+ precedence=EGG_DIST):
2593
+ self.project_name = safe_name(project_name or 'Unknown')
2594
+ if version is not None:
2595
+ self._version = safe_version(version)
2596
+ self.py_version = py_version
2597
+ self.platform = platform
2598
+ self.location = location
2599
+ self.precedence = precedence
2600
+ self._provider = metadata or empty_provider
2601
+
2602
+ @classmethod
2603
+ def from_location(cls, location, basename, metadata=None, **kw):
2604
+ project_name, version, py_version, platform = [None] * 4
2605
+ basename, ext = os.path.splitext(basename)
2606
+ if ext.lower() in _distributionImpl:
2607
+ cls = _distributionImpl[ext.lower()]
2608
+
2609
+ match = EGG_NAME(basename)
2610
+ if match:
2611
+ project_name, version, py_version, platform = match.group(
2612
+ 'name', 'ver', 'pyver', 'plat'
2613
+ )
2614
+ return cls(
2615
+ location, metadata, project_name=project_name, version=version,
2616
+ py_version=py_version, platform=platform, **kw
2617
+ )._reload_version()
2618
+
2619
+ def _reload_version(self):
2620
+ return self
2621
+
2622
+ @property
2623
+ def hashcmp(self):
2624
+ return (
2625
+ self.parsed_version,
2626
+ self.precedence,
2627
+ self.key,
2628
+ _remove_md5_fragment(self.location),
2629
+ self.py_version or '',
2630
+ self.platform or '',
2631
+ )
2632
+
2633
+ def __hash__(self):
2634
+ return hash(self.hashcmp)
2635
+
2636
+ def __lt__(self, other):
2637
+ return self.hashcmp < other.hashcmp
2638
+
2639
+ def __le__(self, other):
2640
+ return self.hashcmp <= other.hashcmp
2641
+
2642
+ def __gt__(self, other):
2643
+ return self.hashcmp > other.hashcmp
2644
+
2645
+ def __ge__(self, other):
2646
+ return self.hashcmp >= other.hashcmp
2647
+
2648
+ def __eq__(self, other):
2649
+ if not isinstance(other, self.__class__):
2650
+ # It's not a Distribution, so they are not equal
2651
+ return False
2652
+ return self.hashcmp == other.hashcmp
2653
+
2654
+ def __ne__(self, other):
2655
+ return not self == other
2656
+
2657
+ # These properties have to be lazy so that we don't have to load any
2658
+ # metadata until/unless it's actually needed. (i.e., some distributions
2659
+ # may not know their name or version without loading PKG-INFO)
2660
+
2661
+ @property
2662
+ def key(self):
2663
+ try:
2664
+ return self._key
2665
+ except AttributeError:
2666
+ self._key = key = self.project_name.lower()
2667
+ return key
2668
+
2669
+ @property
2670
+ def parsed_version(self):
2671
+ if not hasattr(self, "_parsed_version"):
2672
+ self._parsed_version = parse_version(self.version)
2673
+
2674
+ return self._parsed_version
2675
+
2676
+ def _warn_legacy_version(self):
2677
+ LV = packaging.version.LegacyVersion
2678
+ is_legacy = isinstance(self._parsed_version, LV)
2679
+ if not is_legacy:
2680
+ return
2681
+
2682
+ # While an empty version is technically a legacy version and
2683
+ # is not a valid PEP 440 version, it's also unlikely to
2684
+ # actually come from someone and instead it is more likely that
2685
+ # it comes from setuptools attempting to parse a filename and
2686
+ # including it in the list. So for that we'll gate this warning
2687
+ # on if the version is anything at all or not.
2688
+ if not self.version:
2689
+ return
2690
+
2691
+ tmpl = textwrap.dedent("""
2692
+ '{project_name} ({version})' is being parsed as a legacy,
2693
+ non PEP 440,
2694
+ version. You may find odd behavior and sort order.
2695
+ In particular it will be sorted as less than 0.0. It
2696
+ is recommended to migrate to PEP 440 compatible
2697
+ versions.
2698
+ """).strip().replace('\n', ' ')
2699
+
2700
+ warnings.warn(tmpl.format(**vars(self)), PEP440Warning)
2701
+
2702
+ @property
2703
+ def version(self):
2704
+ try:
2705
+ return self._version
2706
+ except AttributeError:
2707
+ version = self._get_version()
2708
+ if version is None:
2709
+ path = self._get_metadata_path_for_display(self.PKG_INFO)
2710
+ msg = (
2711
+ "Missing 'Version:' header and/or {} file at path: {}"
2712
+ ).format(self.PKG_INFO, path)
2713
+ raise ValueError(msg, self)
2714
+
2715
+ return version
2716
+
2717
+ @property
2718
+ def _dep_map(self):
2719
+ """
2720
+ A map of extra to its list of (direct) requirements
2721
+ for this distribution, including the null extra.
2722
+ """
2723
+ try:
2724
+ return self.__dep_map
2725
+ except AttributeError:
2726
+ self.__dep_map = self._filter_extras(self._build_dep_map())
2727
+ return self.__dep_map
2728
+
2729
+ @staticmethod
2730
+ def _filter_extras(dm):
2731
+ """
2732
+ Given a mapping of extras to dependencies, strip off
2733
+ environment markers and filter out any dependencies
2734
+ not matching the markers.
2735
+ """
2736
+ for extra in list(filter(None, dm)):
2737
+ new_extra = extra
2738
+ reqs = dm.pop(extra)
2739
+ new_extra, _, marker = extra.partition(':')
2740
+ fails_marker = marker and (
2741
+ invalid_marker(marker)
2742
+ or not evaluate_marker(marker)
2743
+ )
2744
+ if fails_marker:
2745
+ reqs = []
2746
+ new_extra = safe_extra(new_extra) or None
2747
+
2748
+ dm.setdefault(new_extra, []).extend(reqs)
2749
+ return dm
2750
+
2751
+ def _build_dep_map(self):
2752
+ dm = {}
2753
+ for name in 'requires.txt', 'depends.txt':
2754
+ for extra, reqs in split_sections(self._get_metadata(name)):
2755
+ dm.setdefault(extra, []).extend(parse_requirements(reqs))
2756
+ return dm
2757
+
2758
+ def requires(self, extras=()):
2759
+ """List of Requirements needed for this distro if `extras` are used"""
2760
+ dm = self._dep_map
2761
+ deps = []
2762
+ deps.extend(dm.get(None, ()))
2763
+ for ext in extras:
2764
+ try:
2765
+ deps.extend(dm[safe_extra(ext)])
2766
+ except KeyError:
2767
+ raise UnknownExtra(
2768
+ "%s has no such extra feature %r" % (self, ext)
2769
+ )
2770
+ return deps
2771
+
2772
+ def _get_metadata_path_for_display(self, name):
2773
+ """
2774
+ Return the path to the given metadata file, if available.
2775
+ """
2776
+ try:
2777
+ # We need to access _get_metadata_path() on the provider object
2778
+ # directly rather than through this class's __getattr__()
2779
+ # since _get_metadata_path() is marked private.
2780
+ path = self._provider._get_metadata_path(name)
2781
+
2782
+ # Handle exceptions e.g. in case the distribution's metadata
2783
+ # provider doesn't support _get_metadata_path().
2784
+ except Exception:
2785
+ return '[could not detect]'
2786
+
2787
+ return path
2788
+
2789
+ def _get_metadata(self, name):
2790
+ if self.has_metadata(name):
2791
+ for line in self.get_metadata_lines(name):
2792
+ yield line
2793
+
2794
+ def _get_version(self):
2795
+ lines = self._get_metadata(self.PKG_INFO)
2796
+ version = _version_from_file(lines)
2797
+
2798
+ return version
2799
+
2800
+ def activate(self, path=None, replace=False):
2801
+ """Ensure distribution is importable on `path` (default=sys.path)"""
2802
+ if path is None:
2803
+ path = sys.path
2804
+ self.insert_on(path, replace=replace)
2805
+ if path is sys.path:
2806
+ fixup_namespace_packages(self.location)
2807
+ for pkg in self._get_metadata('namespace_packages.txt'):
2808
+ if pkg in sys.modules:
2809
+ declare_namespace(pkg)
2810
+
2811
+ def egg_name(self):
2812
+ """Return what this distribution's standard .egg filename should be"""
2813
+ filename = "%s-%s-py%s" % (
2814
+ to_filename(self.project_name), to_filename(self.version),
2815
+ self.py_version or PY_MAJOR
2816
+ )
2817
+
2818
+ if self.platform:
2819
+ filename += '-' + self.platform
2820
+ return filename
2821
+
2822
+ def __repr__(self):
2823
+ if self.location:
2824
+ return "%s (%s)" % (self, self.location)
2825
+ else:
2826
+ return str(self)
2827
+
2828
+ def __str__(self):
2829
+ try:
2830
+ version = getattr(self, 'version', None)
2831
+ except ValueError:
2832
+ version = None
2833
+ version = version or "[unknown version]"
2834
+ return "%s %s" % (self.project_name, version)
2835
+
2836
+ def __getattr__(self, attr):
2837
+ """Delegate all unrecognized public attributes to .metadata provider"""
2838
+ if attr.startswith('_'):
2839
+ raise AttributeError(attr)
2840
+ return getattr(self._provider, attr)
2841
+
2842
+ def __dir__(self):
2843
+ return list(
2844
+ set(super(Distribution, self).__dir__())
2845
+ | set(
2846
+ attr for attr in self._provider.__dir__()
2847
+ if not attr.startswith('_')
2848
+ )
2849
+ )
2850
+
2851
+ if not hasattr(object, '__dir__'):
2852
+ # python 2.7 not supported
2853
+ del __dir__
2854
+
2855
+ @classmethod
2856
+ def from_filename(cls, filename, metadata=None, **kw):
2857
+ return cls.from_location(
2858
+ _normalize_cached(filename), os.path.basename(filename), metadata,
2859
+ **kw
2860
+ )
2861
+
2862
+ def as_requirement(self):
2863
+ """Return a ``Requirement`` that matches this distribution exactly"""
2864
+ if isinstance(self.parsed_version, packaging.version.Version):
2865
+ spec = "%s==%s" % (self.project_name, self.parsed_version)
2866
+ else:
2867
+ spec = "%s===%s" % (self.project_name, self.parsed_version)
2868
+
2869
+ return Requirement.parse(spec)
2870
+
2871
+ def load_entry_point(self, group, name):
2872
+ """Return the `name` entry point of `group` or raise ImportError"""
2873
+ ep = self.get_entry_info(group, name)
2874
+ if ep is None:
2875
+ raise ImportError("Entry point %r not found" % ((group, name),))
2876
+ return ep.load()
2877
+
2878
+ def get_entry_map(self, group=None):
2879
+ """Return the entry point map for `group`, or the full entry map"""
2880
+ try:
2881
+ ep_map = self._ep_map
2882
+ except AttributeError:
2883
+ ep_map = self._ep_map = EntryPoint.parse_map(
2884
+ self._get_metadata('entry_points.txt'), self
2885
+ )
2886
+ if group is not None:
2887
+ return ep_map.get(group, {})
2888
+ return ep_map
2889
+
2890
+ def get_entry_info(self, group, name):
2891
+ """Return the EntryPoint object for `group`+`name`, or ``None``"""
2892
+ return self.get_entry_map(group).get(name)
2893
+
2894
+ def insert_on(self, path, loc=None, replace=False):
2895
+ """Ensure self.location is on path
2896
+
2897
+ If replace=False (default):
2898
+ - If location is already in path anywhere, do nothing.
2899
+ - Else:
2900
+ - If it's an egg and its parent directory is on path,
2901
+ insert just ahead of the parent.
2902
+ - Else: add to the end of path.
2903
+ If replace=True:
2904
+ - If location is already on path anywhere (not eggs)
2905
+ or higher priority than its parent (eggs)
2906
+ do nothing.
2907
+ - Else:
2908
+ - If it's an egg and its parent directory is on path,
2909
+ insert just ahead of the parent,
2910
+ removing any lower-priority entries.
2911
+ - Else: add it to the front of path.
2912
+ """
2913
+
2914
+ loc = loc or self.location
2915
+ if not loc:
2916
+ return
2917
+
2918
+ nloc = _normalize_cached(loc)
2919
+ bdir = os.path.dirname(nloc)
2920
+ npath = [(p and _normalize_cached(p) or p) for p in path]
2921
+
2922
+ for p, item in enumerate(npath):
2923
+ if item == nloc:
2924
+ if replace:
2925
+ break
2926
+ else:
2927
+ # don't modify path (even removing duplicates) if
2928
+ # found and not replace
2929
+ return
2930
+ elif item == bdir and self.precedence == EGG_DIST:
2931
+ # if it's an .egg, give it precedence over its directory
2932
+ # UNLESS it's already been added to sys.path and replace=False
2933
+ if (not replace) and nloc in npath[p:]:
2934
+ return
2935
+ if path is sys.path:
2936
+ self.check_version_conflict()
2937
+ path.insert(p, loc)
2938
+ npath.insert(p, nloc)
2939
+ break
2940
+ else:
2941
+ if path is sys.path:
2942
+ self.check_version_conflict()
2943
+ if replace:
2944
+ path.insert(0, loc)
2945
+ else:
2946
+ path.append(loc)
2947
+ return
2948
+
2949
+ # p is the spot where we found or inserted loc; now remove duplicates
2950
+ while True:
2951
+ try:
2952
+ np = npath.index(nloc, p + 1)
2953
+ except ValueError:
2954
+ break
2955
+ else:
2956
+ del npath[np], path[np]
2957
+ # ha!
2958
+ p = np
2959
+
2960
+ return
2961
+
2962
+ def check_version_conflict(self):
2963
+ if self.key == 'setuptools':
2964
+ # ignore the inevitable setuptools self-conflicts :(
2965
+ return
2966
+
2967
+ nsp = dict.fromkeys(self._get_metadata('namespace_packages.txt'))
2968
+ loc = normalize_path(self.location)
2969
+ for modname in self._get_metadata('top_level.txt'):
2970
+ if (modname not in sys.modules or modname in nsp
2971
+ or modname in _namespace_packages):
2972
+ continue
2973
+ if modname in ('pkg_resources', 'setuptools', 'site'):
2974
+ continue
2975
+ fn = getattr(sys.modules[modname], '__file__', None)
2976
+ if fn and (normalize_path(fn).startswith(loc) or
2977
+ fn.startswith(self.location)):
2978
+ continue
2979
+ issue_warning(
2980
+ "Module %s was already imported from %s, but %s is being added"
2981
+ " to sys.path" % (modname, fn, self.location),
2982
+ )
2983
+
2984
+ def has_version(self):
2985
+ try:
2986
+ self.version
2987
+ except ValueError:
2988
+ issue_warning("Unbuilt egg for " + repr(self))
2989
+ return False
2990
+ return True
2991
+
2992
+ def clone(self, **kw):
2993
+ """Copy this distribution, substituting in any changed keyword args"""
2994
+ names = 'project_name version py_version platform location precedence'
2995
+ for attr in names.split():
2996
+ kw.setdefault(attr, getattr(self, attr, None))
2997
+ kw.setdefault('metadata', self._provider)
2998
+ return self.__class__(**kw)
2999
+
3000
+ @property
3001
+ def extras(self):
3002
+ return [dep for dep in self._dep_map if dep]
3003
+
3004
+
3005
+ class EggInfoDistribution(Distribution):
3006
+ def _reload_version(self):
3007
+ """
3008
+ Packages installed by distutils (e.g. numpy or scipy),
3009
+ which uses an old safe_version, and so
3010
+ their version numbers can get mangled when
3011
+ converted to filenames (e.g., 1.11.0.dev0+2329eae to
3012
+ 1.11.0.dev0_2329eae). These distributions will not be
3013
+ parsed properly
3014
+ downstream by Distribution and safe_version, so
3015
+ take an extra step and try to get the version number from
3016
+ the metadata file itself instead of the filename.
3017
+ """
3018
+ md_version = self._get_version()
3019
+ if md_version:
3020
+ self._version = md_version
3021
+ return self
3022
+
3023
+
3024
+ class DistInfoDistribution(Distribution):
3025
+ """
3026
+ Wrap an actual or potential sys.path entry
3027
+ w/metadata, .dist-info style.
3028
+ """
3029
+ PKG_INFO = 'METADATA'
3030
+ EQEQ = re.compile(r"([\(,])\s*(\d.*?)\s*([,\)])")
3031
+
3032
+ @property
3033
+ def _parsed_pkg_info(self):
3034
+ """Parse and cache metadata"""
3035
+ try:
3036
+ return self._pkg_info
3037
+ except AttributeError:
3038
+ metadata = self.get_metadata(self.PKG_INFO)
3039
+ self._pkg_info = email.parser.Parser().parsestr(metadata)
3040
+ return self._pkg_info
3041
+
3042
+ @property
3043
+ def _dep_map(self):
3044
+ try:
3045
+ return self.__dep_map
3046
+ except AttributeError:
3047
+ self.__dep_map = self._compute_dependencies()
3048
+ return self.__dep_map
3049
+
3050
+ def _compute_dependencies(self):
3051
+ """Recompute this distribution's dependencies."""
3052
+ dm = self.__dep_map = {None: []}
3053
+
3054
+ reqs = []
3055
+ # Including any condition expressions
3056
+ for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
3057
+ reqs.extend(parse_requirements(req))
3058
+
3059
+ def reqs_for_extra(extra):
3060
+ for req in reqs:
3061
+ if not req.marker or req.marker.evaluate({'extra': extra}):
3062
+ yield req
3063
+
3064
+ common = frozenset(reqs_for_extra(None))
3065
+ dm[None].extend(common)
3066
+
3067
+ for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
3068
+ s_extra = safe_extra(extra.strip())
3069
+ dm[s_extra] = list(frozenset(reqs_for_extra(extra)) - common)
3070
+
3071
+ return dm
3072
+
3073
+
3074
+ _distributionImpl = {
3075
+ '.egg': Distribution,
3076
+ '.egg-info': EggInfoDistribution,
3077
+ '.dist-info': DistInfoDistribution,
3078
+ }
3079
+
3080
+
3081
+ def issue_warning(*args, **kw):
3082
+ level = 1
3083
+ g = globals()
3084
+ try:
3085
+ # find the first stack frame that is *not* code in
3086
+ # the pkg_resources module, to use for the warning
3087
+ while sys._getframe(level).f_globals is g:
3088
+ level += 1
3089
+ except ValueError:
3090
+ pass
3091
+ warnings.warn(stacklevel=level + 1, *args, **kw)
3092
+
3093
+
3094
+ class RequirementParseError(ValueError):
3095
+ def __str__(self):
3096
+ return ' '.join(self.args)
3097
+
3098
+
3099
+ def parse_requirements(strs):
3100
+ """Yield ``Requirement`` objects for each specification in `strs`
3101
+
3102
+ `strs` must be a string, or a (possibly-nested) iterable thereof.
3103
+ """
3104
+ # create a steppable iterator, so we can handle \-continuations
3105
+ lines = iter(yield_lines(strs))
3106
+
3107
+ for line in lines:
3108
+ # Drop comments -- a hash without a space may be in a URL.
3109
+ if ' #' in line:
3110
+ line = line[:line.find(' #')]
3111
+ # If there is a line continuation, drop it, and append the next line.
3112
+ if line.endswith('\\'):
3113
+ line = line[:-2].strip()
3114
+ try:
3115
+ line += next(lines)
3116
+ except StopIteration:
3117
+ return
3118
+ yield Requirement(line)
3119
+
3120
+ def _always_object(classes):
3121
+ """
3122
+ Ensure object appears in the mro even
3123
+ for old-style classes.
3124
+ """
3125
+ if object not in classes:
3126
+ return classes + (object,)
3127
+ return classes
3128
+
3129
+
3130
+ def _find_adapter(registry, ob):
3131
+ """Return an adapter factory for `ob` from `registry`"""
3132
+ types = _always_object(inspect.getmro(getattr(ob, '__class__', type(ob))))
3133
+ for t in types:
3134
+ if t in registry:
3135
+ return registry[t]
3136
+
3137
+
3138
+ def ensure_directory(path):
3139
+ """Ensure that the parent directory of `path` exists"""
3140
+ dirname = os.path.dirname(path)
3141
+ py31compat.makedirs(dirname, exist_ok=True)
3142
+
3143
+
3144
+ def _bypass_ensure_directory(path):
3145
+ """Sandbox-bypassing version of ensure_directory()"""
3146
+ if not WRITE_SUPPORT:
3147
+ raise IOError('"os.mkdir" not supported on this platform.')
3148
+ dirname, filename = split(path)
3149
+ if dirname and filename and not isdir(dirname):
3150
+ _bypass_ensure_directory(dirname)
3151
+ try:
3152
+ mkdir(dirname, 0o755)
3153
+ except FileExistsError:
3154
+ pass
3155
+
3156
+
3157
+ def split_sections(s):
3158
+ """Split a string or iterable thereof into (section, content) pairs
3159
+
3160
+ Each ``section`` is a stripped version of the section header ("[section]")
3161
+ and each ``content`` is a list of stripped lines excluding blank lines and
3162
+ comment-only lines. If there are any such lines before the first section
3163
+ header, they're returned in a first ``section`` of ``None``.
3164
+ """
3165
+ section = None
3166
+ content = []
3167
+ for line in yield_lines(s):
3168
+ if line.startswith("["):
3169
+ if line.endswith("]"):
3170
+ if section or content:
3171
+ yield section, content
3172
+ section = line[1:-1].strip()
3173
+ content = []
3174
+ else:
3175
+ raise ValueError("Invalid section heading", line)
3176
+ else:
3177
+ content.append(line)
3178
+
3179
+ # wrap up last segment
3180
+ yield section, content
3181
+
3182
+
3183
+ def _mkstemp(*args, **kw):
3184
+ old_open = os.open
3185
+ try:
3186
+ # temporarily bypass sandboxing
3187
+ os.open = os_open
3188
+ return tempfile.mkstemp(*args, **kw)
3189
+ finally:
3190
+ # and then put it back
3191
+ os.open = old_open
3192
+
3193
+
3194
+ # Silence the PEP440Warning by default, so that end users don't get hit by it
3195
+ # randomly just because they use pkg_resources. We want to append the rule
3196
+ # because we want earlier uses of filterwarnings to take precedence over this
3197
+ # one.
3198
+ warnings.filterwarnings("ignore", category=PEP440Warning, append=True)
3199
+
3200
+
3201
+ # from jaraco.functools 1.3
3202
+ def _call_aside(f, *args, **kwargs):
3203
+ f(*args, **kwargs)
3204
+ return f
3205
+
3206
+
3207
+ @_call_aside
3208
+ def _initialize(g=globals()):
3209
+ "Set up global resource manager (deliberately not state-saved)"
3210
+ manager = ResourceManager()
3211
+
3212
+ assert "sys" not in dir(manager), manager
3213
+
3214
+ g['_manager'] = manager
3215
+ g.update(
3216
+ (name, getattr(manager, name))
3217
+ for name in dir(manager)
3218
+ if not name.startswith('_')
3219
+ )
3220
+
3221
+
3222
+ @_call_aside
3223
+ def _initialize_master_working_set():
3224
+ """
3225
+ Prepare the master working set and make the ``require()``
3226
+ API available.
3227
+
3228
+ This function has explicit effects on the global state
3229
+ of pkg_resources. It is intended to be invoked once at
3230
+ the initialization of this module.
3231
+
3232
+ Invocation by other packages is unsupported and done
3233
+ at their own risk.
3234
+ """
3235
+
3236
+ # Nuitka: We do not care for this bit in Jinja2, which is the only reason the
3237
+ # inline copy is there.
3238
+ return
3239
+
3240
+ working_set = WorkingSet._build_master()
3241
+ _declare_state('object', working_set=working_set)
3242
+
3243
+ require = working_set.require
3244
+ iter_entry_points = working_set.iter_entry_points
3245
+ add_activation_listener = working_set.subscribe
3246
+ run_script = working_set.run_script
3247
+ # backward compatibility
3248
+ run_main = run_script
3249
+ # Activate all distributions already on sys.path with replace=False and
3250
+ # ensure that all distributions added to the working set in the future
3251
+ # (e.g. by calling ``require()``) will get activated as well,
3252
+ # with higher priority (replace=True).
3253
+ tuple(
3254
+ dist.activate(replace=False)
3255
+ for dist in working_set
3256
+ )
3257
+ add_activation_listener(
3258
+ lambda dist: dist.activate(replace=True),
3259
+ existing=False,
3260
+ )
3261
+ working_set.entries = []
3262
+ # match order
3263
+ list(map(working_set.add_entry, sys.path))
3264
+ globals().update(locals())
3265
+
3266
+ class PkgResourcesDeprecationWarning(Warning):
3267
+ """
3268
+ Base class for warning about deprecations in ``pkg_resources``
3269
+
3270
+ This class is not derived from ``DeprecationWarning``, and as such is
3271
+ visible by default.
3272
+ """