@@ -23,8 +23,8 @@ If ``pygments`` is installed *devtools* will colourise output to make it even mo
2323Chances are you already have pygments installed if you're using ipython, otherwise it can be installed along
2424with *devtools * via ``pip install devtools[pygments] ``.
2525
26- Debug print
27- -----------
26+ Debug
27+ -----
2828
2929Somehow in the 26 years (and counting) of active development of python, no one thought to add a simple
3030and readable way to print stuff during development. (If you know why this is, I'd love to hear).
@@ -45,13 +45,10 @@ you found down the back of a chair on the tube:
4545
4646* each output is prefixed with the file, line number and function where ``debug `` was called
4747* the variable name or expression being printed is shown
48- * each argument is printed "pretty" on a new line
48+ * each argument is printed "pretty" on a new line, see :ref: ` prettier print < prettier_print >`
4949* if ``pygments `` is installed the output is highlighted
5050
51- Complex usage
52- .............
53-
54- a more complex example of ``debug `` shows more of what it can do.
51+ A more complex example of ``debug `` shows more of what it can do.
5552
5653.. literalinclude :: examples/example2.py
5754
@@ -62,34 +59,14 @@ a more complex example of ``debug`` shows more of what it can do.
6259.. raw :: html
6360 :file: ./examples/example2.html
6461
65- Usage without import
66- ....................
67-
68- We all know the annoyance of running code only to discover a missing import, this can be particularly
69- frustrating when the function you're using isn't used except during development.
70-
71- You can setup your environment to make ``debug `` available at all times by editing ``sitecustomize.py ``,
72- with ubuntu and python3.6 this file can be found at ``/usr/lib/python3.6/sitecustomize.py `` but you might
73- need to look elsewhere depending on your OS/python version.
74-
75- Add the following to ``sitecustomize.py ``
76-
77- .. literalinclude :: examples/sitecustomize.py
78-
79- The ``ImportError `` exception is important since you'll want python to run fine even if *devtools * isn't installed.
80-
81- This approach has another advantage: if you forget to remove ``debug(...) `` calls from your code, CI
82- (which won't have devtools installed) should fail both on execution and linting, meaning you don't end up with
83- extraneous debug calls in production code.
84-
8562Other debug tools
8663.................
8764
8865The debug namespace includes a number of other useful functions:
8966
90- * ``format() `` same as calling ``debug() `` but returns a ``DebugOutput `` rather than printing the output
91- * ``timer() `` returns an instance of *devtool's * ``Timer `` class suitable for timing code execution
92- * ``breakpoint() `` introduces a breakpoint using ``pdb ``
67+ * ``debug. format() `` same as calling ``debug() `` but returns a ``DebugOutput `` rather than printing the output
68+ * ``debug. timer() `` returns an instance of *devtool's * ``Timer `` class suitable for timing code execution
69+ * ``debug. breakpoint() `` introduces a breakpoint using ``pdb ``
9370
9471
9572.. literalinclude :: examples/more_debug.py
@@ -101,11 +78,10 @@ The debug namespace includes a number of other useful functions:
10178.. raw :: html
10279 :file: ./examples/more_debug.html
10380
104- Other Tools
105- -----------
81+ .. _prettier_print :
10682
10783Prettier print
108- ..............
84+ --------------
10985
11086Python comes with `pretty print <https://docs.python.org/3/library/pprint.html >`_, problem is quite often
11187it's not that pretty, it also doesn't cope well with non standard python objects (think numpy arrays or
@@ -127,13 +103,33 @@ For more details on prettier printing, see
127103`prettier.py <https://github.com/samuelcolvin/python-devtools/blob/master/devtools/prettier.py >`_.
128104
129105ANSI terminal colours
130- .....................
106+ ---------------------
131107
132108.. literalinclude :: examples/ansi_colours.py
133109
134110For more details on ansi colours, see
135111`ansi.py <https://github.com/samuelcolvin/python-devtools/blob/master/devtools/ansi.py >`_.
136112
113+ Usage without import
114+ --------------------
115+
116+ We all know the annoyance of running code only to discover a missing import, this can be particularly
117+ frustrating when the function you're using isn't used except during development.
118+
119+ You can setup your environment to make ``debug `` available at all times by editing ``sitecustomize.py ``,
120+ with ubuntu and python3.6 this file can be found at ``/usr/lib/python3.6/sitecustomize.py `` but you might
121+ need to look elsewhere depending on your OS/python version.
122+
123+ Add the following to ``sitecustomize.py ``
124+
125+ .. literalinclude :: examples/sitecustomize.py
126+
127+ The ``ImportError `` exception is important since you'll want python to run fine even if *devtools * isn't installed.
128+
129+ This approach has another advantage: if you forget to remove ``debug(...) `` calls from your code, CI
130+ (which won't have devtools installed) should fail both on execution and linting, meaning you don't end up with
131+ extraneous debug calls in production code.
132+
137133.. include :: ../HISTORY.rst
138134
139135.. |pypi | image :: https://img.shields.io/pypi/v/devtools.svg
0 commit comments