Skip to content

Commit e7c124d

Browse files
committed
ENH: Version bump, docs, pippification.
1 parent 8b11e1d commit e7c124d

File tree

4 files changed

+69
-64
lines changed

4 files changed

+69
-64
lines changed

README.rst

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
11
line_profiler and kernprof
22
--------------------------
33

4-
line_profiler is a module for doing line-by-line profiling of functions.
5-
kernprof is a convenient script for running either line_profiler or the Python
4+
`line_profiler` is a module for doing line-by-line profiling of functions.
5+
kernprof is a convenient script for running either `line_profiler` or the Python
66
standard library's cProfile or profile modules, depending on what is available.
77

88
They are available under a `BSD license`_.
99

10-
.. _BSD license: http://packages.python.org/line_profiler/LICENSE.txt
10+
.. _BSD license: https://raw.githubusercontent.com/rkern/line_profiler/master/LICENSE.txt
1111

1212
.. contents::
1313

1414

1515
Installation
1616
============
1717

18-
Source releases and any binaries can be downloaded from the PyPI link.
18+
Releases of `line_profiler` can be installed using pip_::
1919

20-
http://pypi.python.org/pypi/line_profiler
20+
$ pip install line_profiler
2121

22-
The current release of the kernprof.py script may be downloaded separately here:
22+
Source releases and any binaries can be downloaded from the PyPI link.
2323

24-
http://packages.python.org/line_profiler/kernprof.py
24+
http://pypi.python.org/pypi/line_profiler
2525

26-
To check out the development sources, you can use Mercurial_::
26+
To check out the development sources, you can use Git_::
2727

28-
$ hg clone https://bitbucket.org/robertkern/line_profiler
28+
$ git clone https://github.com/rkern/line_profiler.git
2929

3030
You may also download source tarballs of any snapshot from that URL.
3131

32-
Source releases will require a C compiler in order to build line_profiler. In
33-
addition, Mercurial checkouts will also require Cython_ >= 0.10. Source releases
32+
Source releases will require a C compiler in order to build `line_profiler`.
33+
In addition, git checkouts will also require Cython_ >= 0.10. Source releases
3434
on PyPI should contain the pregenerated C sources, so Cython should not be
3535
required in that case.
3636

37-
kernprof.py is a single-file pure Python script and does not require a compiler.
38-
If you wish to use it to run cProfile and not line-by-line profiling, you may
39-
copy it to a directory on your PATH manually and avoid trying to build any
40-
C extensions.
41-
42-
In order to build and install line_profiler, you will simply use the standard
43-
`build and install`_ for most Python packages::
44-
45-
$ python setup.py install
37+
`kernprof.py` is a single-file pure Python script and does not require
38+
a compiler. If you wish to use it to run cProfile and not line-by-line
39+
profiling, you may copy it to a directory on your `PATH` manually and avoid
40+
trying to build any C extensions.
4641

47-
.. _Mercurial: http://www.selenic.com/mercurial/wiki/
42+
.. _git: http://git-scm.com/
4843
.. _Cython: http://www.cython.org
4944
.. _build and install: http://docs.python.org/install/index.html
5045

@@ -75,27 +70,29 @@ of each individual line inside those functions. In a typical workflow, one only
7570
cares about line timings of a few functions because wading through the results
7671
of timing every single line of code would be overwhelming. However, LineProfiler
7772
does need to be explicitly told what functions to profile. The easiest way to
78-
get started is to use the kernprof.py script.
73+
get started is to use the `kernprof` script. ::
7974

80-
If you use "kernprof.py [-l/--line-by-line] script_to_profile.py", an instance
81-
of LineProfiler will be created and inserted into the __builtins__ namespace
82-
with the name "profile". It has been written to be used as a decorator, so in
83-
your script, you can decorate any function you want to profile with @profile. ::
75+
$ kernprof -l script_to_profile.py
76+
77+
`kernprof` will create an instance of LineProfiler and insert it into the
78+
`__builtins__` namespace with the name `profile`. It has been written to be
79+
used as a decorator, so in your script, you can decorate any function you want
80+
to profile with @profile. ::
8481

