MCPcopy
hub / github.com/pytest-dev/pytest / sysfind

Method sysfind

src/_pytest/_py/path.py:1193–1237  ·  view source on GitHub ↗

Return a path object found by looking at the systems underlying PATH specification. If the checker is not None it will be invoked to filter matching paths. If a binary cannot be found, None is returned Note: This is probably not working on plain win32 systems

(cls, name, checker=None, paths=None)

Source from the content-addressed store, hash-verified

1191
1192 @classmethod
1193 def sysfind(cls, name, checker=None, paths=None):
1194 """Return a path object found by looking at the systems
1195 underlying PATH specification. If the checker is not None
1196 it will be invoked to filter matching paths. If a binary
1197 cannot be found, None is returned
1198 Note: This is probably not working on plain win32 systems
1199 but may work on cygwin.
1200 """
1201 if isabs(name):
1202 p = local(name)
1203 if p.check(file=1):
1204 return p
1205 else:
1206 if paths is None:
1207 if iswin32:
1208 paths = os.environ["Path"].split(";")
1209 if "" not in paths and "." not in paths:
1210 paths.append(".")
1211 try:
1212 systemroot = os.environ["SYSTEMROOT"]
1213 except KeyError:
1214 pass
1215 else:
1216 paths = [
1217 path.replace("%SystemRoot%", systemroot) for path in paths
1218 ]
1219 else:
1220 paths = os.environ["PATH"].split(":")
1221 tryadd = []
1222 if iswin32:
1223 tryadd += os.environ["PATHEXT"].split(os.pathsep)
1224 tryadd.append("")
1225
1226 for x in paths:
1227 for addext in tryadd:
1228 p = local(x).join(name, abs=True) + addext
1229 try:
1230 if p.check(file=1):
1231 if checker:
1232 if not checker(p):
1233 continue
1234 return p
1235 except error.EACCES:
1236 pass
1237 return None
1238
1239 @classmethod
1240 def _gethomedir(cls):

Callers 8

test_sysfindMethod · 0.80
test_sysfind_absoluteMethod · 0.80
test_sysfind_multipleMethod · 0.80
test_sysexecMethod · 0.80
test_sysexec_failingMethod · 0.80

Calls 3

appendMethod · 0.80
joinMethod · 0.80
checkMethod · 0.45

Tested by 8

test_sysfindMethod · 0.64
test_sysfind_absoluteMethod · 0.64
test_sysfind_multipleMethod · 0.64
test_sysexecMethod · 0.64
test_sysexec_failingMethod · 0.64