Skip to content

Commit ea071bc

Browse files
authored
Merge pull request #184 from bluetech/testing-rm-py
testing: some cleanups
2 parents 6386980 + ef71036 commit ea071bc

17 files changed

+314
-265
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* minimal mypy fixes and python2 support code drop
77
* migrate packaging to hatch
88
* drop deprecated apis of old makegateway names
9+
* Removed ``py`` testing dependency
910

1011

1112

doc/example/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import pathlib
12
import sys
23

3-
import py
44

5-
# make execnet and example code importable
6-
cand = py.path.local(__file__).dirpath().dirpath().dirpath()
7-
if cand.join("execnet", "__init__.py").check():
5+
# Make execnet and example code importable.
6+
cand = pathlib.Path(__file__).parent.parent.parent
7+
if cand.joinpath("execnet", "__init__.py").exists():
88
if str(cand) not in sys.path:
99
sys.path.insert(0, str(cand))
10-
cand = py.path.local(__file__).dirpath()
10+
cand = pathlib.Path(__file__).parent
1111
if str(cand) not in sys.path:
1212
sys.path.insert(0, str(cand))
1313

doc/example/svn-sync-repo.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
77
"""
88
import os
9+
import pathlib
10+
import subprocess
911
import sys
1012

1113
import execnet
12-
import py
1314

1415

1516
def usage():
@@ -19,8 +20,8 @@ def usage():
1920

2021
def main(args):
2122
remote = args[0]
22-
localrepo = py.path.local(args[1])
23-
if not localrepo.check(dir=1):
23+
localrepo = pathlib.Path(args[1])
24+
if not localrepo.is_dir():
2425
raise SystemExit(f"localrepo {localrepo} does not exist")
2526
if len(args) == 3:
2627
configfile = args[2]
@@ -39,12 +40,18 @@ def main(args):
3940
# 4. client goes back to step 1
4041
c = gw.remote_exec(
4142
"""
42-
import py
4343
import os
44+
import subprocess
4445
import time
46+
4547
remote_rev, repopath = channel.receive()
46-
while 1:
47-
rev = py.process.cmdexec('svnlook youngest "%s"' % repopath)
48+
while True:
49+
rev = subprocess.run(
50+
["svnlook", "youngest", repopath],
51+
check=True,
52+
capture_output=True,
53+
text=True,
54+
).stdout
4855
rev = int(rev)
4956
if rev > remote_rev:
5057
revrange = (remote_rev+1, rev)
@@ -103,12 +110,17 @@ def svn_load(repo, dumpchannel, maxcount=100):
103110
if count <= 0:
104111
dumpchannel.send(maxcount)
105112
count = maxcount
106-
print >> sys.stdout
113+
print()
107114
f.close()
108115

109116

110117
def get_svn_youngest(repo):
111-
rev = py.process.cmdexec('svnlook youngest "%s"' % repo)
118+
rev = subprocess.run(
119+
["svnlook", "youngest", repo],
120+
check=True,
121+
capture_output=True,
122+
text=True,
123+
).stdout
112124
return int(rev)
113125

114126

doc/example/sysinfo.py

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

1213
import execnet
13-
import py
1414

1515

1616
parser = optparse.OptionParser(usage=__doc__)
@@ -34,14 +34,15 @@
3434

3535

3636
def parsehosts(path):
37-
path = py.path.local(path)
37+
path = pathlib.Path(path)
3838
l = []
3939
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)
40+
with path.open() as f:
41+
for line in f:
42+
m = rex.match(line)
43+
if m is not None:
44+
(sshname,) = m.groups()
45+
l.append(sshname)
4546
return l
4647

4748

execnet/gateway.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,15 @@ def rinfo_source(channel):
169169

170170
def _find_non_builtin_globals(source, codeobj):
171171
import ast
172-
173-
try:
174-
import __builtin__
175-
except ImportError:
176-
import builtins as __builtin__
172+
import builtins
177173

178174
vars = dict.fromkeys(codeobj.co_varnames)
179175
return [
180176
node.id
181177
for node in ast.walk(ast.parse(source))
182178
if isinstance(node, ast.Name)
183179
and node.id not in vars
184-
and node.id not in __builtin__.__dict__
180+
and node.id not in builtins.__dict__
185181
]
186182

187183

execnet/rsync.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,26 @@ def _send_directory(self, path):
173173
self._send_directory_structure(p)
174174

175175
def _send_link_structure(self, path):
176-
linkpoint = os.readlink(path)
176+
sourcedir = self._sourcedir
177177
basename = path[len(self._sourcedir) + 1 :]
178-
if linkpoint.startswith(self._sourcedir):
179-
self._send_link("linkbase", basename, linkpoint[len(self._sourcedir) + 1 :])
178+
linkpoint = os.readlink(path)
179+
# On Windows, readlink returns an extended path (//?/) for
180+
# absolute links, but relpath doesn't like mixing extended
181+
# and non-extended paths. So fix it up ourselves.
182+
if (
183+
os.path.__name__ == "ntpath"
184+
and linkpoint.startswith("\\\\?\\")
185+
and not self._sourcedir.startswith("\\\\?\\")
186+
):
187+
sourcedir = "\\\\?\\" + self._sourcedir
188+
try:
189+
relpath = os.path.relpath(linkpoint, sourcedir)
190+
except ValueError:
191+
relpath = None
192+
if relpath not in (None, os.curdir, os.pardir) and not relpath.startswith(
193+
os.pardir + os.sep
194+
):
195+
self._send_link("linkbase", basename, relpath)
180196
else:
181197
# relative or absolute link, just send it
182198
self._send_link("link", basename, linkpoint)

testing/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import pathlib
2+
import shutil
13
import subprocess
24
import sys
35

46
import execnet
5-
import py
67
import pytest
78
from execnet.gateway_base import get_execmodel
89
from execnet.gateway_base import WorkerPool
@@ -76,7 +77,7 @@ def getspecssh(config):
7677
xspecs = getgspecs(config)
7778
for spec in xspecs:
7879
if spec.ssh:
79-
if not py.path.local.sysfind("ssh"):
80+
if not shutil.which("ssh"):
8081
pytest.skip("command not found: ssh")
8182
return spec
8283
pytest.skip("need '--gx ssh=...'")
@@ -113,8 +114,9 @@ def getexecutable(name, cache={}):
113114
return cache[name]
114115
except KeyError:
115116
if name == "sys.executable":
116-
return py.path.local(sys.executable)
117-
executable = py.path.local.sysfind(name)
117+
return pathlib.Path(sys.executable)
118+
path = shutil.which(name)
119+
executable = pathlib.Path(path) if path is not None else None
118120
if executable:
119121
if name == "jython":
120122
popen = subprocess.Popen(

0 commit comments

Comments
 (0)