8582
@profile
8683
def slow_function(a, b, c):
8784
...
8885

89-
The default behavior of kernprof is to put the results into a binary file
90-
script_to_profile.py.lprof . You can tell kernprof to immediately view the
86+
The default behavior of `kernprof` is to put the results into a binary file
87+
script_to_profile.py.lprof . You can tell `kernprof` to immediately view the
9188
formatted results at the terminal with the [-v/--view] option. Otherwise, you
9289
can view the results later like so::
9390

9491
$ python -m line_profiler script_to_profile.py.lprof
9592

9693
For example, here are the results of profiling a single function from
9794
a decorated version of the pystone.py benchmark (the first two lines are output
98-
from pystone.py, not kernprof)::
95+
from `pystone.py`, not `kernprof`)::
9996

10097
Pystone(1.1) time for 50000 passes = 2.48
10198
This machine benchmarks at 20161.3 pystones/second
@@ -148,21 +145,11 @@ line. There are six columns of information.
148145
If you are using IPython, there is an implementation of an %lprun magic command
149146
which will let you specify functions to profile and a statement to execute. It
150147
will also add its LineProfiler instance into the __builtins__, but typically,
151-
you would not use it like that. For IPython 0.10, you can install it by editing
152-
the IPython configuration file ~/.ipython/ipy_user_conf.py to add the following
153-
lines::
154-
155-
# These two lines are standard and probably already there.
156-
import IPython.ipapi
157-
ip = IPython.ipapi.get()
158-
159-
# These two are the important ones.
160-
import line_profiler
161-
ip.expose_magic('lprun', line_profiler.magic_lprun)
148+
you would not use it like that.
162149

163150
For IPython 0.11+, you can install it by editing the IPython configuration file
164-
~/.ipython/profile_default/ipython_config.py to add the `'line_profiler'` item
165-
to the extensions list::
151+
`~/.ipython/profile_default/ipython_config.py` to add the `'line_profiler'`
152+
item to the extensions list::
166153

