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