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 authored and markmcclain committed Jan 8, 2024
1 parent da83902 commit a722631
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
7 changes: 4 additions & 3 deletions client/devpi/main.py
Expand Up @@ -6,6 +6,7 @@
import py
import argparse
import shlex
import shutil
import subprocess
import textwrap
from base64 import b64encode
Expand Down Expand Up @@ -391,10 +392,10 @@ def popen_output(self, args, cwd=None, report=True):
args = [str(x) for x in args]
if cwd is None:
cwd = self.cwd
cmd = py.path.local.sysfind(args[0])
if not cmd:
cmd = shutil.which(args[0])
if cmd is None:
self.fatal("command not found: %s" % args[0])
args[0] = str(cmd)
args[0] = cmd
if report:
self.report_popen(args, cwd)
encoding = sys.getdefaultencoding()
Expand Down
6 changes: 3 additions & 3 deletions client/devpi/test.py
Expand Up @@ -3,7 +3,7 @@
import re
import shlex
import hashlib
import py
import shutil
from devpi_common.archive import Archive
from devpi_common.metadata import parse_requirement
import json
Expand Down Expand Up @@ -72,8 +72,8 @@ def runtox(self, link, pkg, sdist_pkg=None, upload_tox_results=True):
"tox", venvdir=self.hub.venv, glob=True)
if not tox_path:
# try outside of venv
tox_path = py.path.local.sysfind("tox")
if not tox_path:
tox_path = shutil.which("tox")
if tox_path is None:
self.hub.fatal("no tox binary found")
toxcmd = [
str(tox_path),
Expand Down
3 changes: 2 additions & 1 deletion client/devpi/upload.py
Expand Up @@ -3,6 +3,7 @@
import sys
import py
import re
import shutil
import zipfile

import build.util
Expand Down Expand Up @@ -386,7 +387,7 @@ def python(self):

def _virtualenv_python(self):
if 'VIRTUAL_ENV' in os.environ:
return py.path.local.sysfind("python")
return shutil.which("python")

def __str__(self):
return "<Exported %s>" % self.rootpath
Expand Down
5 changes: 3 additions & 2 deletions client/devpi/use.py
Expand Up @@ -10,6 +10,7 @@
import py
import re
import json
import shutil

from devpi_common.types import cached_property
from devpi_common.url import URL
Expand Down Expand Up @@ -360,9 +361,9 @@ def getvenvbin(self, name, venvdir=None, glob=True):
venvdir = self.venvdir
if venvdir:
bindir = py.path.local(venvdir).join(vbin)
return py.path.local.sysfind(name, paths=[bindir])
return shutil.which(name, path=str(bindir))
if glob:
return py.path.local.sysfind(name)
return shutil.which(name)

@property
def root_url(self):
Expand Down
12 changes: 6 additions & 6 deletions client/testing/conftest.py
Expand Up @@ -9,6 +9,7 @@
import socket
import textwrap
import py
import shutil
import sys
import json
import time
Expand Down Expand Up @@ -101,10 +102,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 @@ -132,10 +132,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 not 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
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
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
11 changes: 6 additions & 5 deletions server/test_devpi_server/conftest.py
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 a722631

Please sign in to comment.