mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 14:59:41 +08:00
Add a way to generalize Popen
This commit is contained in:
@@ -10,6 +10,7 @@ import re
|
|||||||
import pkgutil
|
import pkgutil
|
||||||
import warnings
|
import warnings
|
||||||
import inspect
|
import inspect
|
||||||
|
import subprocess
|
||||||
try:
|
try:
|
||||||
import importlib
|
import importlib
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -500,3 +501,11 @@ except ImportError:
|
|||||||
VAR_POSITIONAL = object()
|
VAR_POSITIONAL = object()
|
||||||
KEYWORD_ONLY = object()
|
KEYWORD_ONLY = object()
|
||||||
VAR_KEYWORD = object()
|
VAR_KEYWORD = object()
|
||||||
|
|
||||||
|
|
||||||
|
class GeneralizedPopen(subprocess.Popen):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
creation_flags = 0
|
||||||
|
if os.name == 'nt':
|
||||||
|
creation_flags = subprocess.CREATE_NO_WINDOW
|
||||||
|
super(GeneralizedPopen, self).__init__(*args, creation_flags=creation_flags, **kwargs)
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import PIPE
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
# When dropping Python 2.7 support we should consider switching to
|
# When dropping Python 2.7 support we should consider switching to
|
||||||
# `shutil.which`.
|
# `shutil.which`.
|
||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
|
|
||||||
|
from jedi._compatibility import GeneralizedPopen
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate.compiled.subprocess import get_subprocess, \
|
from jedi.evaluate.compiled.subprocess import get_subprocess, \
|
||||||
EvaluatorSameProcess, EvaluatorSubprocess
|
EvaluatorSameProcess, EvaluatorSubprocess
|
||||||
@@ -54,7 +55,7 @@ class _Environment(_BaseEnvironment):
|
|||||||
|
|
||||||
def _get_version(self):
|
def _get_version(self):
|
||||||
try:
|
try:
|
||||||
process = Popen([self.executable, '--version'], stdout=PIPE, stderr=PIPE)
|
process = GeneralizedPopen([self.executable, '--version'], stdout=PIPE, stderr=PIPE)
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
retcode = process.poll()
|
retcode = process.poll()
|
||||||
if retcode:
|
if retcode:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import traceback
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from jedi._compatibility import queue, is_py3, force_unicode, \
|
from jedi._compatibility import queue, is_py3, force_unicode, \
|
||||||
pickle_dump, pickle_load
|
pickle_dump, pickle_load, GeneralizedPopen
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate.compiled.subprocess import functions
|
from jedi.evaluate.compiled.subprocess import functions
|
||||||
from jedi.evaluate.compiled.access import DirectObjectAccess, AccessPath, \
|
from jedi.evaluate.compiled.access import DirectObjectAccess, AccessPath, \
|
||||||
@@ -138,7 +138,7 @@ class _CompiledSubprocess(object):
|
|||||||
_MAIN_PATH,
|
_MAIN_PATH,
|
||||||
os.path.dirname(os.path.dirname(parso_path))
|
os.path.dirname(os.path.dirname(parso_path))
|
||||||
)
|
)
|
||||||
return subprocess.Popen(
|
return GeneralizedPopen(
|
||||||
args,
|
args,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
|||||||
Reference in New Issue
Block a user