summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python3/get_module_deps3.py
diff options
context:
space:
mode:
authorAlejandro Hernandez <alejandro.hernandez@linux.intel.com>2017-08-04 14:06:14 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-01-20 22:31:56 +0000
commitb6777878ff03c3e956386020a19d11c875c835ae (patch)
tree753d1f85db4fb803204178b121ed544f792edd1b /meta/recipes-devtools/python/python3/get_module_deps3.py
parent86e002572d53cf2e60196269928a411375d24294 (diff)
downloadpoky-b6777878ff03c3e956386020a19d11c875c835ae.tar.gz
python3: Restructure python3 packaging and replace it with autopackaging
See previous commit (python2 version) for more info, since mostly everything applies here as well. Old manifest file had several issues: - Its unorganized and hard to read and understand it for an average human being. - When a new package needs to be added, the user actually has to modify the script that creates the manifest, then call the script to create a new manifest, and then submit a patch for both the script and the manifest, so its a little convoluted. - Git complains every single time a patch is submitted to the manifest, since it violates some of its guidelines. - It changes or may change with every release of python, its impossible to know if the required files for a certain package have changed (it could have more or less dependencies), the only way of doing so would be to install and test them all one by one on separate individual images, and even then we wouldnt know if they require less dependencies, we would just know if an extra dependency is required since it would complain, lets face it, this isnt feasible. - The same thing happens for new packages, if someone wants to add a new package, its dependencies need to be checked manually one by one. Features/Fixes: - A new manifest format is used (JSON), easy to read and understand. This file is parsed by the python recipe and python packages read from here are passed directly to bitbake during parsing time. - It provides an automatic manifest creation task (explained on previous commit), which automagically checks for every package dependencies and adds them to the new manifest, hence we will have on each package exactly what that package needs to be run, providing finer granularity. - Dependencies are also checked automagically for new packages (explained on previous commit). This patch has the same features as the python2 version but it differs in the following ways: - Python3 handles precompiled bytecode files (*.pyc) differently. for this reason and since we are cross compiling, wildcards couldnt be avoided on python3 (See PEP #3147 [1]). Both the manifest and the manifest creation script handle this differently, the manifest for python3 has an extra field for cached files, which is how it lets the user install the cached files or not via : INCLUDE_PYCS = "1" on their local.conf. - Shared libraries nomenclature also changed on python3, so again, we use wildcards to deal with this issue ( See PEP #3149 [2]): - Fixes python3 manifest, python3-core should be base and everything should depend on it, hence several packages were deleted: python3-enum, re, gdbm, subprocess, signal, readline. - When building python3-native it adds as symlink to it called nativepython3, which is then isued by the create_manifest task. - Fixes [YOCTO #11513] while were at it. References: [1] https://www.python.org/dev/peps/pep-3147/ [2] https://www.python.org/dev/peps/pep-3149/ (From OE-Core rev: 54ac820b8a639950ccb534dcd9d6eaf8b2b736e0) Signed-off-by: Alejandro Hernandez <alejandro.hernandez@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/python/python3/get_module_deps3.py')
-rw-r--r--meta/recipes-devtools/python/python3/get_module_deps3.py146
1 files changed, 146 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python3/get_module_deps3.py b/meta/recipes-devtools/python/python3/get_module_deps3.py
new file mode 100644
index 0000000000..fd12baad84
--- /dev/null
+++ b/meta/recipes-devtools/python/python3/get_module_deps3.py
@@ -0,0 +1,146 @@
1# This script is launched on separate task for each python module
2# It checks for dependencies for that specific module and prints
3# them out, the output of this execution will have all dependencies
4# for a specific module, which will be parsed an dealt on create_manifest.py
5#
6# Author: Alejandro Enedino Hernandez Samaniego "aehs29" <aehs29@gmail.com>
7
8# We can get a log per module, for all the dependencies that were found, but its messy.
9debug=False
10
11import sys
12
13# We can get a list of the modules which are currently required to run python
14# so we run python-core and get its modules, we then import what we need
15# and check what modules are currently running, if we substract them from the
16# modules we had initially, we get the dependencies for the module we imported.
17
18# We use importlib to achieve this, so we also need to know what modules importlib needs
19import importlib
20
21core_deps=set(sys.modules)
22
23def fix_path(dep_path):
24 import os
25 # We DONT want the path on our HOST system
26 pivot='recipe-sysroot-native'
27 dep_path=dep_path[dep_path.find(pivot)+len(pivot):]
28
29 if '/usr/bin' in dep_path:
30 dep_path = dep_path.replace('/usr/bin''${bindir}')
31
32 # Handle multilib, is there a better way?
33 if '/usr/lib32' in dep_path:
34 dep_path = dep_path.replace('/usr/lib32','${libdir}')
35 if '/usr/lib64' in dep_path:
36 dep_path = dep_path.replace('/usr/lib64','${libdir}')
37 if '/usr/lib' in dep_path:
38 dep_path = dep_path.replace('/usr/lib','${libdir}')
39 if '/usr/include' in dep_path:
40 dep_path = dep_path.replace('/usr/include','${includedir}')
41 if '__init__.' in dep_path:
42 dep_path = os.path.split(dep_path)[0]
43 return dep_path
44
45
46# Module to import was passed as an argument
47current_module = str(sys.argv[1]).rstrip()
48if(debug==True):
49 log = open('log_%s' % current_module,'w')
50 log.write('Module %s generated the following dependencies:\n' % current_module)
51try:
52 importlib.import_module('%s' % current_module)
53except ImportError as e:
54 if (debug==True):
55 log.write('Module was not found')
56 pass
57
58
59# Get current module dependencies, dif will contain a list of specific deps for this module
60module_deps=set(sys.modules)
61
62# We handle the core package (1st pass on create_manifest.py) as a special case
63if current_module == 'python-core-package':
64 dif = core_deps
65else:
66 # We know this is not the core package, so there must be a difference.
67 dif = module_deps-core_deps
68
69
70# Check where each dependency came from
71for item in dif:
72 dep_path=''
73 try:
74 if (debug==True):
75 log.write('Calling: sys.modules[' + '%s' % item + '].__file__\n')
76 dep_path = sys.modules['%s' % item].__file__
77 except AttributeError as e:
78 # Deals with thread (builtin module) not having __file__ attribute
79 if debug==True:
80 log.write(item + ' ')
81 log.write(str(e))
82 log.write('\n')
83 pass
84 except NameError as e:
85 # Deals with NameError: name 'dep_path' is not defined
86 # because module is not found (wasn't compiled?), e.g. bddsm
87 if (debug==True):
88 log.write(item+' ')
89 log.write(str(e))
90 pass
91
92 # Site-customize is a special case since we (OpenEmbedded) put it there manually
93 if 'sitecustomize' in dep_path:
94 dep_path = '${libdir}/python${PYTHON_MAJMIN}/sitecustomize.py'
95 # Prints out result, which is what will be used by create_manifest
96 print (dep_path)
97 continue
98
99 dep_path = fix_path(dep_path)
100
101 import sysconfig
102 soabi=sysconfig.get_config_var('SOABI')
103 # Check if its a shared library and deconstruct it
104 if soabi in dep_path:
105 if (debug==True):
106 log.write('Shared library found in %s' % dep_path)
107 dep_path = dep_path.replace(soabi,'*')
108 print (dep_path)
109 continue
110
111 if (debug==True):
112 log.write(dep_path+'\n')
113 # Prints out result, which is what will be used by create_manifest
114 print (dep_path)
115
116
117 import imp
118 cpython_tag = imp.get_tag()
119 cached=''
120 # Theres no naive way to find *.pyc files on python3
121 try:
122 if (debug==True):
123 log.write('Calling: sys.modules[' + '%s' % item + '].__cached__\n')
124 cached = sys.modules['%s' % item].__cached__
125 except AttributeError as e:
126 # Deals with thread (builtin module) not having __cached__ attribute
127 if debug==True:
128 log.write(item + ' ')
129 log.write(str(e))
130 log.write('\n')
131 pass
132 except NameError as e:
133 # Deals with NameError: name 'cached' is not defined
134 if (debug==True):
135 log.write(item+' ')
136 log.write(str(e))
137 pass
138 if cached is not None:
139 if (debug==True):
140 log.write(cached)
141 cached = fix_path(cached)
142 cached = cached.replace(cpython_tag,'*')
143 print (cached)
144
145if debug==True:
146 log.close()