Skip to content

PyBites-Open-Source/pysource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyBites Pysource

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.

Installation

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

Usage

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.

Vim integration

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).

Tests

To run the tests:

$ python setup.py test

See: Integrating with setuptools / python setup.py test / pytest-runner.


Enjoy!

About

A command line tool to read Python source code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages