37
37
import socket
38
38
import weakref
39
39
import functools
40
+ from distutils .spawn import find_executable
40
41
41
42
try :
42
43
import queue
@@ -322,7 +323,7 @@ def cleanup(self):
322
323
323
324
324
325
if sys .platform .startswith ("win" ):
325
- from . win32_named_pipe import Win32Pipe
326
+ from win32_named_pipe import Win32Pipe
326
327
327
328
class _PipeConnection (Win32Pipe ):
328
329
"""This is a wrapper around our Win32Pipe class to expose the expected
@@ -339,6 +340,30 @@ def get_stream(self):
339
340
def cleanup (self ):
340
341
return
341
342
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
+
342
367
else :
343
368
# posix pipe class
344
369
class _PipeConnection (_Connection ):
@@ -384,6 +409,13 @@ def close(self):
384
409
self ._read .close ()
385
410
self ._write .close ()
386
411
412
+ CODEINTEL_COMMAND = 'codeintel'
413
+ CODEINTEL_PATHS = (
414
+ '/usr' ,
415
+ '/usr/local' ,
416
+ )
417
+ CODEINTEL_SUBPATHS = ('bin' ,)
418
+
387
419
388
420
class CodeIntelManager (threading .Thread ):
389
421
STATE_UNINITIALIZED = ("uninitialized" ,) # not initialized
@@ -395,7 +427,7 @@ class CodeIntelManager(threading.Thread):
395
427
STATE_DESTROYED = ("destroyed" ,) # connection shut down, child process dead
396
428
STATE_ABORTED = ("aborted" ,)
397
429
398
- _codeintel_command = '/usr/local/bin/codeintel'
430
+ _codeintel_command = None
399
431
_oop_mode = 'pipe'
400
432
_log_levels = ['WARNING' ]
401
433
_state = STATE_UNINITIALIZED
@@ -531,17 +563,36 @@ def kill(self):
531
563
if self ._shutdown_callback :
532
564
self ._shutdown_callback (self )
533
565
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
+
534
587
def init_child (self ):
535
- from . import process
588
+ import process
536
589
assert threading .current_thread ().name != "MainThread" , \
537
590
"CodeIntelManager.init_child should run on background thread!"
538
591
self .log .debug ("initializing child process" )
539
592
conn = None
540
593
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 ]
545
596
546
597
database_dir = os .path .expanduser ('~/.codeintel' )
547
598
cmd += ['--log-file' , os .path .join (database_dir , 'codeintel.log' )]
0 commit comments