167154
c.TerminalIPythonApp.extensions = [
168155
'line_profiler',
@@ -200,7 +187,7 @@ the timer unit.
200187
kernprof
201188
========
202189

203-
kernprof also works with cProfile, its third-party incarnation lsprof, or the
190+
`kernprof` also works with cProfile, its third-party incarnation lsprof, or the
204191
pure-Python profile module depending on what is available. It has a few main
205192
features:
206193

@@ -324,19 +311,19 @@ Frequently Asked Questions
324311
projects for modules as small as these. However, kernprof.py is
325312
a standalone, pure Python script that can be used to do function profiling
326313
with just the Python standard library. You may grab it and install it by
327-
itself without line_profiler.
314+
itself without `line_profiler`.
328315

329-
* Do I need a C compiler to build line_profiler? kernprof.py?
316+
* Do I need a C compiler to build `line_profiler`? kernprof.py?
330317

331318
You do need a C compiler for line_profiler. kernprof.py is a pure Python
332319
script and can be installed separately, though.
333320

334-
* Do I need Cython to build line_profiler?
321+
* Do I need Cython to build `line_profiler`?
335322

336323
You should not have to if you are building from a released source tarball.
337324
It should contain the generated C sources already. If you are running into
338325
problems, that may be a bug; let me know. If you are building from
339-
a Mercurial checkout or snapshot, you will need Cython to generate the
326+
a git checkout or snapshot, you will need Cython to generate the
340327
C sources. You will probably need version 0.10 or higher. There is a bug in
341328
some earlier versions in how it handles NULL PyObject* pointers.
342329

@@ -367,16 +354,25 @@ now. Maybe later. Contributions accepted!
367354
Bugs and Such
368355
=============
369356

370-
If you find a bug, or a missing feature you really want added, please post to
371-
the enthought-dev_ mailing list or email the author at
372-
357+
Bugs and pull requested can be submitted on GitHub_.
373358

374-
.. _enthought-dev : https://mail.enthought.com/mailman/listinfo/enthought-dev
359+
.. _GitHub: https://github.com/rkern/line_profiler
375360

376361

377362
Changes
378363
=======
379364

365+
1.0
366+
~~~
367+
* ENH: Python 3 support. Thanks to the long-suffering Mikhail Korobov for being
368+
patient.
369+
* ENH: The `stripzeros` and `add_module` options. Thanks to Erik Tollerud for
370+
contributing it.
371+
* ENH: Support for IPython cell blocks. Thanks to Michael Forbes for adding
372+
this feature.
373+
* ENH: Better warnings when building without Cython. Thanks to David Cournapeau
374+
for spotting this.
375+
380376
1.0b3
381377
~~~~~
382378

@@ -396,4 +392,3 @@ Changes
396392
~~~~~
397393

398394
* Initial release.
399-

dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cython

kernprof.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def find_script(script_name):
146146
raise SystemExit(1)
147147

148148

149-
def main(args):
149+
def main(args=None):
150+
if args is None:
151+
args = sys.argv
150152
usage = "%prog [-s setupfile] [-o output_file_path] scriptfile [arg] ..."
151153
parser = optparse.OptionParser(usage=usage, version="%prog 1.0b2")
152154
parser.allow_interspersed_args = False
@@ -230,4 +232,3 @@ def main(args):
230232

231233
if __name__ == '__main__':
232234
sys.exit(main(sys.argv))
233-

setup.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#!/usr/bin/env python
2-
import os.path
1+
import os
2+
3+
# Monkeypatch distutils.
4+
import setuptools
35

46
import distutils.errors
57
from distutils.core import setup
@@ -15,10 +17,11 @@
1517
line_profiler_source = '_line_profiler.c'
1618
if not os.path.exists(line_profiler_source):
1719
raise distutils.errors.DistutilsError("""\
18-
You need cython to build the line_profiler from a mercurial checkout, or
19-
alternatively use a release tarball from PyPI to build it without cython.""")
20+
You need Cython to build the line_profiler from a git checkout, or
21+
alternatively use a release tarball from PyPI to build it without Cython.""")
2022
else:
21-
warn("Could not import Cython. Using pre-generated C file if available.")
23+
warn("Could not import Cython. "
24+
"Using the available pre-generated C file.")
2225

2326
long_description = """\
2427
line_profiler will profile the time individual lines of code take to execute.
@@ -32,12 +35,12 @@
3235

3336
setup(
3437
name = 'line_profiler',
35-
version = '1.0b3',
38+
version = '1.0',
3639
author = 'Robert Kern',
3740
author_email = '[email protected]',
3841
description = 'Line-by-line profiler.',
3942
long_description = long_description,
40-
url = 'http://packages.python.org/line_profiler',
43+
url = 'https://github.com/rkern/line_profiler',
4144
ext_modules = [
4245
Extension('_line_profiler',
4346
sources=[line_profiler_source, 'timers.c', 'unset_trace.c'],
@@ -46,7 +49,7 @@
4649
],
4750
license = "BSD",
4851
classifiers = [
49-
"Development Status :: 4 - Beta",
52+
"Development Status :: 5 - Production/Stable",
5053
"Intended Audience :: Developers",
5154
"License :: OSI Approved :: BSD License",
5255
"Operating System :: OS Independent",
@@ -58,11 +61,16 @@
5861
'Programming Language :: Python :: 3',
5962
'Programming Language :: Python :: 3.2',
6063
'Programming Language :: Python :: 3.3',
64+
'Programming Language :: Python :: 3.4',
6165
'Programming Language :: Python :: Implementation :: CPython',
6266
"Topic :: Software Development",
6367
],
64-
py_modules = ['line_profiler'],
65-
scripts = ['kernprof.py'],
68+
py_modules = ['line_profiler', 'kernprof'],
69+
entry_points = {
70+
'console_scripts': [
71+
'kernprof=kernprof:main',
72+
],
73+
},
6674
cmdclass = cmdclass,
6775
)
6876

0 commit comments

Comments
 (0)