ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Python Open Module (New)

by Mimino666 ALL

Opens the Python module file based on the Python import path. Plugin to Sublime Text 2.

Details

  • 2021.03.31.09.08.12
  • github.​com
  • github.​com
  • 3 years ago
  • 55 minutes ago
  • 11 years ago

Installs

  • Total 9K
  • Win 6K
  • Mac 1K
  • Linux 2K
Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12
Windows 0 0 0 0 1 2 0 0 1 0 0 0 0 0 2 0 0 1 1 1 2 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 0
Mac 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 0 0 1

Readme

Source
raw.​githubusercontent.​com

Python Open Module (New)

Plugin to Sublime Text 2. Opens the Python module file based on the Python import path.

More advanced and bugfree version of PythonOpenModule.

Typical use case

Imagine you are reading some Python script and trying to understand why it works the way it works.

At the top of the script you see from some.very.mysterious.module import muhahaha. Are you curious what muhahaha is doing? Simple enough!

Highlight some.very.mysterious.module, press Alt+Shift+o, Enter and enjoy.

Features

  • works with virtual environments
  • easy modification of sys.path contents through settings
  • automatically discoveres and includes Python packages in your currently opened project
  • resolves relative paths and .pth files
  • user-friendly input panel with syntax highlighting (i.e. if you type bullshit, it turns red)
  • you can choose whether to view the modules in the current or a new window

Install

The easiest way to install this is with Package Control.

Usage

Press Alt+Shift+o to open the input panel. Type the Python import path of the module you want to view.

Note: this plugin STRICTLY simulates the Python's import mechanism. What it means is that you can view only such files that Python would be able to import from the current working file. The only exception are your project packages, which are automatically included in sys.path for you.

Suppose the following directory tree of your Python project:

MyProject/
  x.py
  A/
    __init__.py
    y.py            <- current working file
    B/
      __init__.py
      z.py

Examples:

Type into input panel   ->  What file is opened (sys.path prefix to file omitted):
----------------------------------------------------------------------------------
os                      ->  os.py
django.db               ->  django.db.__init__.py

Prefix import paths with `+` to open them in a new window:
----------------------------------------------------------
+os                     ->  Opens os.py in a new window.
+django                 ->  Opens whole django project in a new window (because `django` is a package).

Inside your project (MyProject/ is automatically included to sys.path):
-----------------------------------------------------------------------
x                       ->  x.py
A.y                     ->  A/y.py
A.B.z                   ->  A/B/z.py

Relative paths are resolved based on the current working file:
--------------------------------------------------------------
.B.z                    ->  A/B/z.py
.B                      ->  A/B/__init__.py
.                       ->  A/__init__.py

If you try to input a path that Python would not be able to import from the current working file, nothing will be opened and you will receive an information in the status bar (at the bottom of ST2 window).

Virtual environment

If you are using virtual environment, you need to set the setting python_executable (Preferences > Package Settings > PythonOpenModule(New) > Settings - User) to the path pointing to the Python executable inside your venv directory.

Modifying sys.path

Use the setting path to modify the contents of sys.path, used for module search. See the default settings for reference.

FAQ

Plugin doesn't work for sys or datetime modules. Is it a bug?

No it is not a bug. Some modules simply doesn't have the raw .py files available, thus cannot be opened. For example sys module is on your system probably stored as sysmodule.c file. For other modules, maybe only .pyc files are available. There is nothing that can be done about this. Sorry.