Skip to content

Commit caa583c

Browse files
nomore pylib
1 parent 8b9d121 commit caa583c

18 files changed

+269
-447
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exclude: doc/en/example/py2py3/test_py2.py
1+
22
repos:
33
- repo: https://github.com/codespell-project/codespell
44
rev: v2.2.2
@@ -28,7 +28,7 @@ repos:
2828
rev: v3.9.0
2929
hooks:
3030
- id: reorder-python-imports
31-
args: ['--application-directories=execnet', --py37-plus]
31+
args: ['--application-directories=execnet', --py37-plus, "--remove-import=import py"]
3232
- repo: https://github.com/PyCQA/doc8
3333
rev: 'v1.1.1'
3434
hooks:

doc/example/conftest.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import os
12
import sys
3+
from pathlib import Path
24

3-
import py
45

6+
def _add_path(path: Path):
7+
strpath = os.fspath(path)
8+
if strpath not in sys.path:
9+
sys.path.insert(0, strpath)
10+
11+
12+
mydir = Path(__file__).parent
513
# make execnet and example code importable
6-
cand = py.path.local(__file__).dirpath().dirpath().dirpath()
7-
if cand.join("execnet", "__init__.py").check():
8-
if str(cand) not in sys.path:
9-
sys.path.insert(0, str(cand))
10-
cand = py.path.local(__file__).dirpath()
11-
if str(cand) not in sys.path:
12-
sys.path.insert(0, str(cand))
1314

15+
cand = mydir.parent.parent
16+
if cand.joinpath("execnet", "__init__.py").is_file():
17+
_add_path(cand)
18+
_add_path(mydir)
1419
pytest_plugins = ["doctest"]

doc/example/svn-sync-repo.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

doc/example/sysinfo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import sys
1111

1212
import execnet
13-
import py
1413

1514

1615
parser = optparse.OptionParser(usage=__doc__)
@@ -34,14 +33,15 @@
3433

3534

3635
def parsehosts(path):
37-
path = py.path.local(path)
36+
host_regex = re.compile(r"Host\s*(\S+)")
3837
l = []
39-
rex = re.compile(r"Host\s*(\S+)")
40-
for line in path.readlines():
41-
m = rex.match(line)
42-
if m is not None:
43-
(sshname,) = m.groups()
44-
l.append(sshname)
38+
39+
with open(path) as fp:
40+
for line in fp:
41+
m = rex.match(line)
42+
if m is not None:
43+
(sshname,) = m.groups()
44+
l.append(sshname)
4545
return l
4646

4747

execnet/gateway_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import weakref
2121
from io import BytesIO
2222
from typing import Callable
23+
from typing import IO
2324

2425

2526
def reraise(cls, val, tb):
@@ -961,7 +962,7 @@ def log(*msg):
961962
def _terminate_execution(self):
962963
pass
963964

964-
def _send(self, msgcode, channelid=0, data=b""):
965+
def _send(self, msgcode, channelid: int = 0, data: bytes = b""):
965966
message = Message(msgcode, channelid, data)
966967
try:
967968
message.to_io(self._io)

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

execnet/multi.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
(c) 2008-2014, Holger Krekel and others
55
"""
6+
from __future__ import annotations
7+
68
import atexit
79
import sys
810
from functools import partial
@@ -280,16 +282,16 @@ def putreceived(obj, channel=ch):
280282
ch.setcallback(putreceived, endmarker=endmarker)
281283
return self._queue
282284

283-
def waitclose(self):
284-
first = None
285+
def waitclose(self) -> None:
286+
first: Exception | None = None
285287
for ch in self._channels:
286288
try:
287289
ch.waitclose()
288-
except ch.RemoteError:
290+
except ch.RemoteError as e:
289291
if first is None:
290-
first = sys.exc_info()
291-
if first:
292-
reraise(*first)
292+
first = e
293+
if first is not None:
294+
raise first
293295

294296

295297
def safe_terminate(execmodel, timeout, list_of_paired_functions):

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: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import subprocess
22
import sys
3+
from functools import lru_cache
4+
from typing import Callable
5+
from typing import Iterator
36

4-
import execnet
5-
import py
7+
import execnet.gateway
68
import pytest
79
from execnet.gateway_base import get_execmodel
810
from execnet.gateway_base import WorkerPool
@@ -22,10 +24,15 @@ def pytest_runtest_setup(item):
2224

2325

2426
@pytest.fixture
25-
def makegateway(request):
27+
def group_function() -> Iterator[execnet.Group]:
2628
group = execnet.Group()
27-
request.addfinalizer(lambda: group.terminate(0.5))
28-
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
2936

3037

3138
pytest_plugins = ["pytester", "doctest"]
@@ -76,7 +83,7 @@ def getspecssh(config):
7683
xspecs = getgspecs(config)
7784
for spec in xspecs:
7885
if spec.ssh:
79-
if not py.path.local.sysfind("ssh"):
86+
if not shutil.which("ssh"):
8087
pytest.skip("command not found: ssh")
8188
return spec
8289
pytest.skip("need '--gx ssh=...'")
@@ -100,36 +107,18 @@ def pytest_generate_tests(metafunc):
100107
else:
101108
gwtypes = ["popen", "socket", "ssh", "proxy"]
102109
metafunc.parametrize("gw", gwtypes, indirect=True)
103-
elif "anypython" in metafunc.fixturenames:
104-
metafunc.parametrize(
105-
"anypython",
106-
indirect=True,
107-
argvalues=("sys.executable", "pypy3"),
108-
)
109110

110111

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

118+
return shutil.which(name)
131119

132-
@pytest.fixture
120+
121+
@pytest.fixture(params=("sys.executable", "pypy3"))
133122
def anypython(request):
134123
name = request.param
135124
executable = getexecutable(name)

0 commit comments

Comments
 (0)