https://github.com/pybites-open-source/pysource
A command line tool to read Python source code.
https://github.com/pybites-open-source/pysource
hacktoberfest
Last synced: 7 months ago
JSON representation
A command line tool to read Python source code.
- Host: GitHub
- URL: https://github.com/pybites-open-source/pysource
- Owner: PyBites-Open-Source
- License: mit
- Created: 2020-12-15T06:52:15.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-05T07:23:01.000Z (over 4 years ago)
- Last Synced: 2025-07-01T10:08:41.587Z (8 months ago)
- Topics: hacktoberfest
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 22
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://twitter.com/bbelderbos/status/1456234396810362885).
## Installation
You can install `pybites-pysource` from [PyPI](https://pypi.org/project/pybites-pysource/):
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](https://pybit.es/get-python-source.html) for a demo.
### Vim integration
If you want to dump `pysource`'s output to a vertical split window I recommend installing [`ConqueTerm`](https://github.com/gingerhot/conque-term-vim) and then add this to your `.vimrc`:
```
nmap s :ConqueTermVSplit pysource -m
```
Now if you hit `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](https://docs.pytest.org/en/documentation-restructure/background/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner).
---
Enjoy!