Skip to content

Commit b6ffb9d

Browse files
committed
Add something in the cookbook.
1 parent c4c94e7 commit b6ffb9d

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

docs/cookbook.rst

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,58 @@
22
Cookbook
33
========
44

5-
TODO
5+
.. epigraph::
6+
7+
When in doubt, use hunter.
8+
9+
Packaging
10+
=========
11+
12+
I frequently use Hunter to figure out how distutils/setuptools work. It's very hard to figure out what's going on by just
13+
looking at the code - lots of stuff happens at runtime. If you ever tried to write a custom command you know what I mean.
14+
15+
To show everything that is being run::
16+
17+
PYTHONHUNTER='module_startswith=["setuptools", "distutils", "wheel"]' python setup.py bdist_wheel
18+
19+
If you want too see some interesting variables::
20+
21+
PYTHONHUNTER='module_startswith=["setuptools", "distutils", "wheel"], actions=[CodePrinter, VarsPrinter("self.bdist_dir")]' python setup.py bdist_wheel
22+
23+
Typical
24+
=======
25+
26+
Normally you'd only want to look at your code. For that purpose, there's the ``stdlib`` option. Set it to ``False``.
27+
28+
Building a bit on the previous example, if I have a ``build`` Distutils command and I only want to see my code then I'd run
29+
this::
30+
31+
PYTHONHUNTER='stdlib=False' python setup.py build
32+
33+
But this also means I'd be seeing anything from ``site-packages``. I could filter on only the events from the current
34+
directory (assuming the filename is going to be a relative path)::
35+
36+
PYTHONHUNTER='~Q(filename_startswith="/")' python setup.py build
37+
38+
Needle in the haystack
39+
======================
40+
41+
If the needle might be though the stdlib then you got not choice. But some of the `hay` is very verbose and useless, like
42+
stuff from the ``re`` module.
43+
44+
Note that there are few "hidden" modules like ``sre``, ``sre_parse``, ``sre_compile`` etc. You can filter that out with::
45+
46+
PYTHONHUNTER='~Q(module_regex="(re|sre.*)$")'
47+
48+
Although filtering out that regex stuff can cut down lots of useless output you usually still get lots of output.
49+
50+
Another way, if you got at least some vague idea of what might be going on is to "grep" for sourcecode. Example, to show all
51+
the code that does something with a ``build_dir`` property::
52+
53+
PYTHONHUNTER='source_contains=".build_dir"'
54+
55+
You could even extend that a bit to dump some variables::
56+
57+
PYTHONHUNTER='source_contains=".build_dir", actions=[CodePrinter, VarsPrinter("self.build_dir")]'
58+
59+

0 commit comments

Comments
 (0)