A command line tool to read Python source code.
Update 5th of Nov 2021: we did not know it at the time, but this actually can be accomplished by Python's inspect
module! So you might want to use that over this tool, for more info see this Twitter thread.
You can install pybites-pysource
from PyPI:
pip install pybites-pysource
Or use pipx
if you want to have it available globally.
This tool uses Python 3.x
You can use pybites-pysource
:
$ pysource -m re.match
def match(pattern, string, flags=0):
"""Try to apply the pattern at the start of the string, returning
a Match object, or None if no match was found."""
return _compile(pattern, flags).match(string)
To show the resulting code with paging add -p
to the pysource
command, so in this case: pysource -m re.match -p
.
Check out our blog post for a demo.
If you want to dump pysource
's output to a vertical split window I recommend installing ConqueTerm
and then add this to your .vimrc
:
nmap <leader>s :ConqueTermVSplit pysource -m <C-R><C-A><CR>
Now if you hit <leader>s
(,s
in my case as my Vim leader key is ,
) on any object, it will open a split window with the source code (if it can be found, otherwise you will see a ModuleNotFoundError
).
To run the tests:
$ python setup.py test
See: Integrating with setuptools / python setup.py test / pytest-runner.
Enjoy!