Skip to main content

Locate python object definition in your file-system

Project description

pyloc prints the location of the definition of any python object in your file-system.

Introduction

pyloc is very similar to what python3 -m inspect -d <object> offers. However, it is only focused to retrieve the file name (and eventually the line number) defining a given Python object. The object can be a package, module, class, method or function.

pyloc makes some further effort to figure out the line and column number and its outputs is formatted so that it can easily be passed to emacsclient or vi.

pyloc works with Python 2.7, 3.2, 3.3 and 3.4.

Examples

You can see the location of Popen.wait method in the sub-process package:

$ python -m pyloc -f human subprocess:Popen.wait
Filename: /Users/polrop/.pyenv/versions/2.7.9/lib/python2.7/subprocess.py
Line: 1379

$ python -m pyloc -f human email.utils:formataddr
Filename: /Users/polrop/.pyenv/versions/2.7.9/lib/python2.7/email/utils.py
Line: 85

(Output may be different on your system since you have different installation path and version)

Note that the object naming syntax is as follow: module[:qualname]

To open it in Emacs you can do:

$ emacsclient `python -m pyloc -f emacs subprocess:Popen.wait`

or in vim:

$ vim `python -m pyloc -f vi subprocess:Popen.wait`

If you are lazy typing -f <format> all the time and you often use the same format, you can set the default output format this way (you can add this line in your .zshenv or .bashrc):

$ export PYLOC_DEFAULT_FORMAT=emacs

pyloc will always locate object based on the python interpreter your are using:

$ python3 -m pyloc -f human subprocess:Popen.wait
Filename: /Users/polrop/.pyenv/versions/3.4.3/lib/python3.4/subprocess.py
Line: 1526

$ /usr/local/bin/python -m pyloc -f human email.utils:formataddr
Filename: /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py
Line: 85

$ /usr/bin/python -m pyloc -f human email.utils:formataddr
Filename: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py
Line: 85

Installation

pip

You can install _pyloc_ using pip like this:

$ pip install pyloc

or

$ pip3 install pyloc

From source

Clone this repository and run:

$ python setup.py develop

Known bugs

  • Classes or built-in types like int or str do not contain location information. In this case pyloc tries to look for the name in the AST. This procedure may not be accurate since Python is a dynamic language.

Hacking

See HACKING for details.

License

pyloc is released under the term of the Simplified BSD License. Copyright (c) 2015, Nicolas Desprès All rights reserved.

As noted in the source code, some part has been inspired by code from the inspect module written by Ka-Ping Yee <ping@lfw.org> and Yury Selivanov <yselivanov@sprymix.com> form the Python 3.4.3 distribution (see the LICENSE file in the python distribution)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyloc-0.1.8.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyloc-0.1.8-py2.py3-none-any.whl (12.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyloc-0.1.8.tar.gz.

File metadata

  • Download URL: pyloc-0.1.8.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyloc-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c28bffc5b01d9baeed85c3475781897d59eddd62116d701250c428eefd3090c8
MD5 ebd34774499462c0f74f3804d4aae78d
BLAKE2b-256 2eec051104a90a7a05122c5f129c3f5acb0792248ce383c6f8a143cf555751b5

See more details on using hashes here.

File details

Details for the file pyloc-0.1.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pyloc-0.1.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 db75c088782dc96a0ee5eeca5ee4feedce51b49893c4c559335bb2d11e1c891d
MD5 71616ad64c6bf4d24fc73a614f87f3b2
BLAKE2b-256 0cd70ddfcc98a72dd805eecc35942afdcedb27e9822e3371b8e5304147b521c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page