~nhoad/pyopen

a10be0acb19099d418bd97488190e11e9d942dbc — Nathan Hoad 9 months ago 14f24a3 master
Update this to be a bit more up to date.
1 files changed, 31 insertions(+), 37 deletions(-)

M README.md
M README.md => README.md +31 -37
@@ 3,45 3,39 @@ pyopen

`pyopen` is a tool to open Python files by import path.

If you've ever had to open the source code for a module installed on your
system, you probably did something like this:

    nathan@nathan ~ $ python2
    Python 2.7.7 (default, Jun  3 2014, 01:46:20)
    [GCC 4.9.0 20140521 (prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> requests
    <module 'requests' from '/usr/lib/python2.7/site-packages/requests/__init__.pyc'>
    >>>
    nathan@nathan ~ $ vim /usr/lib/python2.7/site-packages/requests/__init__.py

Or you guessed the path, and tabbed-completed your way there. `pyopen` instead
lets you do this:

    nathan@nathan ~ $ pyvim requests
If you've ever had to read the source code for a Python object, you've probably done
something like this:

```
Python 3.7.4 (default, Jul 16 2019, 07:12:58)
[GCC 9.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get.__module__
'requests.api'
>>> requests.api
<module 'requests.api' from '/usr/lib/python3.7/site-packages/requests/api.py'>
```

Or you guessed the path, and tabbed-completed your way there, and then found out you
need to hop around a bit to actually find it. `pyopen` instead lets you do this:

```
nathan@nathan ~ $ pyvim requests.get
```

Which will change to the directory containing the found file, and open it
relatively with $EDITOR.
relatively with $EDITOR to the definition of the `get` function.

Opening it relatively is helpful for navigating the rest of the module, so it
Opening it relative-wise is helpful for navigating the rest of the module, so it
is done by default.

More usefully, this lets you jump directly to the definitions of classes and
functions. For example jumping to the definition of `requests.get` is much
easier than normal:

    nathan@nathan ~ $ pyvim requests.get --verbose --absolute-path
    vim /usr/lib/python2.7/site-packages/requests/api.py +46

Or, as a more extreme example (that I use quite a lot), say you want to find
the implementation of `listenTCP` for the default reactor in Twisted:

    nathan@nathan ~ $ pyvim twisted.internet.reactor.listenTCP --verbose --absolute-open
    vim /home/nathan/.local/lib/python2.7/site-packages/Twisted-13.0.0-py2.7-linux-x86_64.egg/twisted/internet/posixbase.py +485
You can even use this to get at method definitions on classes:

This is a particularly extreme example because it's actually the method of a
class that is constructed at import time, yet `pyopen` found it just fine.
```
$ pyopen.py pathlib.Path.iterdir --verbose --absolute-open
kak /usr/lib/python3.7/pathlib.py +1084
```

Installation
============


@@ 50,14 44,14 @@ Clone the repository to somewhere sensible, and modify your $PATH to include
the `bin` directory of this project. For example:

    $ cd projects
    $ git clone https://github.com/nathan-hoad/pyopen
    $ git clone https://git.sr.ht/~nhoad/pyopen
    $ echo 'export PATH=~/projects/pyopen/bin:$PATH' >> ~/.bashrc

Tips and Tricks
===============

pyopen.py --help has lots of general options that should be useful in
integrating with your current workflow.
pyopen.py --help has some options that should be useful in integrating with your current
workflow.

    Usage: pyopen.py [options]



@@ 71,7 65,7 @@ integrating with your current workflow.
                           changing to the parent directory.
      -v, --verbose        Display commands before they're run.

## Jumping to the directory where source lives instead of opening the file
## cd to the package directory
Easy! Add a function to your `.bashrc` (or equivalent).

    pycd() {