Skip to content

Commit 2ccaf83

Browse files
authored
Fix subprocess_shell code (Windows Side) (#4)
* add another branch to test on my end * force trigger workflow * reformat test_context with black * reformat all tests to obey flake8 * fix flake8 errors * add dns related things from winloop * try something that isn't invalid on 3.8 * reformat with black using valid 3.8 syntax and the 79 character limit * update setup.py * fix more formatting problems with test_process * uncomment trest_process_streams_pass_fds on windows * slience all other known to fail tests with windows * fix if statement for dns.pyx * silencing reamining failures * remove whitespace * update tests * update tests * skip signal test on apple for now * remove whitespace * reformat with black once more * mark todo for issue 126 (winloop) related * skip test_call_later_2 on windows normal asyncio in 3.11 due to rounding bug * reformat test_base.py * uvloop still has the same problem on windows 3.11 * siganls fork test broken * better skipping system for test_base.py * add extra removal to makefile * nope, 3.8+ on windows has the same problem wiht test_call_later_2 * add __Pyx_MonitoringEventTypes_CyGen_count as a macro incase accidently exposed in windows debug mode * skip create over ssl when in win32 3.14t it's currently a todo bugfix. * skip test_getaddrinfo_4 on mac, it can randomly freeze at different times. * fix subprocess shell code for window's end * update stdlib with os.path.join to help it out * add isabs to subprocess_shell * make outer modules used into constant values * forgot about errors.pyx let me fix that up real quickly
1 parent 3778759 commit 2ccaf83

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

uvloop/dns.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ cdef class AddrInfoRequest(UVRequest):
352352

353353
if host is None:
354354
chost = NULL
355-
elif host == b'' and sys.platform == 'darwin':
355+
elif host == b'' and sys_platform == 'darwin':
356356
# It seems `getaddrinfo("", ...)` on macOS is equivalent to
357357
# `getaddrinfo("localhost", ...)`. This is inconsistent with
358358
# libuv 1.48 which treats empty nodename as EINVAL.
359359
chost = <char*>'localhost'
360-
elif host == b'' and sys.platform == "win32":
360+
elif host == b'' and sys_platform == "win32":
361361
# On Windows, `getaddrinfo("", ...)` is *almost* equivalent to
362362
# `getaddrinfo("..localmachine", ...)`. This is inconsistent with
363363
# libuv 1.48 which treats empty nodename as EINVAL.
@@ -398,7 +398,7 @@ cdef class AddrInfoRequest(UVRequest):
398398
# EAI_NONAME [ErrNo 10001] "No such host is known. ".
399399
# We replace the message with "getaddrinfo failed".
400400
# See also errors.pyx.
401-
if sys.platform == 'win32':
401+
if sys_platform == 'win32':
402402
msg = 'getaddrinfo failed'
403403
else:
404404
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')

uvloop/errors.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ cdef convert_error(int uverr):
131131
# EAI_FAMILY [ErrNo 10047] "An address incompatible with the requested protocol was used. "
132132
# EAI_NONAME [ErrNo 10001] "No such host is known. "
133133
# We replace these messages with "getaddrinfo failed"
134-
if sys.platform == "win32":
134+
if sys_platform == "win32":
135135
if sock_err in (socket_EAI_FAMILY, socket_EAI_NONAME):
136136
msg = 'getaddrinfo failed'
137137
return socket_gaierror(sock_err, msg)

uvloop/includes/stdlib.pxi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ cdef int socket_EAI_SOCKTYPE = getattr(socket, 'EAI_SOCKTYPE', -1)
100100

101101

102102
cdef str os_name = os.name
103+
cdef os_path_isabs = os.path.isabs
104+
cdef os_path_join = os.path.join
103105
cdef os_environ = os.environ
104106
cdef os_dup = os.dup
105107
cdef os_set_inheritable = os.set_inheritable

uvloop/loop.pyx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,34 +2824,25 @@ cdef class Loop:
28242824
if not shell:
28252825
raise ValueError("shell must be True")
28262826

2827-
28282827
if not system.PLATFORM_IS_WINDOWS:
28292828
args = [cmd]
28302829
if shell:
28312830
args = [b'/bin/sh', b'-c'] + args
28322831
else:
2833-
if not shell:
2834-
args = [cmd]
2835-
else:
2836-
# XXX: os is somehow nonexistant.
2837-
# TODO: Fix OS Import on windows.
2838-
import os
2839-
# CHANGED WINDOWS Shell see : https://github.com/libuv/libuv/pull/2627 for more details...
2840-
2841-
# Winloop comment: args[0].split(' ') instead of args to pass some tests in test_process
2842-
2843-
# See subprocess.py for the mirror of this code.
2844-
comspec = os.environ.get("ComSpec")
2845-
if comspec:
2846-
system_root = os.environ.get("SystemRoot", '')
2847-
comspec = os.path.join(system_root, 'System32', 'cmd.exe')
2848-
if not os.path.isabs(comspec):
2849-
raise FileNotFoundError('shell not found: neither %ComSpec% nor %SystemRoot% is set')
2850-
2851-
args = [comspec]
2852-
args.append('/c')
2853-
# TODO: (Vizonex) We probably need a new solution besides using a shlex parser setup.
2854-
args.append(cmd)
2832+
# SEE: https://github.com/libuv/libuv/pull/2627
2833+
2834+
# See subprocess.py for the mirror of this code.
2835+
comspec = os_environ.get("ComSpec")
2836+
if not comspec:
2837+
system_root = os_environ.get("SystemRoot", '')
2838+
comspec = os_path_join(system_root, 'System32', 'cmd.exe')
2839+
if not os_path_isabs(comspec):
2840+
raise FileNotFoundError('shell not found: neither %ComSpec% nor %SystemRoot% is set')
2841+
2842+
args = [comspec]
2843+
args.append('/c')
2844+
args.append(cmd)
2845+
28552846
return await self.__subprocess_run(protocol_factory, args, shell=True,
28562847
**kwargs)
28572848

0 commit comments

Comments
 (0)