Skip to content

Commit

Permalink
Show stdout/stderr if fails call
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Dec 3, 2022
1 parent d672220 commit 5bdc4b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3 (2021-12-03)

- Show stdout/stderr details if a command fails

## 0.2 (2021-12-29)

- Drop 3.6 support and bump linters
Expand Down
18 changes: 11 additions & 7 deletions src/devpi_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
import sysconfig
from contextlib import closing
from pathlib import Path
from subprocess import PIPE, Popen, check_call
from subprocess import PIPE, Popen, run
from threading import Thread
from types import TracebackType
from typing import IO, Iterator, Sequence, cast

from .version import __version__


def _check_call(cmd: list[str]) -> None:
run(cmd, check=True, stdout=PIPE, stderr=PIPE)


class Index:
def __init__(self, base_url: str, name: str, user: str, client_cmd_base: list[str]) -> None:
self._client_cmd_base = client_cmd_base
Expand All @@ -27,11 +31,11 @@ def url(self) -> str:
return f"{self._server_url}/{self.name}/+simple/"

def use(self) -> None:
check_call(self._client_cmd_base + ["use", f"{self.user}/{self.name}"], stdout=PIPE, stderr=PIPE)
_check_call(self._client_cmd_base + ["use", f"{self.user}/{self.name}"])

def upload(self, *files: Path) -> None:
cmd = self._client_cmd_base + ["upload", "--index", self.name] + [str(i) for i in files]
check_call(cmd)
_check_call(cmd)

def __repr__(self) -> str:
return f"{self.__class__.__name__}(url={self.url})"
Expand Down Expand Up @@ -81,7 +85,7 @@ def _create_and_start_server(self) -> None:
cmd.extend(("--role", "standalone", "--root-passwd", self._passwd))
if self._with_root_pypi is False:
cmd.append("--no-root-pypi")
check_call(cmd, stdout=PIPE, stderr=PIPE)
_check_call(cmd)
# 2. start the server
cmd = [self._server, "--serverdir", server_at, "--port", str(self.port)]
cmd.extend(self._start_args)
Expand Down Expand Up @@ -112,14 +116,14 @@ def _setup_client(self) -> None:
"""create a user on the server and authenticate it"""
self._client_dir.mkdir(exist_ok=True)
base = ["--clientdir", str(self._client_dir)]
check_call([self._client, "use"] + base + [self.url], stdout=PIPE, stderr=PIPE)
check_call([self._client, "login"] + base + [self.user, "--password", self._passwd], stdout=PIPE, stderr=PIPE)
_check_call([self._client, "use"] + base + [self.url])
_check_call([self._client, "login"] + base + [self.user, "--password", self._passwd])

def create_index(self, name: str, *args: str) -> Index:
if name in self._indexes: # pragma: no cover
raise ValueError(f"index {name} already exists")
base = [self._client, "--clientdir", str(self._client_dir)]
check_call(base + ["index", "-c", name, *args], stdout=PIPE, stderr=PIPE)
_check_call(base + ["index", "-c", name, *args])
index = Index(f"{self.url}/{self.user}", name, self.user, base)
self._indexes[name] = index
return index
Expand Down
7 changes: 0 additions & 7 deletions whitelist.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
addfile
cmd
devpi
dirname
exc
exe
getsockname
inet
mktemp
popen
readline
sdist
sysconfig
tmp
tmpdir
util
writestr

0 comments on commit 5bdc4b5

Please sign in to comment.