Skip to content

Commit

Permalink
Replace py.path.local.sysfind with shutil.which. Refs devpi#930
Browse files Browse the repository at this point in the history
  • Loading branch information
fschulze committed Aug 30, 2023
1 parent 5a1efdd commit 027d069
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
12 changes: 6 additions & 6 deletions client/testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import socket
import textwrap
import py
import shutil
import sys
import json
import time
Expand Down Expand Up @@ -149,10 +150,9 @@ def find_python3():
'python3.9',
'python3']
for name in names:
path = py.path.local.sysfind(name)
if not path:
path = shutil.which(name)
if path is None:
continue
path = str(path)
try:
print("Checking %s at %s" % (name, path))
output = subprocess.check_output([path, '--version'])
Expand Down Expand Up @@ -181,10 +181,10 @@ def server_executable(request, tmpdir_factory):
if not requirements:
requirements = ['devpi-server>=6dev']
# first try installed devpi-server for quick runs during development
path = py.path.local.sysfind("devpi-server")
if path:
path = shutil.which("devpi-server")
if path is None:
print("server_executable: Using existing devpi-server at %s" % path)
return str(path)
return path
# there is no devpi-server installed
python3 = find_python3()
# prepare environment for subprocess call
Expand Down
7 changes: 4 additions & 3 deletions client/testing/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import py
import pytest
import re
import shutil
import sys
import tarfile
from devpi.upload import Checkout
Expand All @@ -28,7 +29,7 @@ def runproc(cmd):
args = cmd.split()
path0 = args[0]
if not os.path.isabs(path0):
path0 = py.path.local.sysfind(path0)
path0 = shutil.which(path0)
if not path0:
pytest.skip("%r not found" % args[0])
return check_output([str(path0)] + args[1:])
Expand Down Expand Up @@ -75,7 +76,7 @@ def repo(self, request, setupdir_rel, tmpdir_factory):
unicode_fn = str(unicode_fn, "utf8")
setupdir.ensure(unicode_fn)
if request.param == "hg":
if not py.path.local.sysfind("hg"):
if not shutil.which("hg"):
pytest.skip("'hg' command not found")
with repo.as_cwd():
runproc("hg init")
Expand All @@ -84,7 +85,7 @@ def repo(self, request, setupdir_rel, tmpdir_factory):
unicode_fn))
runproc("hg commit --config ui.username=whatever -m message")
return repo
if not py.path.local.sysfind("git"):
if not shutil.which("git"):
pytest.skip("'git' command not found")
with repo.as_cwd():
runproc("git init")
Expand Down
3 changes: 2 additions & 1 deletion common/testing/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from subprocess import Popen, PIPE
import py
import pytest
import shutil
import sys


Expand All @@ -30,7 +31,7 @@ def _writedir(tmpdir, contentdict, prefixes=()):


def create_tarfile_fromdict(tmpdir, contentdict):
tar = py.path.local.sysfind("tar")
tar = shutil.which("tar")
if not tar:
pytest.skip("tar command not found")
if sys.platform.startswith('win'):
Expand Down
4 changes: 2 additions & 2 deletions common/testing/test_proc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest
import py
import shutil
from devpi_common.proc import CalledProcessError
from devpi_common.proc import check_output


@pytest.fixture
def hg():
hg = py.path.local.sysfind("hg")
hg = shutil.which("hg")
if not hg:
pytest.skip("no hg")
return str(hg)
Expand Down
11 changes: 6 additions & 5 deletions server/test_devpi_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import py
import requests
import shutil
import socket
import sys
import time
Expand Down Expand Up @@ -1027,10 +1028,10 @@ def server_directory():
@pytest.fixture(scope="module")
def call_devpi_in_dir():
# let xproc find the correct executable instead of py.test
devpigenconfig = str(py.path.local.sysfind("devpi-gen-config"))
devpiimport = str(py.path.local.sysfind("devpi-import"))
devpiinit = str(py.path.local.sysfind("devpi-init"))
devpiserver = str(py.path.local.sysfind("devpi-server"))
devpigenconfig = shutil.which("devpi-gen-config")
devpiimport = shutil.which("devpi-import")
devpiinit = shutil.which("devpi-init")
devpiserver = shutil.which("devpi-server")

def devpi(server_dir, args):
from devpi_server.genconfig import genconfig
Expand Down Expand Up @@ -1194,7 +1195,7 @@ def adjust_nginx_conf_content(content):

def _nginx_host_port(host, port, call_devpi_in_dir, server_directory, adjust_nginx_conf_content):
# let xproc find the correct executable instead of py.test
nginx = py.path.local.sysfind("nginx")
nginx = shutil.which("nginx")
if nginx is None:
pytest.skip("No nginx executable found.")
nginx = str(nginx)
Expand Down

0 comments on commit 027d069

Please sign in to comment.