3737import socket
3838import weakref
3939import functools
40+ from distutils .spawn import find_executable
4041
4142try :
4243 import queue
@@ -322,7 +323,7 @@ def cleanup(self):
322323
323324
324325if sys .platform .startswith ("win" ):
325- from . win32_named_pipe import Win32Pipe
326+ from win32_named_pipe import Win32Pipe
326327
327328 class _PipeConnection (Win32Pipe ):
328329 """This is a wrapper around our Win32Pipe class to expose the expected
@@ -339,6 +340,30 @@ def get_stream(self):
339340 def cleanup (self ):
340341 return
341342 del Win32Pipe
343+ 344+ CODEINTEL_COMMAND = 'codeintel.exe'
345+ CODEINTEL_PATHS = (
346+ '/' ,
347+ '/Program Files' ,
348+ '/Program Files/Python' ,
349+ '/Program Files (x86)' ,
350+ '/Program Files (x86)/Python' ,
351+ '~/AppData/Local/Programs' ,
352+ '~/AppData/Local/Programs/Python' ,
353+ '~/AppData/Local/Programs (x86)' ,
354+ '~/AppData/Local/Programs (x86)/Python' ,
355+ )
356+ CODEINTEL_SUBPATHS = (
357+ 'Python/Scripts'
358+ 'Python26/Scripts' ,
359+ 'Python27/Scripts' ,
360+ 'Python33/Scripts' ,
361+ 'Python34/Scripts' ,
362+ 'Python35/Scripts' ,
363+ 'Python36/Scripts' ,
364+ 'Python37/Scripts' ,
365+ )
366+ 342367else :
343368 # posix pipe class
344369 class _PipeConnection (_Connection ):
@@ -384,6 +409,13 @@ def close(self):
384409 self ._read .close ()
385410 self ._write .close ()
386411
412+ CODEINTEL_COMMAND = 'codeintel'
413+ CODEINTEL_PATHS = (
414+ '/usr' ,
415+ '/usr/local' ,
416+ )
417+ CODEINTEL_SUBPATHS = ('bin' ,)
418+ 387419
388420class CodeIntelManager (threading .Thread ):
389421 STATE_UNINITIALIZED = ("uninitialized" ,) # not initialized
@@ -395,7 +427,7 @@ class CodeIntelManager(threading.Thread):
395427 STATE_DESTROYED = ("destroyed" ,) # connection shut down, child process dead
396428 STATE_ABORTED = ("aborted" ,)
397429
398- _codeintel_command = '/usr/local/bin/codeintel'
430+ _codeintel_command = None
399431 _oop_mode = 'pipe'
400432 _log_levels = ['WARNING' ]
401433 _state = STATE_UNINITIALIZED
@@ -531,17 +563,36 @@ def kill(self):
531563 if self ._shutdown_callback :
532564 self ._shutdown_callback (self )
533565
566+ def find_command (self ):
567+ codeintel_command = self ._codeintel_command
568+ if codeintel_command :
569+ if os .path .exists (codeintel_command ):
570+ return codeintel_command
571+ codeintel_command = find_executable (codeintel_command )
572+ if codeintel_command :
573+ return codeintel_command
574+ 575+ if os .path .exists (CODEINTEL_COMMAND ):
576+ return CODEINTEL_COMMAND
577+ codeintel_command = find_executable (CODEINTEL_COMMAND )
578+ if codeintel_command :
579+ return codeintel_command
580+ 581+ for path in CODEINTEL_PATHS :
582+ for subpath in CODEINTEL_SUBPATHS :
583+ codeintel_command = os .path .expanduser (os .path .join (path , subpath , CODEINTEL_COMMAND ))
584+ if os .path .exists (codeintel_command ):
585+ return codeintel_command
586+ 534587 def init_child (self ):
535- from . import process
588+ import process
536589 assert threading .current_thread ().name != "MainThread" , \
537590 "CodeIntelManager.init_child should run on background thread!"
538591 self .log .debug ("initializing child process" )
539592 conn = None
540593 try :
541- _codeintel_command = self ._codeintel_command
542- if not os .path .exists (_codeintel_command ):
543- _codeintel_command = os .path .basename (_codeintel_command )
544- cmd = [_codeintel_command ]
594+ codeintel_command = self .find_command ()
595+ cmd = [codeintel_command ]
545596
546597 database_dir = os .path .expanduser ('~/.codeintel' )
547598 cmd += ['--log-file' , os .path .join (database_dir , 'codeintel.log' )]
0 commit comments