Skip to content

Commit a5be565

Browse files
committed
Add support for python 3.13 plugin host
Assuming folder structure keeps unchanged, this commit adds support for another plugin_host. Supported python environment is dynamically evaluated using available library paths.
1 parent 4a643c2 commit a5be565

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

package_control/distinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def generate_wheel(python_version, plat_specific):
157157
specific to a platform and optionally architecture
158158
"""
159159

160-
if python_version is not None and python_version not in {"3.3", "3.8"}:
160+
if python_version is not None and python_version not in sys_path.python_versions():
161161
raise ValueError("Invalid python_version %s" % repr(python_version))
162162

163163
version_tag = "py3"
@@ -171,7 +171,7 @@ def generate_wheel(python_version, plat_specific):
171171
arch = os.uname()[4]
172172
if python_version == "3.3":
173173
arch_tag = "macosx_10_7_%s" % arch
174-
elif python_version == "3.8":
174+
else:
175175
arch_tag = "macosx_10_9_%s" % arch
176176
elif sys.platform == "linux":
177177
arch_tag = "linux_%s" % os.uname()[4]

package_control/library.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from . import distinfo
99
from .clear_directory import delete_directory
1010

11-
BUILTIN_LIBRARIES = {"3.3": {}, "3.8": {"enum", "pathlib", "typing"}}
11+
BUILTIN_LIBRARIES = {
12+
"3.3": {},
13+
"3.8": {"enum", "pathlib", "typing"},
14+
"3.13": {"enum", "exceptiongroup", "pathlib", "typing"},
15+
}
1216
"""3rd-party libraries, which are part of stdlib as of certain python version"""
1317

1418
DEPENDENCY_NAME_MAP = {

package_control/package_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ def get_python_version(self, package_name):
262262
A unicode string of "3.3" or "3.8"
263263
"""
264264

265-
if self.settings["disable_plugin_host_3.3"]:
266-
return "3.8"
265+
if self.settings['version'] > 4200 or self.settings["disable_plugin_host_3.3"]:
266+
return sys_path.python_version()
267267

268268
python_version = read_package_file(package_name, ".python-version")
269269
if python_version:

package_control/sys_path.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ def add_dependency(name, first=False):
9191
pass
9292

9393

94+
def python_version():
95+
"""
96+
Return version of current python environment.
97+
98+
returns
99+
A string like "3.3", "3.8" or "3.13"
100+
"""
101+
try:
102+
return python_version.cache
103+
except AttributeError:
104+
python_version.cache = "{0}.{1}".format(*sys.version_info[:2])
105+
return python_version.cache
106+
107+
108+
def python_versions():
109+
"""
110+
Return a list of supported python environments.
111+
returns
112+
A tuple of e.g. ("3.3", "3.8")
113+
"""
114+
return tuple(lib_paths())
115+
116+
94117
def cache_path():
95118
"""
96119
Returns the ST cache directory
@@ -130,12 +153,21 @@ def lib_paths():
130153
try:
131154
return lib_paths.cache
132155
except AttributeError:
133-
lib_paths.cache = {
134-
"3.3": os.path.join(__data_path, "Lib", "python33"),
135-
"3.8": os.path.join(__data_path, "Lib", "python38")
136-
} if int(sublime.version()) >= 4000 else {
137-
"3.3": os.path.join(__data_path, "Lib", "python3.3")
138-
}
156+
if int(sublime.version()) >= 4000:
157+
items = {}
158+
root = os.path.join(__data_path, "Lib")
159+
for fentry in os.scandir(root):
160+
if fentry.name.startswith("python3") and fentry.is_dir():
161+
minor = fentry.name[len("python3"):]
162+
if minor and all(c in "0123456789" for c in minor):
163+
version = "3." + minor
164+
items[version] = os.path.join(root, fentry.name)
165+
166+
lib_paths.cache = items
167+
else:
168+
lib_paths.cache = {
169+
"3.3": os.path.join(__data_path, "Lib", "python3.3")
170+
}
139171
return lib_paths.cache
140172

141173

@@ -193,12 +225,13 @@ def python_libs_cache_path(python_version):
193225

194226
global __python_libs_cache_path
195227

196-
if not __python_libs_cache_path:
197-
__python_libs_cache_path = {
198-
"3.3": None, # bytecode cache not supported
199-
"3.8": os.path.join(
200-
cache_path(), '__pycache__', 'install', 'Data', 'Lib', "python38")
201-
}
228+
if __python_libs_cache_path is None:
229+
__python_libs_cache_path = {}
230+
for pyver, libpath in lib_paths().items():
231+
if pyver != "3.3":
232+
__python_libs_cache_path[pyver] = os.path.join(
233+
cache_path(), '__pycache__', 'install', 'Data', 'Lib', os.path.basename(libpath)
234+
)
202235

203236
return str(__python_libs_cache_path[python_version])
204237

@@ -213,7 +246,7 @@ def python_packages_cache_path():
213246

214247
global __python_packages_cache_path
215248

216-
if not __python_packages_cache_path:
249+
if __python_packages_cache_path is None:
217250
__python_packages_cache_path = os.path.join(
218251
cache_path(), '__pycache__', 'install', 'Data', 'Packages')
219252

@@ -230,7 +263,7 @@ def pc_cache_dir():
230263

231264
global __package_control_cache_path
232265

233-
if not __package_control_cache_path:
266+
if __package_control_cache_path is None:
234267
__package_control_cache_path = os.path.join(cache_path(), 'Package Control')
235268

236269
return str(__package_control_cache_path)

0 commit comments

Comments
 (0)