forked from SublimeText/LaTeXTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_reload_submodules.py
136 lines (104 loc) · 3.25 KB
/
01_reload_submodules.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#
# This module will reload any existing submodules, such as latextools_utils,
# that may be cached in memory. Note that it must be run before any module
# that uses any imports from any of those modules, hence the name.
#
import sublime
import sys
import traceback
if sys.version_info >= (3,):
from imp import reload
_ST3 = sublime.version() >= '3000'
def _load_module_exports(module):
if 'exports' in module.__dict__:
for name in module.exports:
try:
# lift the export to this modules top level
globals()[name] = module.__dict__[name]
except KeyError:
print(
"Error: {0} not defined in {1}."
.format(name, module.__name__))
MOD_PREFIX = ''
if _ST3:
MOD_PREFIX = 'LaTeXTools.' + MOD_PREFIX
# these modules must be specified in the order they depend on one another
LOAD_ORDER = [
'external.latex_chars',
# reloaded here so that makePDF imports the current version
'parseTeXlog',
'latextools_utils',
'latextools_utils.six',
# no internal dependencies
'latextools_utils.bibformat',
'latextools_utils.settings',
'latextools_utils.utils',
'latextools_utils.tex_directives',
'latextools_utils.system',
'latextools_utils.internal_types',
# depend on previous only
'latextools_utils.distro_utils',
'latextools_utils.is_tex_file',
'latextools_utils.cache',
'latextools_utils.quickpanel',
'latextools_utils.external_command',
# depend on any previous
'latextools_utils.sublime_utils',
# depend on any previous
'latextools_utils.analysis',
'latextools_utils.ana_utils',
'latextools_utils.output_directory',
'latextools_utils.bibcache',
'latextools_plugin',
# ensure latex_fill_all is loaded before the modules that depend on it
'latex_fill_all'
]
if _ST3:
LOAD_ORDER.insert(1, 'latextools_plugin_internal')
# modules which should be scanned for any exports to be hoisted to this
# module's context
EXPORT_MODULES = []
if sublime.version() > '3118':
LOAD_ORDER += [
'st_preview.preview_utils',
'st_preview.preview_threading'
]
EXPORT_MODULES += [
'st_preview.preview_math',
'st_preview.preview_image'
]
LOAD_ORDER += EXPORT_MODULES
for suffix in LOAD_ORDER:
mod = MOD_PREFIX + suffix
try:
if mod in sys.modules and sys.modules[mod] is not None:
reload(sys.modules[mod])
else:
__import__(mod)
except:
traceback.print_exc()
if suffix in EXPORT_MODULES:
_load_module_exports(sys.modules[mod])
def plugin_loaded():
# reload any plugins cached in memory
mods = [m for m in sys.modules if m.startswith('_latextools_')]
for mod in mods:
try:
del sys.modules[mod]
except:
traceback.print_exc()
for module in EXPORT_MODULES:
mod = MOD_PREFIX + module
try:
sys.modules[mod].plugin_loaded()
except AttributeError:
pass
def plugin_unloaded():
for module in EXPORT_MODULES:
mod = MOD_PREFIX + module
try:
sys.modules[mod].plugin_unloaded()
except AttributeError:
pass
if not _ST3:
plugin_loaded()