Gentoo Archives: gentoo-commits

From: David Seifert <soap@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/line_profiler/files/, dev-python/line_profiler/
Date: Thu, 25 Aug 2016 09:04:42
Message-Id: 1472115819.f03bc7da70ad8ba36fb23416c1f6ebc7705b9801.soap@gentoo
1 commit: f03bc7da70ad8ba36fb23416c1f6ebc7705b9801
2 Author: Marius Brehler <marbre <AT> linux <DOT> sungazer <DOT> de>
3 AuthorDate: Wed Aug 24 12:53:44 2016 +0000
4 Commit: David Seifert <soap <AT> gentoo <DOT> org>
5 CommitDate: Thu Aug 25 09:03:39 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f03bc7da
7
8 dev-python/line_profiler: Bump to 1.0-r1 (including patches); Bump to EAPI=6
9
10 Package-Manager: portage-2.2.28
11 Closes: https://github.com/gentoo/gentoo/pull/2136
12
13 Signed-off-by: David Seifert <soap <AT> gentoo.org>
14
15 ...line_profiler-1.0-fix-name-from-copypasta.patch | 25 ++
16 ...ne_profiler-1.0-ipython-5.0-compatibility.patch | 299 +++++++++++++++++++++
17 .../line_profiler/line_profiler-1.0-r1.ebuild | 33 +++
18 3 files changed, 357 insertions(+)
19
20 diff --git a/dev-python/line_profiler/files/line_profiler-1.0-fix-name-from-copypasta.patch b/dev-python/line_profiler/files/line_profiler-1.0-fix-name-from-copypasta.patch
21 new file mode 100644
22 index 00000000..e51a24f
23 --- /dev/null
24 +++ b/dev-python/line_profiler/files/line_profiler-1.0-fix-name-from-copypasta.patch
25 @@ -0,0 +1,25 @@
26 +From 717df8c2088087ea4bce870400a2c99b36b0e53d Mon Sep 17 00:00:00 2001
27 +From: Robert Kern <rkern@×××××××××.com>
28 +Date: Mon, 21 Dec 2015 19:25:51 +0000
29 +Subject: [PATCH] BUG: fix name from copypasta.
30 +
31 +Fixes #43
32 +
33 +Thanks, @anntzer!
34 +---
35 + line_profiler.py | 2 +-
36 + 1 file changed, 1 insertion(+), 1 deletion(-)
37 +
38 +diff --git a/line_profiler.py b/line_profiler.py
39 +index 4480c7b..aac01c8 100755
40 +--- a/line_profiler.py
41 ++++ b/line_profiler.py
42 +@@ -303,7 +303,7 @@ def magic_lprun(self, parameter_s=''):
43 + mod = __import__(modname, fromlist=[''])
44 + profile.add_module(mod)
45 + except Exception as e:
46 +- raise UsageError('Could not find module %r.\n%s: %s' % (name,
47 ++ raise UsageError('Could not find module %r.\n%s: %s' % (modname,
48 + e.__class__.__name__, e))
49 +
50 + # Add the profiler to the builtins for @profile.
51
52 diff --git a/dev-python/line_profiler/files/line_profiler-1.0-ipython-5.0-compatibility.patch b/dev-python/line_profiler/files/line_profiler-1.0-ipython-5.0-compatibility.patch
53 new file mode 100644
54 index 00000000..04caa8c
55 --- /dev/null
56 +++ b/dev-python/line_profiler/files/line_profiler-1.0-ipython-5.0-compatibility.patch
57 @@ -0,0 +1,299 @@
58 +https://github.com/rkern/line_profiler/pull/65
59 +
60 +From 677a43104dd537b515c06eaeffa77f8dcfa5a76e Mon Sep 17 00:00:00 2001
61 +From: Brett Olsen <brett.olsen@×××××××.com>
62 +Date: Tue, 12 Jul 2016 10:18:28 -0700
63 +Subject: [PATCH 1] Update for compatibility with IPython 5.0
64 +
65 +Also tested with IPython 4.1.1. Replaces the depreciated ip.define_magic() method with ip.register_magics() and some modifications to handle the different API required.
66 +---
67 + line_profiler.py | 245 ++++++++++++++++++++++++++++---------------------------
68 + 1 file changed, 125 insertions(+), 120 deletions(-)
69 +
70 +diff --git a/line_profiler.py b/line_profiler.py
71 +index aac01c8..7645997 100755
72 +--- a/line_profiler.py
73 ++++ b/line_profiler.py
74 +@@ -17,6 +17,8 @@
75 + import os
76 + import sys
77 +
78 ++from IPython.core.magic import (Magics, magics_class, line_magic)
79 ++
80 + from _line_profiler import LineProfiler as CLineProfiler
81 +
82 + # Python 2/3 compatibility utils
83 +@@ -226,150 +228,153 @@ def show_text(stats, unit, stream=None, stripzeros=False):
84 + for (fn, lineno, name), timings in sorted(stats.items()):
85 + show_func(fn, lineno, name, stats[fn, lineno, name], unit, stream=stream, stripzeros=stripzeros)
86 +
87 +-# A %lprun magic for IPython.
88 +-def magic_lprun(self, parameter_s=''):
89 +- """ Execute a statement under the line-by-line profiler from the
90 +- line_profiler module.
91 ++@magics_class
92 ++class LineProfilerMagics(Magics):
93 +
94 +- Usage:
95 +- %lprun -f func1 -f func2 <statement>
96 ++ @line_magic
97 ++ def lprun(self, parameter_s=''):
98 ++ """ Execute a statement under the line-by-line profiler from the
99 ++ line_profiler module.
100 +
101 +- The given statement (which doesn't require quote marks) is run via the
102 +- LineProfiler. Profiling is enabled for the functions specified by the -f
103 +- options. The statistics will be shown side-by-side with the code through the
104 +- pager once the statement has completed.
105 ++ Usage:
106 ++ %lprun -f func1 -f func2 <statement>
107 +
108 +- Options:
109 ++ The given statement (which doesn't require quote marks) is run via the
110 ++ LineProfiler. Profiling is enabled for the functions specified by the -f
111 ++ options. The statistics will be shown side-by-side with the code through the
112 ++ pager once the statement has completed.
113 +
114 +- -f <function>: LineProfiler only profiles functions and methods it is told
115 +- to profile. This option tells the profiler about these functions. Multiple
116 +- -f options may be used. The argument may be any expression that gives
117 +- a Python function or method object. However, one must be careful to avoid
118 +- spaces that may confuse the option parser. Additionally, functions defined
119 +- in the interpreter at the In[] prompt or via %run currently cannot be
120 +- displayed. Write these functions out to a separate file and import them.
121 ++ Options:
122 +
123 +- -m <module>: Get all the functions/methods in a module
124 ++ -f <function>: LineProfiler only profiles functions and methods it is told
125 ++ to profile. This option tells the profiler about these functions. Multiple
126 ++ -f options may be used. The argument may be any expression that gives
127 ++ a Python function or method object. However, one must be careful to avoid
128 ++ spaces that may confuse the option parser. Additionally, functions defined
129 ++ in the interpreter at the In[] prompt or via %run currently cannot be
130 ++ displayed. Write these functions out to a separate file and import them.
131 +
132 +- One or more -f or -m options are required to get any useful results.
133 ++ -m <module>: Get all the functions/methods in a module
134 +
135 +- -D <filename>: dump the raw statistics out to a pickle file on disk. The
136 +- usual extension for this is ".lprof". These statistics may be viewed later
137 +- by running line_profiler.py as a script.
138 ++ One or more -f or -m options are required to get any useful results.
139 +
140 +- -T <filename>: dump the text-formatted statistics with the code side-by-side
141 +- out to a text file.
142 ++ -D <filename>: dump the raw statistics out to a pickle file on disk. The
143 ++ usual extension for this is ".lprof". These statistics may be viewed later
144 ++ by running line_profiler.py as a script.
145 +
146 +- -r: return the LineProfiler object after it has completed profiling.
147 ++ -T <filename>: dump the text-formatted statistics with the code side-by-side
148 ++ out to a text file.
149 +
150 +- -s: strip out all entries from the print-out that have zeros.
151 +- """
152 +- # Local imports to avoid hard dependency.
153 +- from distutils.version import LooseVersion
154 +- import IPython
155 +- ipython_version = LooseVersion(IPython.__version__)
156 +- if ipython_version < '0.11':
157 +- from IPython.genutils import page
158 +- from IPython.ipstruct import Struct
159 +- from IPython.ipapi import UsageError
160 +- else:
161 +- from IPython.core.page import page
162 +- from IPython.utils.ipstruct import Struct
163 +- from IPython.core.error import UsageError
164 +-
165 +- # Escape quote markers.
166 +- opts_def = Struct(D=[''], T=[''], f=[], m=[])
167 +- parameter_s = parameter_s.replace('"', r'\"').replace("'", r"\'")
168 +- opts, arg_str = self.parse_options(parameter_s, 'rsf:m:D:T:', list_all=True)
169 +- opts.merge(opts_def)
170 +-
171 +- global_ns = self.shell.user_global_ns
172 +- local_ns = self.shell.user_ns
173 +-
174 +- # Get the requested functions.
175 +- funcs = []
176 +- for name in opts.f:
177 +- try:
178 +- funcs.append(eval(name, global_ns, local_ns))
179 +- except Exception as e:
180 +- raise UsageError('Could not find function %r.\n%s: %s' % (name,
181 +- e.__class__.__name__, e))
182 ++ -r: return the LineProfiler object after it has completed profiling.
183 +
184 +- profile = LineProfiler(*funcs)
185 ++ -s: strip out all entries from the print-out that have zeros.
186 ++ """
187 ++ # Local imports to avoid hard dependency.
188 ++ from distutils.version import LooseVersion
189 ++ import IPython
190 ++ ipython_version = LooseVersion(IPython.__version__)
191 ++ if ipython_version < '0.11':
192 ++ from IPython.genutils import page
193 ++ from IPython.ipstruct import Struct
194 ++ from IPython.ipapi import UsageError
195 ++ else:
196 ++ from IPython.core.page import page
197 ++ from IPython.utils.ipstruct import Struct
198 ++ from IPython.core.error import UsageError
199 ++
200 ++ # Escape quote markers.
201 ++ opts_def = Struct(D=[''], T=[''], f=[], m=[])
202 ++ parameter_s = parameter_s.replace('"', r'\"').replace("'", r"\'")
203 ++ opts, arg_str = self.parse_options(parameter_s, 'rsf:m:D:T:', list_all=True)
204 ++ opts.merge(opts_def)
205 ++
206 ++ global_ns = self.shell.user_global_ns
207 ++ local_ns = self.shell.user_ns
208 ++
209 ++ # Get the requested functions.
210 ++ funcs = []
211 ++ for name in opts.f:
212 ++ try:
213 ++ funcs.append(eval(name, global_ns, local_ns))
214 ++ except Exception as e:
215 ++ raise UsageError('Could not find function %r.\n%s: %s' % (name,
216 ++ e.__class__.__name__, e))
217 +
218 +- # Get the modules, too
219 +- for modname in opts.m:
220 +- try:
221 +- mod = __import__(modname, fromlist=[''])
222 +- profile.add_module(mod)
223 +- except Exception as e:
224 +- raise UsageError('Could not find module %r.\n%s: %s' % (modname,
225 +- e.__class__.__name__, e))
226 +-
227 +- # Add the profiler to the builtins for @profile.
228 +- if PY3:
229 +- import builtins
230 +- else:
231 +- import __builtin__ as builtins
232 ++ profile = LineProfiler(*funcs)
233 +
234 +- if 'profile' in builtins.__dict__:
235 +- had_profile = True
236 +- old_profile = builtins.__dict__['profile']
237 +- else:
238 +- had_profile = False
239 +- old_profile = None
240 +- builtins.__dict__['profile'] = profile
241 ++ # Get the modules, too
242 ++ for modname in opts.m:
243 ++ try:
244 ++ mod = __import__(modname, fromlist=[''])
245 ++ profile.add_module(mod)
246 ++ except Exception as e:
247 ++ raise UsageError('Could not find module %r.\n%s: %s' % (modname,
248 ++ e.__class__.__name__, e))
249 ++
250 ++ # Add the profiler to the builtins for @profile.
251 ++ if PY3:
252 ++ import builtins
253 ++ else:
254 ++ import __builtin__ as builtins
255 ++
256 ++ if 'profile' in builtins.__dict__:
257 ++ had_profile = True
258 ++ old_profile = builtins.__dict__['profile']
259 ++ else:
260 ++ had_profile = False
261 ++ old_profile = None
262 ++ builtins.__dict__['profile'] = profile
263 +
264 +- try:
265 + try:
266 +- profile.runctx(arg_str, global_ns, local_ns)
267 +- message = ''
268 +- except SystemExit:
269 +- message = """*** SystemExit exception caught in code being profiled."""
270 +- except KeyboardInterrupt:
271 +- message = ("*** KeyboardInterrupt exception caught in code being "
272 +- "profiled.")
273 +- finally:
274 +- if had_profile:
275 +- builtins.__dict__['profile'] = old_profile
276 +-
277 +- # Trap text output.
278 +- stdout_trap = StringIO()
279 +- profile.print_stats(stdout_trap, stripzeros='s' in opts)
280 +- output = stdout_trap.getvalue()
281 +- output = output.rstrip()
282 +-
283 +- if ipython_version < '0.11':
284 +- page(output, screen_lines=self.shell.rc.screen_length)
285 +- else:
286 +- page(output)
287 +- print(message, end="")
288 ++ try:
289 ++ profile.runctx(arg_str, global_ns, local_ns)
290 ++ message = ''
291 ++ except SystemExit:
292 ++ message = """*** SystemExit exception caught in code being profiled."""
293 ++ except KeyboardInterrupt:
294 ++ message = ("*** KeyboardInterrupt exception caught in code being "
295 ++ "profiled.")
296 ++ finally:
297 ++ if had_profile:
298 ++ builtins.__dict__['profile'] = old_profile
299 ++
300 ++ # Trap text output.
301 ++ stdout_trap = StringIO()
302 ++ profile.print_stats(stdout_trap, stripzeros='s' in opts)
303 ++ output = stdout_trap.getvalue()
304 ++ output = output.rstrip()
305 ++
306 ++ if ipython_version < '0.11':
307 ++ page(output, screen_lines=self.shell.rc.screen_length)
308 ++ else:
309 ++ page(output)
310 ++ print(message, end="")
311 +
312 +- dump_file = opts.D[0]
313 +- if dump_file:
314 +- profile.dump_stats(dump_file)
315 +- print('\n*** Profile stats pickled to file %r. %s' % (
316 +- dump_file, message))
317 ++ dump_file = opts.D[0]
318 ++ if dump_file:
319 ++ profile.dump_stats(dump_file)
320 ++ print('\n*** Profile stats pickled to file %r. %s' % (
321 ++ dump_file, message))
322 +
323 +- text_file = opts.T[0]
324 +- if text_file:
325 +- pfile = open(text_file, 'w')
326 +- pfile.write(output)
327 +- pfile.close()
328 +- print('\n*** Profile printout saved to text file %r. %s' % (
329 +- text_file, message))
330 ++ text_file = opts.T[0]
331 ++ if text_file:
332 ++ pfile = open(text_file, 'w')
333 ++ pfile.write(output)
334 ++ pfile.close()
335 ++ print('\n*** Profile printout saved to text file %r. %s' % (
336 ++ text_file, message))
337 +
338 +- return_value = None
339 +- if 'r' in opts:
340 +- return_value = profile
341 ++ return_value = None
342 ++ if 'r' in opts:
343 ++ return_value = profile
344 +
345 +- return return_value
346 ++ return return_value
347 +
348 +
349 + def load_ipython_extension(ip):
350 + """ API for IPython to recognize this module as an IPython extension.
351 + """
352 +- ip.define_magic('lprun', magic_lprun)
353 ++ ip.register_magics(LineProfilerMagics)
354 +
355 +
356 + def load_stats(filename):
357
358 diff --git a/dev-python/line_profiler/line_profiler-1.0-r1.ebuild b/dev-python/line_profiler/line_profiler-1.0-r1.ebuild
359 new file mode 100644
360 index 00000000..00e1e86
361 --- /dev/null
362 +++ b/dev-python/line_profiler/line_profiler-1.0-r1.ebuild
363 @@ -0,0 +1,33 @@
364 +# Copyright 1999-2016 Gentoo Foundation
365 +# Distributed under the terms of the GNU General Public License v2
366 +# $Id$
367 +
368 +EAPI=6
369 +
370 +PYTHON_COMPAT=( python2_7 python3_{4,5} )
371 +
372 +inherit distutils-r1
373 +
374 +DESCRIPTION="Line-by-line profiler"
375 +HOMEPAGE="https://github.com/rkern/line_profiler"
376 +SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
377 +KEYWORDS="~amd64"
378 +
379 +SLOT="0"
380 +LICENSE="BSD"
381 +KEYWORDS="~amd64 ~x86"
382 +IUSE="test"
383 +
384 +DEPEND="
385 + test? ( dev-python/pytest[${PYTHON_USEDEP}] )
386 + "
387 +
388 +PATCHES=(
389 + "${FILESDIR}/${P}-fix-name-from-copypasta.patch"
390 + "${FILESDIR}/${P}-ipython-5.0-compatibility.patch"
391 +)
392 +
393 +python_test() {
394 + "${PYTHON}" -m unittest discover -v "${S}"/tests/ \
395 + || die "Tests failed with ${EPYTHON}"
396 +}