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

Python Import Magic

by alecthomas ST2

This Sublime Text 2 plugin attempts to automatically manage Python imports.

Details

  • 2016.03.16.23.30.19
  • github.​com
  • github.​com
  • 2 years ago
  • 1 hour ago
  • 4 years ago

Installs

  • Total 2K
  • Win 736
  • OS X 554
  • Linux 451
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 Jun 11 Jun 10 Jun 9 Jun 8 Jun 7 Jun 6
Windows 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 0 0 0 0 0 0 0 0 0 1
OS X 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 0 0 0 0 0
Linux 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 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Sublime Text 3 - Python Import Magic image

This plugin attempts to automatically manage Python imports.

WARNING: This is a relatively complex plugin and thus may contain bugs. It may remove imports that you need. It may add imports that you don't. Use at your own risk.

It can:

  • Detect and add imports for unknown symbols.
  • Remove unused imports.
  • Order imports according to PEP8.

It currently does NOT (but support is planned):

  • Detect changes to files and update its index automatically. The current workaround is to use the command palette Python Import Magic: Reset Index.

Example

Example of Import Magic at work

Usage

There are three ways of invoking the auto-importer:

  • The hotkey: ⌘⇧I on OSX and ^⇧I on Windows and Linux.
  • Via the command palette: Python Import Magic: Update Imports.
  • Setting update_imports_on_save to true in the user settings for the package. I would not encourage use of this setting at this stage, but if you're feeling particularly brave…

Configuration

eg.

{
    "update_imports_on_save": true,
    "python_path": {
        "/Library/Python/2.7/site-packages": "S",
        "/Users/alec/Projects/SublimePythonImportMagic/.venv/lib/python2.7/site-packages": "L"
    }
}

update_imports_on_save = false

If true, update imports on each save. WARNING: This might not be a good idea.

index_filename = ".importmagic.idx"

Name of file to store index in.

python_path = {<path>: <classification>}

NOTE: Not implemented yet

Keys are the paths to search for Python modules. Values are how the path should be classified.

Paths will also be looked up in the default Sublime configuration under the key python_import_magic_python_path.

<classification> is from the following table:

Key Classification
3 Third party
S System
L Local