Skip to content

Commit b8dc330

Browse files
authored
Merge pull request #188 from bluetech/ronny-changes-1
Ronny changes 1
2 parents ea071bc + 35e03ea commit b8dc330

File tree

12 files changed

+200
-256
lines changed

12 files changed

+200
-256
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
- "master"
77
- "test-me-*"
88
tags:
9-
- "[0-9]+.[0-9]+.[0-9]+"
10-
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
9+
- "v[0-9]+.[0-9]+.[0-9]+"
10+
- "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
1111

1212
pull_request:
1313
branches:

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
exclude: doc/en/example/py2py3/test_py2.py
21
repos:
32
- repo: https://github.com/codespell-project/codespell
43
rev: v2.2.4

doc/example/sysinfo.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
(c) Holger Krekel, MIT license
77
"""
88
import optparse
9-
import pathlib
109
import re
1110
import sys
1211

@@ -34,12 +33,12 @@
3433

3534

3635
def parsehosts(path):
37-
path = pathlib.Path(path)
36+
host_regex = re.compile(r"Host\s*(\S+)")
3837
l = []
39-
rex = re.compile(r"Host\s*(\S+)")
40-
with path.open() as f:
41-
for line in f:
42-
m = rex.match(line)
38+
39+
with open(path) as fp:
40+
for line in fp:
41+
m = host_regex.match(line)
4342
if m is not None:
4443
(sshname,) = m.groups()
4544
l.append(sshname)
@@ -119,7 +118,7 @@ def getcpuinfo(self):
119118

120119

121120
def debug(*args):
122-
print >> sys.stderr, " ".join(map(str, args))
121+
print(" ".join(map(str, args)), file=sys.stderr)
123122

124123

125124
def error(*args):
@@ -140,7 +139,7 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
140139
ri = RemoteInfo(gw)
141140
# print "%s info:" % sshname
142141
prefix = sshname.upper() + " "
143-
print >> loginfo, prefix, "fqdn:", ri.getfqdn()
142+
print(prefix, "fqdn:", ri.getfqdn(), file=loginfo)
144143
for attr in ("sys.platform", "sys.version_info"):
145144
loginfo.write(f"{prefix} {attr}: ")
146145
loginfo.flush()
@@ -151,12 +150,12 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
151150
memswap = ri.getmemswap()
152151
if memswap:
153152
mem, swap = memswap
154-
print >> loginfo, prefix, "Memory:", mem, "Swap:", swap
153+
print(prefix, "Memory:", mem, "Swap:", swap, file=loginfo)
155154
cpuinfo = ri.getcpuinfo()
156155
if cpuinfo:
157156
numcpu, model = cpuinfo
158-
print >> loginfo, prefix, "number of cpus:", numcpu
159-
print >> loginfo, prefix, "cpu model", model
157+
print(prefix, "number of cpus:", numcpu, file=loginfo)
158+
print(prefix, "cpu model", model, file=loginfo)
160159
return ri
161160

162161

execnet/gateway_io.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,12 @@ def kill(self):
3232

3333
def killpopen(popen):
3434
try:
35-
if hasattr(popen, "kill"):
36-
popen.kill()
37-
else:
38-
killpid(popen.pid)
39-
except OSError:
40-
sys.stderr.write("ERROR killing: %s\n" % (sys.exc_info()[1]))
35+
popen.kill()
36+
except OSError as e:
37+
sys.stderr.write("ERROR killing: %s\n" % e)
4138
sys.stderr.flush()
4239

4340

44-
def killpid(pid):
45-
if hasattr(os, "kill"):
46-
os.kill(pid, 15)
47-
elif sys.platform == "win32" or getattr(os, "_name", None) == "nt":
48-
import ctypes
49-
50-
PROCESS_TERMINATE = 1
51-
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
52-
ctypes.windll.kernel32.TerminateProcess(handle, -1)
53-
ctypes.windll.kernel32.CloseHandle(handle)
54-
else:
55-
raise OSError(f"no method to kill {pid}")
56-
57-
5841
popen_bootstrapline = "import sys;exec(eval(sys.stdin.readline()))"
5942

6043

@@ -72,10 +55,8 @@ def shell_split_path(path):
7255
def popen_args(spec):
7356
args = shell_split_path(spec.python) if spec.python else [sys.executable]
7457
args.append("-u")
75-
if spec is not None and spec.dont_write_bytecode:
58+
if spec.dont_write_bytecode:
7659
args.append("-B")
77-
# Slight gymnastics in ordering these arguments because CPython (as of
78-
# 2.7.1) ignores -B if you provide `python -c "something" -B`
7960
args.extend(["-c", popen_bootstrapline])
8061
return args
8162

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ version-file = "execnet/_version.py"
5555
include = [
5656
"/execnet",
5757
]
58+
59+
60+
[tool.mypy]
61+
python_version = "3.7"

testing/conftest.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import pathlib
21
import shutil
3-
import subprocess
42
import sys
3+
from functools import lru_cache
4+
from typing import Callable
5+
from typing import Iterator
56

67
import execnet
78
import pytest
@@ -23,10 +24,15 @@ def pytest_runtest_setup(item):
2324

2425

2526
@pytest.fixture
26-
def makegateway(request):
27+
def group_function() -> Iterator[execnet.Group]:
2728
group = execnet.Group()
28-
request.addfinalizer(lambda: group.terminate(0.5))
29-
return group.makegateway
29+
yield group
30+
group.terminate(0.5)
31+
32+
33+
@pytest.fixture
34+
def makegateway(group_function) -> Callable[[str], execnet.gateway.Gateway]:
35+
return group_function.makegateway
3036

3137

3238
pytest_plugins = ["pytester", "doctest"]
@@ -101,37 +107,16 @@ def pytest_generate_tests(metafunc):
101107
else:
102108
gwtypes = ["popen", "socket", "ssh", "proxy"]
103109
metafunc.parametrize("gw", gwtypes, indirect=True)
104-
elif "anypython" in metafunc.fixturenames:
105-
metafunc.parametrize(
106-
"anypython",
107-
indirect=True,
108-
argvalues=("sys.executable", "pypy3"),
109-
)
110110

111111

112-
def getexecutable(name, cache={}):
113-
try:
114-
return cache[name]
115-
except KeyError:
116-
if name == "sys.executable":
117-
return pathlib.Path(sys.executable)
118-
path = shutil.which(name)
119-
executable = pathlib.Path(path) if path is not None else None
120-
if executable:
121-
if name == "jython":
122-
popen = subprocess.Popen(
123-
[str(executable), "--version"],
124-
universal_newlines=True,
125-
stderr=subprocess.PIPE,
126-
)
127-
out, err = popen.communicate()
128-
if not err or "2.5" not in err:
129-
executable = None
130-
cache[name] = executable
131-
return executable
112+
@lru_cache()
113+
def getexecutable(name):
114+
if name == "sys.executable":
115+
return sys.executable
116+
return shutil.which(name)
132117

133118

134-
@pytest.fixture
119+
@pytest.fixture(params=("sys.executable", "pypy3"))
135120
def anypython(request):
136121
name = request.param
137122
executable = getexecutable(name)

0 commit comments

Comments
 (0)