Skip to content

Commit a419b85

Browse files
committed
Version bump to v2.0.0-beta.31
+ Fix windows imports under Python 3
1 parent 95a715c commit a419b85

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

codeintel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.0-beta.30'
1+
__version__ = '2.0.0-beta.31'

codeintel/process.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def __init__(self, msg, errno=-1):
8888
self.errno = errno
8989

9090

91-
# Check if this is Windows NT and above.
92-
if sys.platform == "win32" and sys.getwindowsversion()[3] == 2:
93-
94-
import winprocess
91+
if sys.platform.startswith("win"):
9592
import subprocess
9693

9794
# In Python 3 on Windows, a lot of the functions previously
@@ -106,6 +103,16 @@ def subprocess_import(attr):
106103
return value
107104
raise ImportError
108105

106+
GetStdHandle = subprocess_import('GetStdHandle')
107+
STD_INPUT_HANDLE = subprocess_import('STD_INPUT_HANDLE')
108+
STD_OUTPUT_HANDLE = subprocess_import('STD_OUTPUT_HANDLE')
109+
STD_ERROR_HANDLE = subprocess_import('STD_ERROR_HANDLE')
110+
111+
112+
# Check if this is Windows NT and above.
113+
if sys.platform == "win32" and sys.getwindowsversion()[3] == 2:
114+
import winprocess
115+
109116
try:
110117
# These subprocess variables have moved around between Python versions.
111118
list2cmdline = subprocess_import('list2cmdline')
@@ -389,16 +396,14 @@ def _needToHackAroundStdHandles(cls):
389396
if sys.platform != "win32":
390397
cls.__needToHackAroundStdHandles = False
391398
else:
392-
from _subprocess import GetStdHandle, STD_INPUT_HANDLE
393399
stdin_handle = GetStdHandle(STD_INPUT_HANDLE)
394400
if stdin_handle is not None:
395401
cls.__needToHackAroundStdHandles = True
396402
else:
397403
cls.__needToHackAroundStdHandles = False
398404
return cls.__needToHackAroundStdHandles
399405

400-
@classmethod
401-
def _isFileObjInheritable(cls, fileobj, stream_name):
406+
def _isFileObjInheritable(self, fileobj, stream_name):
402407
"""Check if a given file-like object (or whatever else subprocess.Popen
403408
takes as a handle/stream) can be correctly inherited by a child process.
404409
This just duplicates the code in subprocess.Popen._get_handles to make
@@ -408,7 +413,6 @@ def _isFileObjInheritable(cls, fileobj, stream_name):
408413
@param fileobj The object being used as a fd/handle/whatever
409414
@param stream_name The name of the stream, "stdin", "stdout", or "stderr"
410415
"""
411-
import _subprocess
412416
import ctypes
413417
import msvcrt
414418
new_handle = None
@@ -423,11 +427,11 @@ def _isFileObjInheritable(cls, fileobj, stream_name):
423427
try:
424428
if fileobj is None:
425429
std_handle = {
426-
"stdin": _subprocess.STD_INPUT_HANDLE,
427-
"stdout": _subprocess.STD_OUTPUT_HANDLE,
428-
"stderr": _subprocess.STD_ERROR_HANDLE,
430+
"stdin": STD_INPUT_HANDLE,
431+
"stdout": STD_OUTPUT_HANDLE,
432+
"stderr": STD_ERROR_HANDLE,
429433
}[stream_name]
430-
handle = _subprocess.GetStdHandle(std_handle)
434+
handle = GetStdHandle(std_handle)
431435
if handle is None:
432436
# subprocess.Popen._get_handles creates a new pipe here
433437
# we don't have to worry about things we create

0 commit comments

Comments
 (0)