forked from DamnWidget/anaconda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anaconda.py
102 lines (74 loc) · 2.71 KB
/
anaconda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf8 -*-
# Copyright (C) 2013 - Oscar Campos <[email protected]>
# This program is Free Software see LICENSE file for details
"""
Anaconda is a python autocompletion and linting plugin for Sublime Text 3
"""
import os
import sys
import logging
from string import Template
import sublime
import sublime_plugin
from .anaconda_lib import ioloop
from .anaconda_lib.helpers import get_settings
from .commands import * # noqa
from .listeners import * # noqa
if sys.version_info < (3, 3):
raise RuntimeError('Anaconda works with Sublime Text 3 only')
DISABLED_PLUGINS = []
LOOP_RUNNING = False
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.DEBUG)
def plugin_loaded() -> None:
"""Called directly from sublime on plugin load
"""
package_folder = os.path.dirname(__file__)
if not os.path.exists(os.path.join(package_folder, 'Main.sublime-menu')):
template_file = os.path.join(
package_folder, 'templates', 'Main.sublime-menu.tpl'
)
with open(template_file, 'r', encoding='utf8') as tplfile:
template = Template(tplfile.read())
menu_file = os.path.join(package_folder, 'Main.sublime-menu')
with open(menu_file, 'w', encoding='utf8') as menu:
menu.write(template.safe_substitute({
'package_folder': os.path.basename(package_folder)
}))
# unload any conflictive package while anaconda is running
sublime.set_timeout_async(monitor_plugins, 0)
if not LOOP_RUNNING:
ioloop.loop()
def plugin_unloaded() -> None:
"""Called directly from sublime on plugin unload
"""
# reenable any conflictive package
enable_plugins()
if LOOP_RUNNING:
ioloop.terminate()
def monitor_plugins():
"""Monitor for any plugin that conflicts with anaconda
"""
view = sublime.active_window().active_view()
if not get_settings(view, 'auto_unload_conflictive_plugins', True):
return
plist = [
'Jedi - Python autocompletion', # breaks auto completion
'SublimePythonIDE', # interfere with autocompletion
'SublimeCodeIntel' # breaks everything, SCI is a mess
]
for plugin in plist:
if plugin in sys.modules:
[
sublime_plugin.unload_module(m) for k, m in sys.modules.items()
if plugin in k
]
if plugin not in DISABLED_PLUGINS:
DISABLED_PLUGINS.append(plugin)
sublime.set_timeout_async(monitor_plugins, 5 * 60 * 1000)
def enable_plugins():
"""Reenable disabled plugins by anaconda
"""
for plugin in DISABLED_PLUGINS:
sublime_plugin.reload_plugin(plugin)