3
3
import re
4
4
import sys
5
5
import uuid
6
+ from pathlib import Path
7
+ from typing import List , Union , Sequence , Optional , Any , Tuple , Set
6
8
7
9
import py
8
10
import pytest
@@ -33,7 +35,7 @@ class NodeManager:
33
35
EXIT_TIMEOUT = 10
34
36
DEFAULT_IGNORES = [".*" , "*.pyc" , "*.pyo" , "*~" ]
35
37
36
- def __init__ (self , config , specs = None , defaultchdir = "pyexecnetcache" ):
38
+ def __init__ (self , config , specs = None , defaultchdir = "pyexecnetcache" ) -> None :
37
39
self .config = config
38
40
self .trace = self .config .trace .get ("nodemanager" )
39
41
self .testrunuid = self .config .getoption ("testrunuid" )
@@ -52,7 +54,7 @@ def __init__(self, config, specs=None, defaultchdir="pyexecnetcache"):
52
54
self .specs .append (spec )
53
55
self .roots = self ._getrsyncdirs ()
54
56
self .rsyncoptions = self ._getrsyncoptions ()
55
- self ._rsynced_specs = set ()
57
+ self ._rsynced_specs : Set [ Tuple [ Any , Any ]] = set ()
56
58
57
59
def rsync_roots (self , gateway ):
58
60
"""Rsync the set of roots to the node's gateway cwd."""
@@ -81,7 +83,7 @@ def teardown_nodes(self):
81
83
def _getxspecs (self ):
82
84
return [execnet .XSpec (x ) for x in parse_spec_config (self .config )]
83
85
84
- def _getrsyncdirs (self ):
86
+ def _getrsyncdirs (self ) -> List [ Path ] :
85
87
for spec in self .specs :
86
88
if not spec .popen or spec .chdir :
87
89
break
@@ -108,8 +110,8 @@ def get_dir(p):
108
110
candidates .extend (rsyncroots )
109
111
roots = []
110
112
for root in candidates :
111
- root = py . path . local (root ).realpath ()
112
- if not root .check ():
113
+ root = Path (root ).resolve ()
114
+ if not root .exists ():
113
115
raise pytest .UsageError ("rsyncdir doesn't exist: {!r}" .format (root ))
114
116
if root not in roots :
115
117
roots .append (root )
@@ -160,18 +162,24 @@ def finished():
160
162
class HostRSync (execnet .RSync ):
161
163
"""RSyncer that filters out common files"""
162
164
163
- def __init__ (self , sourcedir , * args , ** kwargs ):
164
- self ._synced = {}
165
- ignores = kwargs .pop ("ignores" , None ) or []
166
- self ._ignores = [
167
- re .compile (fnmatch .translate (getattr (x , "strpath" , x ))) for x in ignores
168
- ]
169
- super ().__init__ (sourcedir = sourcedir , ** kwargs )
170
-
171
- def filter (self , path ):
172
- path = py .path .local (path )
165
+ PathLike = Union [str , "os.PathLike[str]" ]
166
+
167
+ def __init__ (
168
+ self ,
169
+ sourcedir : PathLike ,
170
+ * ,
171
+ ignores : Optional [Sequence [PathLike ]] = None ,
172
+ ** kwargs : object
173
+ ) -> None :
174
+ if ignores is None :
175
+ ignores = []
176
+ self ._ignores = [re .compile (fnmatch .translate (os .fspath (x ))) for x in ignores ]
177
+ super ().__init__ (sourcedir = Path (sourcedir ), ** kwargs )
178
+
179
+ def filter (self , path : PathLike ) -> bool :
180
+ path = Path (path )
173
181
for cre in self ._ignores :
174
- if cre .match (path .basename ) or cre .match (path . strpath ):
182
+ if cre .match (path .name ) or cre .match (str ( path ) ):
175
183
return False
176
184
else :
177
185
return True
@@ -187,20 +195,28 @@ def _report_send_file(self, gateway, modified_rel_path):
187
195
print ("{}:{} <= {}" .format (gateway .spec , remotepath , path ))
188
196
189
197
190
- def make_reltoroot (roots , args ) :
198
+ def make_reltoroot (roots : Sequence [ Path ] , args : List [ str ]) -> List [ str ] :
191
199
# XXX introduce/use public API for splitting pytest args
192
200
splitcode = "::"
193
201
result = []
194
202
for arg in args :
195
203
parts = arg .split (splitcode )
196
- fspath = py .path .local (parts [0 ])
197
- if not fspath .exists ():
204
+ fspath = Path (parts [0 ])
205
+ try :
206
+ exists = fspath .exists ()
207
+ except OSError :
208
+ exists = False
209
+ if not exists :
198
210
result .append (arg )
199
211
continue
200
212
for root in roots :
201
- x = fspath .relto (root )
213
+ x : Optional [Path ]
214
+ try :
215
+ x = fspath .relative_to (root )
216
+ except ValueError :
217
+ x = None
202
218
if x or fspath == root :
203
- parts [0 ] = root .basename + "/" + x
219
+ parts [0 ] = root .name + "/" + str ( x )
204
220
break
205
221
else :
206
222
raise ValueError ("arg {} not relative to an rsync root" .format (arg ))
0 commit comments