@@ -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+
94117def cache_path ():
95118 """
96119 Returns the ST cache directory
@@ -130,12 +153,19 @@ 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 (os .path .dirname (__executable_path )):
160+ if fentry .name .startswith ("plugin_host-3." ) and fentry .is_file ():
161+ version = fentry .name .rsplit ("." , 1 )[0 ][len ("plugin_host-" ):]
162+ items [version ] = os .path .join (root , "python" + version .replace ("." , "" ))
163+
164+ lib_paths .cache = items
165+ else :
166+ lib_paths .cache = {
167+ "3.3" : os .path .join (__data_path , "Lib" , "python3.3" )
168+ }
139169 return lib_paths .cache
140170
141171
@@ -193,12 +223,13 @@ def python_libs_cache_path(python_version):
193223
194224 global __python_libs_cache_path
195225
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- }
226+ if __python_libs_cache_path is None :
227+ __python_libs_cache_path = {}
228+ for pyver , libpath in lib_paths ().items ():
229+ if pyver != "3.3" :
230+ __python_libs_cache_path [pyver ] = os .path .join (
231+ cache_path (), '__pycache__' , 'install' , 'Data' , 'Lib' , os .path .basename (libpath )
232+ )
202233
203234 return str (__python_libs_cache_path [python_version ])
204235
@@ -213,7 +244,7 @@ def python_packages_cache_path():
213244
214245 global __python_packages_cache_path
215246
216- if not __python_packages_cache_path :
247+ if __python_packages_cache_path is None :
217248 __python_packages_cache_path = os .path .join (
218249 cache_path (), '__pycache__' , 'install' , 'Data' , 'Packages' )
219250
@@ -230,7 +261,7 @@ def pc_cache_dir():
230261
231262 global __package_control_cache_path
232263
233- if not __package_control_cache_path :
264+ if __package_control_cache_path is None :
234265 __package_control_cache_path = os .path .join (cache_path (), 'Package Control' )
235266
236267 return str (__package_control_cache_path )
0 commit comments