@@ -21,7 +21,9 @@ If ``pygments`` is installed *devtools* will colourise output to make it even mo
2121chances are you already have pygments installed if you're using ipython, otherwise it can be installed along
2222with *devtools * via ``pip install devtools[pygments] ``.
2323
24- debug print
24+ *python-devtools * has no requirements beyond python and optionally pygments.
25+
26+ Debug print
2527-----------
2628
2729Example:
@@ -40,6 +42,9 @@ you found down the back of a chair on the tube:
4042* each argument is printed "pretty" on a new line with
4143* if ``pygments `` is installed the output will be highlighted
4244
45+ Complex usage
46+ .............
47+
4348a more complex example of ``debug `` shows more of what it can do.
4449
4550.. literalinclude :: examples/2_input.py
@@ -49,9 +54,53 @@ Will output:
4954.. image :: examples/2_output.png
5055
5156
57+ Usage without import
58+ ....................
5259
53- .. include :: ../HISTORY.rst
60+ We all know the annoyance of running code only to discover a missing import, this can be particularly
61+ frustrating when the function you're using isn't used except during development.
62+
63+ You can setup your environment to make ``debug `` available at all times by editing ``sitecustomize.py ``,
64+ with ubuntu and python3.6 this file can be found at ``/usr/lib/python3.6/sitecustomize.py `` but you might
65+ need to look elsewhere depending on your OS/python version.
66+
67+ Add the following to ``sitecustomize.py ``
68+
69+ .. literalinclude :: examples/sitecustomize.py
70+
71+ The ``ImportError `` exception is important since you'll want python to run fine even if *devtools * isn't installed.
72+
73+ This approach has another advantage: if you forget to remove ``debug(...) `` calls from your code, CI
74+ (which won't have devtools installed) should fail both on execution and linting, meaning you don't end up with
75+ extraneous debug calls in production code.
76+
77+ Other Tools
78+ -----------
5479
80+ Prettier print
81+ ..............
82+
83+ Python comes with `pretty print <https://docs.python.org/3/library/pprint.html >`_, problem is quite often
84+ it's not that pretty, it also doesn't cope well with non standard python objects (think numpy arrays or
85+ django querysets) which have their own pretty print functionality.
86+
87+ To get round this *devtools * comes with prettier print, my take on pretty printing. You can see it in use above
88+ in ``debug() ``, but you can also call it directly:
89+
90+ .. literalinclude :: examples/prettier.py
91+
92+ For more details on prettier printing, see
93+ `prettier.py <https://github.com/samuelcolvin/python-devtools/blob/master/devtools/prettier.py >`_.
94+
95+ ANSI terminal colours
96+ .....................
97+
98+ .. literalinclude :: examples/ansi_colours.py
99+
100+ For more details on ansi colours, see
101+ `ansi.py <https://github.com/samuelcolvin/python-devtools/blob/master/devtools/ansi.py >`_.
102+
103+ .. include :: ../HISTORY.rst
55104
56105.. |pypi | image :: https://img.shields.io/pypi/v/python-devtools.svg
57106 :target: https://pypi.python.org/pypi/python-devtools
0 commit comments