Giter Site home page Giter Site logo

sublimetext2-python-open-module-new's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.