Merge lp:~l3on/ubuntu/trusty/astroid/fix-1306674 into lp:ubuntu/trusty/astroid

Proposed by Leo Iannacone
Status: Rejected
Rejected by: Iain Lane
Proposed branch: lp:~l3on/ubuntu/trusty/astroid/fix-1306674
Merge into: lp:ubuntu/trusty/astroid
Diff against target: 308 lines (+230/-4)
7 files modified
.pc/applied-patches (+1/-0)
.pc/git_fa1312a4d7aa.patch/brain/py2gi.py (+147/-0)
brain/py2gi.py (+15/-3)
debian/changelog (+7/-0)
debian/control (+2/-1)
debian/patches/git_fa1312a4d7aa.patch (+57/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~l3on/ubuntu/trusty/astroid/fix-1306674
Reviewer Review Type Date Requested Status
Ubuntu Development Team Pending
Review via email: mp+215442@code.launchpad.net

Description of the change

Imported patch from upstream to fix issues regarding gobject instrospection.

See LP: #1306674

To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

Looks like this is in Trusty via a sync already, thanks for reporting to Debian!

If you'd like to have this SRUed then please convert the bug into an SRU compliant report and unreject this MP.

Good work :).

Unmerged revisions

3. By Leo Iannacone

imported patch from upstream - lp: #1306674

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.pc/applied-patches'
2--- .pc/applied-patches 2014-01-04 12:14:12 +0000
3+++ .pc/applied-patches 2014-04-11 15:21:41 +0000
4@@ -0,0 +1,1 @@
5+git_fa1312a4d7aa.patch
6
7=== added directory '.pc/git_fa1312a4d7aa.patch'
8=== added file '.pc/git_fa1312a4d7aa.patch/.timestamp'
9=== added directory '.pc/git_fa1312a4d7aa.patch/brain'
10=== added file '.pc/git_fa1312a4d7aa.patch/brain/py2gi.py'
11--- .pc/git_fa1312a4d7aa.patch/brain/py2gi.py 1970-01-01 00:00:00 +0000
12+++ .pc/git_fa1312a4d7aa.patch/brain/py2gi.py 2014-04-11 15:21:41 +0000
13@@ -0,0 +1,147 @@
14+"""Astroid hooks for the Python 2 GObject introspection bindings.
15+
16+Helps with understanding everything imported from 'gi.repository'
17+"""
18+
19+import inspect
20+import sys
21+
22+from astroid import MANAGER, AstroidBuildingException
23+from astroid.builder import AstroidBuilder
24+
25+
26+_inspected_modules = {}
27+
28+
29+def _gi_build_stub(parent):
30+ """
31+ Inspect the passed module recursively and build stubs for functions,
32+ classes, etc.
33+ """
34+ classes = {}
35+ functions = {}
36+ constants = {}
37+ methods = {}
38+ for name in dir(parent):
39+ if not name or name.startswith("__"):
40+ # GLib.IConv has a parameter named "" :/
41+ continue
42+ try:
43+ obj = getattr(parent, name)
44+ except:
45+ continue
46+
47+ if inspect.isclass(obj):
48+ classes[name] = obj
49+ elif (inspect.isfunction(obj) or
50+ inspect.isbuiltin(obj)):
51+ functions[name] = obj
52+ elif (inspect.ismethod(obj) or
53+ inspect.ismethoddescriptor(obj)):
54+ methods[name] = obj
55+ elif type(obj) in [int, str]:
56+ constants[name] = obj
57+ elif (str(obj).startswith("<flags") or
58+ str(obj).startswith("<enum ") or
59+ str(obj).startswith("<GType ") or
60+ inspect.isdatadescriptor(obj)):
61+ constants[name] = 0
62+
63+ ret = ""
64+
65+ if constants:
66+ ret += "# %s contants\n\n" % parent.__name__
67+ for name in sorted(constants):
68+ if name[0].isdigit():
69+ # GDK has some busted constant names like
70+ # Gdk.EventType.2BUTTON_PRESS
71+ continue
72+
73+ val = constants[name]
74+
75+ strval = str(val)
76+ if type(val) is str:
77+ strval = '"%s"' % str(val).replace("\\", "\\\\")
78+ ret += "%s = %s\n" % (name, strval)
79+
80+ if ret:
81+ ret += "\n\n"
82+ if functions:
83+ ret += "# %s functions\n\n" % parent.__name__
84+ for name in sorted(functions):
85+ func = functions[name]
86+ ret += "def %s(*args, **kwargs):\n" % name
87+ ret += " pass\n"
88+
89+ if ret:
90+ ret += "\n\n"
91+ if methods:
92+ ret += "# %s methods\n\n" % parent.__name__
93+ for name in sorted(methods):
94+ func = methods[name]
95+ ret += "def %s(self, *args, **kwargs):\n" % name
96+ ret += " pass\n"
97+
98+ if ret:
99+ ret += "\n\n"
100+ if classes:
101+ ret += "# %s classes\n\n" % parent.__name__
102+ for name in sorted(classes):
103+ ret += "class %s(object):\n" % name
104+
105+ classret = _gi_build_stub(classes[name])
106+ if not classret:
107+ classret = "pass\n"
108+
109+ for line in classret.splitlines():
110+ ret += " " + line + "\n"
111+ ret += "\n"
112+
113+ return ret
114+
115+# Overwrite Module.module_import to _actually_ import the introspected module if
116+# it's a gi module, then build stub code by examining its info and get an astng
117+# from that
118+
119+from astroid.scoped_nodes import Module
120+_orig_import_module = Module.import_module
121+
122+def _new_import_module(self, modname, relative_only=False, level=None):
123+ # Could be a static piece of gi.repository or whatever unrelated module,
124+ # let that fall through
125+ try:
126+ return _orig_import_module(self, modname, relative_only, level)
127+ except AstroidBuildingException:
128+ # we only consider gi.repository submodules
129+ if not modname.startswith('gi.repository.'):
130+ if relative_only and level is None:
131+ level = 0
132+ modname = self.relative_to_absolute_name(modname, level)
133+ if not modname.startswith('gi.repository.'):
134+ raise
135+ # build astroid representation unless we already tried so
136+ if modname not in _inspected_modules:
137+ modnames = [modname]
138+ # GLib and GObject have some special case handling
139+ # in pygobject that we need to cope with
140+ if modname == 'gi.repository.GLib':
141+ modnames.append('gi._glib')
142+ elif modname == 'gi.repository.GObject':
143+ modnames.append('gi._gobject')
144+ try:
145+ modcode = ''
146+ for m in modnames:
147+ __import__(m)
148+ modcode += _gi_build_stub(sys.modules[m])
149+ except ImportError:
150+ astng = _inspected_modules[modname] = None
151+ else:
152+ astng = AstroidBuilder(MANAGER).string_build(modcode, modname)
153+ _inspected_modules[modname] = astng
154+ else:
155+ astng = _inspected_modules[modname]
156+ if astng is None:
157+ raise AstroidBuildingException('Failed to import module %r' % modname)
158+ return astng
159+
160+Module.import_module = _new_import_module
161
162=== modified file 'brain/py2gi.py'
163--- brain/py2gi.py 2014-01-04 12:14:12 +0000
164+++ brain/py2gi.py 2014-04-11 15:21:41 +0000
165@@ -5,6 +5,7 @@
166
167 import inspect
168 import sys
169+import re
170
171 from astroid import MANAGER, AstroidBuildingException
172 from astroid.builder import AstroidBuilder
173@@ -12,6 +13,7 @@
174
175 _inspected_modules = {}
176
177+_identifier_re = r'^[A-Za-z_]\w*$'
178
179 def _gi_build_stub(parent):
180 """
181@@ -23,9 +25,13 @@
182 constants = {}
183 methods = {}
184 for name in dir(parent):
185- if not name or name.startswith("__"):
186- # GLib.IConv has a parameter named "" :/
187- continue
188+ if name.startswith("__"):
189+ continue
190+
191+ # Check if this is a valid name in python
192+ if not re.match(_identifier_re, name):
193+ continue
194+
195 try:
196 obj = getattr(parent, name)
197 except:
198@@ -46,6 +52,12 @@
199 str(obj).startswith("<GType ") or
200 inspect.isdatadescriptor(obj)):
201 constants[name] = 0
202+ elif callable(obj):
203+ # Fall back to a function for anything callable
204+ functions[name] = obj
205+ else:
206+ # Assume everything else is some manner of constant
207+ constants[name] = 0
208
209 ret = ""
210
211
212=== modified file 'debian/changelog'
213--- debian/changelog 2014-01-04 12:14:12 +0000
214+++ debian/changelog 2014-04-11 15:21:41 +0000
215@@ -1,3 +1,10 @@
216+astroid (1.0.1-1ubuntu1) trusty; urgency=medium
217+
218+ * debian/patch/git_fa1312a4d7aa.patch
219+ + fix gi instrospections issues (lp: #1306674)
220+
221+ -- Leo Iannacone <l3on@ubuntu.com> Fri, 11 Apr 2014 17:15:12 +0200
222+
223 astroid (1.0.1-1) unstable; urgency=low
224
225 * Initial release (Closes: #734075)
226
227=== modified file 'debian/control'
228--- debian/control 2014-01-04 12:14:12 +0000
229+++ debian/control 2014-04-11 15:21:41 +0000
230@@ -1,7 +1,8 @@
231 Source: astroid
232 Section: python
233 Priority: optional
234-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
235+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
236+XSBC-Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
237 Uploaders: Sandro Tosi <morph@debian.org>
238 Build-Depends: debhelper (>= 9.0.0), python, python3
239 Standards-Version: 3.9.5
240
241=== added directory 'debian/patches'
242=== added file 'debian/patches/git_fa1312a4d7aa.patch'
243--- debian/patches/git_fa1312a4d7aa.patch 1970-01-01 00:00:00 +0000
244+++ debian/patches/git_fa1312a4d7aa.patch 2014-04-11 15:21:41 +0000
245@@ -0,0 +1,57 @@
246+From: User Sylvain Thénault <sylvain.thenault@logilab.fr>
247+Subject: backport gi related changes from pylint-brain
248+Origin: upstream, https://bitbucket.org/logilab/astroid/commits/fa1312a4d7aa
249+
250+Bug: https://bitbucket.org/logilab/astroid/issue/22/patch-brain-pygi-fix-function-inspection
251+Bug: https://bitbucket.org/logilab/astroid/issue/19/syntaxerror-when-examining-gi-modules
252+Bug-Debian: http://bugs.debian.org/744225
253+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1306674
254+
255+diff --git a/brain/py2gi.py b/brain/py2gi.py
256+--- a/brain/py2gi.py
257++++ b/brain/py2gi.py
258+@@ -5,6 +5,7 @@
259+
260+ import inspect
261+ import sys
262++import re
263+
264+ from astroid import MANAGER, AstroidBuildingException
265+ from astroid.builder import AstroidBuilder
266+@@ -12,6 +13,7 @@
267+
268+ _inspected_modules = {}
269+
270++_identifier_re = r'^[A-Za-z_]\w*$'
271+
272+ def _gi_build_stub(parent):
273+ """
274+@@ -23,9 +25,13 @@
275+ constants = {}
276+ methods = {}
277+ for name in dir(parent):
278+- if not name or name.startswith("__"):
279+- # GLib.IConv has a parameter named "" :/
280++ if name.startswith("__"):
281+ continue
282++
283++ # Check if this is a valid name in python
284++ if not re.match(_identifier_re, name):
285++ continue
286++
287+ try:
288+ obj = getattr(parent, name)
289+ except:
290+@@ -46,6 +52,12 @@
291+ str(obj).startswith("<GType ") or
292+ inspect.isdatadescriptor(obj)):
293+ constants[name] = 0
294++ elif callable(obj):
295++ # Fall back to a function for anything callable
296++ functions[name] = obj
297++ else:
298++ # Assume everything else is some manner of constant
299++ constants[name] = 0
300+
301+ ret = ""
302+
303
304=== added file 'debian/patches/series'
305--- debian/patches/series 1970-01-01 00:00:00 +0000
306+++ debian/patches/series 2014-04-11 15:21:41 +0000
307@@ -0,0 +1,1 @@
308+git_fa1312a4d7aa.patch

Subscribers

People subscribed via source and target branches

to all changes: