forked from DamnWidget/anaconda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anaconda.py
56 lines (41 loc) · 1.5 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
# -*- 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
from .anaconda_lib import ioloop
from .anaconda_lib.worker import LOOP_RUNNING
from .commands import *
from .listeners import *
if sys.version_info < (3, 3):
raise RuntimeError('Anaconda works with Sublime Text 3 only')
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.DEBUG)
def plugin_loaded():
"""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)
}))
if not LOOP_RUNNING:
ioloop.loop()
def plugin_unloaded():
"""Called directly from sublime on plugin unload
"""
if LOOP_RUNNING:
ioloop.terminate()