Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ronny changes 1 #188

Merged
merged 7 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- "master"
- "test-me-*"
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+"

pull_request:
branches:
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude: doc/en/example/py2py3/test_py2.py
repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
Expand Down
21 changes: 10 additions & 11 deletions doc/example/sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
(c) Holger Krekel, MIT license
"""
import optparse
import pathlib
import re
import sys

Expand Down Expand Up @@ -34,12 +33,12 @@


def parsehosts(path):
path = pathlib.Path(path)
host_regex = re.compile(r"Host\s*(\S+)")
l = []
rex = re.compile(r"Host\s*(\S+)")
with path.open() as f:
for line in f:
m = rex.match(line)

with open(path) as fp:
for line in fp:
m = host_regex.match(line)
if m is not None:
(sshname,) = m.groups()
l.append(sshname)
Expand Down Expand Up @@ -119,7 +118,7 @@ def getcpuinfo(self):


def debug(*args):
print >> sys.stderr, " ".join(map(str, args))
print(" ".join(map(str, args)), file=sys.stderr)


def error(*args):
Expand All @@ -140,7 +139,7 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
ri = RemoteInfo(gw)
# print "%s info:" % sshname
prefix = sshname.upper() + " "
print >> loginfo, prefix, "fqdn:", ri.getfqdn()
print(prefix, "fqdn:", ri.getfqdn(), file=loginfo)
for attr in ("sys.platform", "sys.version_info"):
loginfo.write(f"{prefix} {attr}: ")
loginfo.flush()
Expand All @@ -151,12 +150,12 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
memswap = ri.getmemswap()
if memswap:
mem, swap = memswap
print >> loginfo, prefix, "Memory:", mem, "Swap:", swap
print(prefix, "Memory:", mem, "Swap:", swap, file=loginfo)
cpuinfo = ri.getcpuinfo()
if cpuinfo:
numcpu, model = cpuinfo
print >> loginfo, prefix, "number of cpus:", numcpu
print >> loginfo, prefix, "cpu model", model
print(prefix, "number of cpus:", numcpu, file=loginfo)
print(prefix, "cpu model", model, file=loginfo)
return ri


Expand Down
27 changes: 4 additions & 23 deletions execnet/gateway_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,12 @@ def kill(self):

def killpopen(popen):
try:
if hasattr(popen, "kill"):
popen.kill()
else:
killpid(popen.pid)
except OSError:
sys.stderr.write("ERROR killing: %s\n" % (sys.exc_info()[1]))
popen.kill()
except OSError as e:
sys.stderr.write("ERROR killing: %s\n" % e)
sys.stderr.flush()


def killpid(pid):
if hasattr(os, "kill"):
os.kill(pid, 15)
elif sys.platform == "win32" or getattr(os, "_name", None) == "nt":
import ctypes

PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)
else:
raise OSError(f"no method to kill {pid}")


popen_bootstrapline = "import sys;exec(eval(sys.stdin.readline()))"


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

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ version-file = "execnet/_version.py"
include = [
"/execnet",
]


[tool.mypy]
python_version = "3.7"
49 changes: 17 additions & 32 deletions testing/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pathlib
import shutil
import subprocess
import sys
from functools import lru_cache
from typing import Callable
from typing import Iterator

import execnet
import pytest
Expand All @@ -23,10 +24,15 @@ def pytest_runtest_setup(item):


@pytest.fixture
def makegateway(request):
def group_function() -> Iterator[execnet.Group]:
group = execnet.Group()
request.addfinalizer(lambda: group.terminate(0.5))
return group.makegateway
yield group
group.terminate(0.5)


@pytest.fixture
def makegateway(group_function) -> Callable[[str], execnet.gateway.Gateway]:
return group_function.makegateway


pytest_plugins = ["pytester", "doctest"]
Expand Down Expand Up @@ -101,37 +107,16 @@ def pytest_generate_tests(metafunc):
else:
gwtypes = ["popen", "socket", "ssh", "proxy"]
metafunc.parametrize("gw", gwtypes, indirect=True)
elif "anypython" in metafunc.fixturenames:
metafunc.parametrize(
"anypython",
indirect=True,
argvalues=("sys.executable", "pypy3"),
)


def getexecutable(name, cache={}):
try:
return cache[name]
except KeyError:
if name == "sys.executable":
return pathlib.Path(sys.executable)
path = shutil.which(name)
executable = pathlib.Path(path) if path is not None else None
if executable:
if name == "jython":
popen = subprocess.Popen(
[str(executable), "--version"],
universal_newlines=True,
stderr=subprocess.PIPE,
)
out, err = popen.communicate()
if not err or "2.5" not in err:
executable = None
cache[name] = executable
return executable
@lru_cache()
def getexecutable(name):
if name == "sys.executable":
return sys.executable
return shutil.which(name)


@pytest.fixture
@pytest.fixture(params=("sys.executable", "pypy3"))
def anypython(request):
name = request.param
executable = getexecutable(name)
Expand Down
Loading