-
-
Notifications
You must be signed in to change notification settings - Fork 802
Expand file tree
/
Copy pathplugin.py
More file actions
163 lines (133 loc) · 4.87 KB
/
plugin.py
File metadata and controls
163 lines (133 loc) · 4.87 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
import sublime
import sys
# Ensure compatibility with python 3.3 to 3.14+
if sys.version_info > (3, 8):
__name__ = __spec__.name
__package__ = __spec__.parent
# Clear module cache to force reloading all modules of this package.
prefix1 = __package__ + "." # sub modules of Package Control package
prefix2 = "package_control." # sub modules of package_control namespace package
for module_name in [
module_name
for module_name in sys.modules
if (module_name.startswith(prefix1) or module_name.startswith(prefix2)) and module_name != __name__
]:
del sys.modules[module_name]
del prefix1
del prefix2
from .package_control.package_io import (
get_installed_package_path,
get_package_dir,
regular_file_exists
)
from .package_control import text
has_packed = os.path.exists(get_installed_package_path('Package Control'))
has_unpacked = regular_file_exists('Package Control', 'plugin.py')
# Ensure least requires ST version
if int(sublime.version()) < 3143:
message = text.format(
'''
Package Control
This package requires at least Sublime Text 3143.
Please consider updating ST or remove Package Control.
'''
)
sublime.error_message(message)
def plugin_loaded():
"""
plugin loaded hook
Disable Package Control to avoid error message popping up again.
"""
from .package_control.bootstrap import disable_package_control
disable_package_control()
# Ensure the user has installed Package Control properly
elif __package__ != 'Package Control':
message = text.format(
'''
Package Control
This package appears to be installed incorrectly.
It should be installed as "Package Control", but seems to be installed
as "%s".
To fix the issue, please:
1. Open the "Preferences" menu
2. Select "Browse Packages\u2026"
''',
__package__,
strip=False
)
# If installed unpacked
if os.path.exists(get_package_dir(__package__)):
message += text.format(
'''
3. Rename the folder "%s" to "Package Control"
4. Restart Sublime Text
''',
__package__
)
# If installed as a .sublime-package file
else:
message += text.format(
'''
3. Browse up a folder
4. Browse into the "Installed Packages/" folder
5. Rename "%s.sublime-package" to "Package Control.sublime-package"
6. Restart Sublime Text
''',
__package__
)
sublime.error_message(message)
elif has_packed and has_unpacked:
message = text.format(
'''
Package Control
It appears you have Package Control installed as both a
.sublime-package file and a directory inside of the Packages folder.
To fix this issue, please:
1. Open the "Preferences" menu
2. Select "Browse Packages\u2026"
3. Delete the folder "Package Control"
4. Restart Sublime Text
'''
)
sublime.error_message(message)
else:
# Make sure the user's locale can handle non-ASCII. A whole bunch of
# work was done to try and make Package Control work even if the locale
# was poorly set, by manually encoding all file paths, but it ended up
# being a fool's errand since the package loading code built into
# Sublime Text is not written to work that way, and although packages
# could be installed, they could not be loaded properly.
try:
os.path.exists(get_package_dir("fran\u2013ais"))
except (UnicodeEncodeError) as exception:
message = text.format(
'''
Package Control
Your system's locale is set to a value that can not handle
non-ASCII characters. Package Control can not properly work
unless this is fixed.
On Linux, please reference your distribution's docs for
information on properly setting the LANG and LC_CTYPE
environmental variables. As a temporary work-around, you can
launch Sublime Text from the terminal with:
LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 sublime_text
Error Details:
%s
''',
exception,
strip=False
)
sublime.error_message(message)
# Normal execution will finish setting up the package
else:
from .package_control.commands import * # noqa
def plugin_loaded():
"""
Run bootstrapping once plugin is loaded
Bootstrapping is executed with little delay to work around a ST core bug,
which causes `sublime.load_resource()` to fail when being called directly
by `bootstrap()` hook.
"""
from .package_control.bootstrap import bootstrap
bootstrap()