@@ -61,7 +61,7 @@ def ensure_active_file():
61
61
"""
62
62
ensure_confdir ()
63
63
if not os .path .exists (ACTIVE_FILE ):
64
- with open (ACTIVE_FILE , "w+" ) as f :
64
+ with open (ACTIVE_FILE , "w+" , encoding = "utf-8" ) as f :
65
65
f .write ("" )
66
66
67
67
@@ -83,12 +83,14 @@ def get_python_installs(relaunching=False):
83
83
Write the found Python versions to `py-installs`. Create
84
84
a new database if `relaunching=True`.
85
85
"""
86
- versions = ["3.9" , "3.8" , "3.7" , "3.6" , "3.5" , "3.4" , "3.3" ]
86
+ versions = [
87
+ "3.11" , "3.10" , "3.9" , "3.8" , "3.7" , "3.6" , "3.5" , "3.4" , "3.3"
88
+ ]
87
89
py_info_list = []
88
90
ensure_confdir ()
89
91
90
92
if not os .path .exists (DB_FILE ) or relaunching :
91
- with open (DB_FILE , "w" , newline = "" ) as cf :
93
+ with open (DB_FILE , "w" , newline = "" , encoding = "utf-8" ) as cf :
92
94
fields = ["PYTHON_VERSION" , "PYTHON_PATH" ]
93
95
writer = csv .DictWriter (
94
96
cf ,
@@ -126,7 +128,7 @@ def add_python(py_path):
126
128
"""
127
129
ensure_dbfile ()
128
130
129
- with open (DB_FILE , "a" , newline = "" ) as cf :
131
+ with open (DB_FILE , "a" , newline = "" , encoding = "utf-8" ) as cf :
130
132
fields = ["PYTHON_VERSION" , "PYTHON_PATH" ]
131
133
writer = csv .DictWriter (
132
134
cf ,
@@ -150,9 +152,9 @@ def remove_env():
150
152
Remove our interpreter if we're running in a virtual
151
153
environment.
152
154
"""
153
- with open (DB_FILE , "r" ) as f :
155
+ with open (DB_FILE , "r" , encoding = "utf-8" ) as f :
154
156
lines = f .readlines ()
155
- with open (DB_FILE , "w" ) as f :
157
+ with open (DB_FILE , "w" , encoding = "utf-8" ) as f :
156
158
for line in lines :
157
159
if sys .executable not in line .strip ("\n " ):
158
160
f .write (line )
@@ -212,11 +214,16 @@ def get_pyvenv_cfg(cfg_file, cfg):
212
214
Values for `cfg` can be strings: `version`, `py_path`,
213
215
`site_packages` or `installed`.
214
216
"""
215
- with open (cfg_file , "r" ) as f :
217
+ with open (cfg_file , "r" , encoding = "utf-8" ) as f :
216
218
lines = f .readlines ()
217
219
220
+ if lines [2 ][13 ] == "." :
221
+ version = lines [2 ][10 :13 ].strip () # python 3.x
222
+ else :
223
+ version = lines [2 ][10 :14 ].strip () # python 3.10+
224
+
218
225
version_str = to_version (lines [2 ][10 :].strip ())
219
- binary_path = to_path (lines [0 ][7 :].strip (), lines [ 2 ][ 10 : 13 ]. strip () )
226
+ binary_path = to_path (lines [0 ][7 :].strip (), version )
220
227
site_packages = lines [1 ][31 :].strip ()
221
228
222
229
if cfg == "version" :
@@ -234,7 +241,7 @@ def get_pyvenv_cfg(cfg_file, cfg):
234
241
235
242
if cfg == "installed" :
236
243
ensure_dbfile ()
237
- with open (DB_FILE , newline = "" ) as cf :
244
+ with open (DB_FILE , newline = "" , encoding = "utf-8" ) as cf :
238
245
reader = csv .DictReader (cf , delimiter = "," )
239
246
for info in reader :
240
247
if binary_path == info ["PYTHON_PATH" ]:
@@ -248,7 +255,7 @@ def get_active_dir_str():
248
255
"""Get the default venv directory string from `active` file.
249
256
"""
250
257
ensure_active_file ()
251
- with open (ACTIVE_FILE , "r" ) as f :
258
+ with open (ACTIVE_FILE , "r" , encoding = "utf-8" ) as f :
252
259
active_dir = f .read ()
253
260
return active_dir
254
261
return ""
0 commit comments