Skip to content

Commit 866766b

Browse files
authored
Fix library cleanup (#1739)
Fixes #1737 This commit... 1. adds python 3.13 to the list of legacy environments requiring cleanup, if no longer supported. 2. uses ST versions to detect supported python version(s), to avoid wrong assumptions if an upgrade doesn't cleanup obsolete files.
1 parent e0f84ae commit 866766b

2 files changed

Lines changed: 23 additions & 32 deletions

File tree

package_control/package_cleanup.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,12 @@ def cleanup_python_environments(self):
159159
cache2 = os.path.join(sys_path.cache_path(), "__pycache__", "data", "Lib", "python")
160160

161161
supported_versions = sys_path.python_versions()
162-
if "3.3" not in supported_versions:
163-
# Python folder is re-created at each startup, hence just clear it for now.
164-
clear_directory(libdir + "33")
165-
# Python 3.3 itself doesn't support nor create compiled cache modules,
166-
# ST's fallback mechanism might however have created some py38 or py313 cache files
167-
# in those directories, which need to be cleared out.
168-
delete_directory(cache1 + "33")
169-
delete_directory(cache2 + "33")
170-
171-
if "3.8" not in supported_versions:
172-
# if 3.8 is not supported it is not present, delete all folders
173-
delete_directory(libdir + "38")
174-
delete_directory(cache1 + "38")
175-
delete_directory(cache2 + "38")
162+
for pyver in ("3.3", "3.8", "3.13", "3.14"):
163+
if pyver not in supported_versions:
164+
pyver = pyver.replace(".", "")
165+
clear_directory(libdir + pyver)
166+
delete_directory(cache1 + pyver)
167+
delete_directory(cache2 + pyver)
176168

177169
def cleanup_pending_packages(self):
178170
"""

package_control/sys_path.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
if __installed_packages_path is None:
7676
raise FileNotFoundError('Installed Packages')
7777

78+
assert __data_path
79+
7880
if PREFIX:
7981
__data_path = PREFIX + __data_path
8082
__default_packages_path = PREFIX + __default_packages_path
@@ -151,28 +153,25 @@ def lib_paths():
151153
try:
152154
return lib_paths.cache
153155
except AttributeError:
156+
assert __data_path
154157
st_version = int(sublime.version())
155-
if st_version > 4000:
156-
root = os.path.dirname(__executable_path)
157-
fext = ".exe" if sublime.platform() == "windows" else ""
158+
if st_version >= 4203:
159+
lib_paths.cache = {"3.14": os.path.join(__data_path, "Lib", "python314")}
160+
elif st_version >= 4201:
161+
lib_paths.cache = {"3.13": os.path.join(__data_path, "Lib", "python313")}
162+
elif st_version >= 4000:
163+
lib_paths.cache = {"3.8": os.path.join(__data_path, "Lib", "python38")}
164+
else:
165+
lib_paths.cache = {"3.3": os.path.join(__data_path, "Lib", "python3.3")}
158166

167+
if st_version >= 4194:
159168
settings = sublime.load_settings("Preferences.sublime-settings")
160-
data = (
161-
("3.3", "python33", not settings.get('disable_plugin_host_3.3', False)),
162-
("3.8", "python38", True),
163-
("3.13", "python313", True),
164-
("3.14", "python314", True),
165-
)
166-
lib_paths.cache = {
167-
py_ver: os.path.join(__data_path, "Lib", py_dir)
168-
for py_ver, py_dir, enable in data
169-
if enable and os.path.isfile(os.path.join(root, "plugin_host-" + py_ver + fext))
170-
}
169+
if not settings.get("disable_plugin_host_3.3", False):
170+
root = os.path.dirname(__executable_path)
171+
fext = ".exe" if sublime.platform() == "windows" else ""
172+
if os.path.isfile(os.path.join(root, "plugin_host-3.3" + fext)):
173+
lib_paths.cache["3.3"] = os.path.join(__data_path, "Lib", "python33")
171174

172-
else:
173-
lib_paths.cache = {
174-
"3.3": os.path.join(__data_path, "Lib", "python3.3")
175-
}
176175
return lib_paths.cache
177176

178177

0 commit comments

Comments
 (0)