Skip to content

Commit

Permalink
WIP Remove usage of py.path from devpi-client. Refs devpi#930
Browse files Browse the repository at this point in the history
  • Loading branch information
fschulze committed Aug 30, 2023
1 parent 83266e6 commit 8488a85
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 199 deletions.
46 changes: 23 additions & 23 deletions client/devpi/main.py
Expand Up @@ -3,21 +3,22 @@
import sys
import time
import traceback
import py
import argparse
import shlex
import shutil
import subprocess
import textwrap
from base64 import b64encode
from contextlib import closing, contextmanager
from contextlib import suppress
from devpi import hookspecs
from devpi_common.terminal import TerminalWriter
from devpi_common.types import lazydecorator, cached_property
from devpi_common.url import URL
from devpi.use import PersistentCurrent
from devpi_common.request import new_requests_session
from devpi import __version__ as client_version
from pathlib import Path
from pluggy import HookimplMarker
from pluggy import PluginManager
from shutil import rmtree
Expand Down Expand Up @@ -70,7 +71,7 @@ class Hub:
def __init__(self, args, file=None, pm=None):
self._tw = TerminalWriter(file)
self.args = args
self.cwd = py.path.local()
self.cwd = Path()
self.quiet = False
self._last_http_stati = []
self.http = new_requests_session(agent=("client", client_version))
Expand All @@ -95,24 +96,24 @@ def set_quiet(self):

@property
def clientdir(self):
return py.path.local(self.args.clientdir)
return Path(self.args.clientdir)

@property
def auth_path(self):
return self.clientdir.join("auth.json")
return self.clientdir / "auth.json"

@property
def local_current_path(self):
venv = self.active_venv()
if venv is not None:
return venv.join('devpi.json')
return venv / 'devpi.json'

@property
def current_path(self):
local_path = self.local_current_path
if local_path is not None and local_path.exists():
return local_path
return self.clientdir.join("current.json")
return self.clientdir / "current.json"

def require_valid_current_with_index(self):
current = self.current
Expand Down Expand Up @@ -238,17 +239,16 @@ def remove_readonly(func, path, excinfo):
else:
return

workdir = py.path.local(
mkdtemp(prefix=prefix))
workdir = Path(mkdtemp(prefix=prefix))

self.info("using workdir", workdir)
try:
yield workdir
finally:
rmtree(workdir.strpath, onerror=remove_readonly)
rmtree(workdir, onerror=remove_readonly)

def get_current(self, args_url=None):
self.clientdir.ensure(dir=1)
self.clientdir.mkdir(parents=True, exist_ok=True)
current = PersistentCurrent(self.auth_path, self.current_path)
index_url = getattr(self.args, "index", None)
if "DEVPI_INDEX" in os.environ:
Expand Down Expand Up @@ -307,10 +307,10 @@ def current(self):
return self.get_current()

def get_existing_file(self, arg):
p = py.path.local(arg, expanduser=True)
p = Path(arg).expanduser()
if not p.exists():
self.fatal("file does not exist: %s" % p)
elif not p.isfile():
elif not p.is_file():
self.fatal("is not a file: %s" % p)
return p

Expand Down Expand Up @@ -349,11 +349,11 @@ def venv(self):
else:
venvdir = self.current.venvdir or self.active_venv()
if venvdir:
cand = self.cwd.join(venvdir, vbin, abs=True)
if not cand.check() and self.venvwrapper_home:
cand = self.venvwrapper_home.join(venvdir, vbin, abs=True)
venvdir = cand.dirpath().strpath
if not cand.check():
cand = self.cwd / venvdir / vbin
if not cand.exists() and self.venvwrapper_home:
cand = self.venvwrapper_home / venvdir / vbin
venvdir = str(cand.parent)
if not cand.exists():
if self.current.venvdir:
self.fatal(
"No virtualenv found at: %r\n"
Expand All @@ -376,14 +376,14 @@ def venvwrapper_home(self):
path = os.environ.get("WORKON_HOME", None)
if path is None:
return
return py.path.local(path)
return Path(path)

def active_venv(self):
"""current activated virtualenv"""
path = os.environ.get("VIRTUAL_ENV", None)
if path is None:
return
return py.path.local(path)
return Path(path)

def popen_output(self, args, cwd=None, report=True):
if isinstance(args, str):
Expand Down Expand Up @@ -426,15 +426,15 @@ def popen(self, args, cwd=None, dryrun=None, **popen_kwargs):

def report_popen(self, args, cwd=None, extraenv=None):
base = cwd or self.cwd
rel = py.path.local(args[0]).relto(base)
if not rel:
rel = str(args[0])
rel = Path(args[0])
with suppress(ValueError):
rel = rel.relative_to(base)
if extraenv is not None:
envadd = " [%s]" % ",".join(
["%s=%r" % item for item in sorted(extraenv.items())])
else:
envadd = ""
self.line("--> ", base + "$", rel, " ".join(args[1:]), envadd)
self.line(f"--> {base}$ {rel} {' '.join(args[1:])} {envadd}")

def popen_check(self, args, extraenv=None, **kwargs):
assert args[0], args
Expand Down
10 changes: 5 additions & 5 deletions client/devpi/push.py
@@ -1,6 +1,6 @@
import py
from devpi_common.metadata import parse_requirement, splitbasename
from . import pypirc
from pathlib import Path
import traceback


Expand Down Expand Up @@ -34,11 +34,11 @@ def parse_target(hub, args):
posturl = args.target[5:]
pypirc_path = args.pypirc
if pypirc_path is None:
pypirc_path = py.path.local._gethomedir().join(".pypirc")
pypirc_path = Path().home() / ".pypirc"
else:
pypirc_path = py.path.local().join(args.pypirc, abs=True)
if not pypirc_path.check():
hub.fatal("no pypirc file found at: %s" %(pypirc_path))
pypirc_path = Path() / args.pypirc
if not pypirc_path.is_file():
hub.fatal(f"no pypirc file found at: {pypirc_path}")
hub.info("using pypirc", pypirc_path)
auth = pypirc.Auth(pypirc_path)
try:
Expand Down
4 changes: 2 additions & 2 deletions client/devpi/pypirc.py
@@ -1,14 +1,14 @@
"""
helpers for authenticating against info from .pypirc files.
"""
from pathlib import Path
import iniconfig
import py


class Auth:
def __init__(self, path=None):
if path is None:
path = py.path.local._gethomedir().join(".pypirc")
path = Path().home() / ".pypirc"
self.ini = iniconfig.IniConfig(path)

def get_url_auth(self, secname):
Expand Down
5 changes: 2 additions & 3 deletions client/devpi/test.py
@@ -1,10 +1,9 @@

from __future__ import with_statement
import re
import shlex
import hashlib
import shutil
from devpi_common.archive import Archive
from devpi_common.contextlib import chdir
from devpi_common.metadata import parse_requirement
import json
import sys
Expand Down Expand Up @@ -96,7 +95,7 @@ def runtox(self, link, pkg, sdist_pkg=None, upload_tox_results=True):
toxcmd.extend(self.get_tox_args(unpack_path=sdist_pkg.path_unpacked))

ret = 0
with sdist_pkg.path_unpacked.as_cwd():
with chdir(sdist_pkg.path_unpacked):
try:
self.hub.popen_check(
toxcmd,
Expand Down

0 comments on commit 8488a85

Please sign in to comment.