@@ -226,14 +226,22 @@ def jedi_names(self, all_scopes=False, definitions=True, references=False):
226
226
def jedi_script (self , position = None ):
227
227
extra_paths = []
228
228
environment_path = None
229
+ env_vars = None
229
230
230
231
if self ._config :
231
232
jedi_settings = self ._config .plugin_settings ('jedi' , document_path = self .path )
232
233
environment_path = jedi_settings .get ('environment' )
233
234
extra_paths = jedi_settings .get ('extra_paths' ) or []
235
+ env_vars = jedi_settings .get ('env_vars' )
234
236
235
- environment = self .get_enviroment (environment_path ) if environment_path else None
236
- sys_path = self .sys_path (environment_path ) + extra_paths
237
+ # Drop PYTHONPATH from env_vars before creating the environment because that makes
238
+ # Jedi throw an error.
239
+ if env_vars is None :
240
+ env_vars = os .environ .copy ()
241
+ env_vars .pop ('PYTHONPATH' , None )
242
+
243
+ environment = self .get_enviroment (environment_path , env_vars = env_vars ) if environment_path else None
244
+ sys_path = self .sys_path (environment_path , env_vars = env_vars ) + extra_paths
237
245
project_path = self ._workspace .root_path
238
246
239
247
kwargs = {
@@ -249,22 +257,25 @@ def jedi_script(self, position=None):
249
257
250
258
return jedi .Script (** kwargs )
251
259
252
- def get_enviroment (self , environment_path = None ):
260
+ def get_enviroment (self , environment_path = None , env_vars = None ):
253
261
# TODO(gatesn): #339 - make better use of jedi environments, they seem pretty powerful
254
262
if environment_path is None :
255
263
environment = jedi .api .environment .get_cached_default_environment ()
256
264
else :
257
265
if environment_path in self ._workspace ._environments :
258
266
environment = self ._workspace ._environments [environment_path ]
259
267
else :
260
- environment = jedi .api .environment .create_environment (path = environment_path , safe = False )
268
+ environment = jedi .api .environment .create_environment (path = environment_path ,
269
+ safe = False ,
270
+ env_vars = env_vars )
261
271
self ._workspace ._environments [environment_path ] = environment
262
272
263
273
return environment
264
274
265
- def sys_path (self , environment_path = None ):
275
+ def sys_path (self , environment_path = None , env_vars = None ):
266
276
# Copy our extra sys path
277
+ # TODO: when safe to break API, use env_vars explicitly to pass to create_environment
267
278
path = list (self ._extra_sys_path )
268
- environment = self .get_enviroment (environment_path = environment_path )
279
+ environment = self .get_enviroment (environment_path = environment_path , env_vars = env_vars )
269
280
path .extend (environment .get_sys_path ())
270
281
return path
0 commit comments