Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:
priority: 3
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
- repo: https://github.com/gaborbernat/simplint-pre-commit
rev: 5f12b15e1199c42bdeb3e13ea1c8b45952fbd802 # frozen: v0.11.0
rev: 36f74b836f184e20c3660656572d7f5b58f3e904 # frozen: v0.12.0
hooks:
- id: simplint
priority: 4
Expand Down
24 changes: 10 additions & 14 deletions src/devpi_process/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Devpi PyPI to test with."""
"""Devpi PyPI to test with.""" # simplint: ignore[unused-dependency] # Provide the devpi commands it runs.

from __future__ import annotations

Expand Down Expand Up @@ -101,19 +101,12 @@ def __init__(
if scripts_dir is None:
msg = "could not get scripts folder of host interpreter"
raise RuntimeError(msg)

def _exe(name: str) -> str:
return str(Path(scripts_dir) / f"{name}{'.exe' if sys.platform == 'win32' else ''}")

self._init: str = _exe("devpi-init")
self._server: str = _exe("devpi-server")
self._client: str = _exe("devpi")
self._scripts = Path(scripts_dir)

self._server_dir = self.path / "server"
self._client_dir = self.path / "client"
self._indexes: dict[str, Index] = {}
self._process: Popen[str] | None = None
self._has_use = False
self._stdout_drain: Thread | None = None

def __enter__(self) -> Self:
Expand All @@ -130,13 +123,13 @@ def _create_and_start_server(self) -> None:
self._server_dir.mkdir(exist_ok=True)
server_at = str(self._server_dir)
# 1. create the server
cmd = [self._init, "--serverdir", server_at]
cmd = [self._exe("devpi-init"), "--serverdir", server_at]
cmd.extend(("--role", "standalone", "--root-passwd", self._passwd))
if self._with_root_pypi is False:
cmd.append("--no-root-pypi")
_check_call(cmd)
# 2. start the server
cmd = [self._server, "--serverdir", server_at, "--port", str(self.port)]
cmd = [self._exe("devpi-server"), "--serverdir", server_at, "--port", str(self.port)]
cmd.extend(self._start_args)
self._process = Popen(cmd, stdout=PIPE, universal_newlines=True) # ruff:ignore[subprocess-without-shell-equals-true] # no shell, argument list only
stdout = self._drain_stdout()
Expand All @@ -155,6 +148,9 @@ def _keep_draining() -> None:
msg = f"devpi server at {self._server_dir} exited before it was ready"
raise RuntimeError(msg)

def _exe(self, name: str) -> str:
return str(self._scripts / f"{name}{'.exe' if sys.platform == 'win32' else ''}")

def _drain_stdout(self) -> Iterator[str]:
process = cast("Popen[str]", self._process)
stdout = cast("IO[str]", process.stdout)
Expand All @@ -167,8 +163,8 @@ def _drain_stdout(self) -> Iterator[str]:
def _setup_client(self) -> None:
self._client_dir.mkdir(exist_ok=True)
base = ["--clientdir", str(self._client_dir)]
_check_call([self._client, "use", *base, self.url])
_check_call([self._client, "login", *base, self.user, "--password", self._passwd])
_check_call([self._exe("devpi"), "use", *base, self.url])
_check_call([self._exe("devpi"), "login", *base, self.user, "--password", self._passwd])

@property
def url(self) -> str:
Expand Down Expand Up @@ -214,7 +210,7 @@ def create_index(self, name: str, *args: str) -> Index:
if name in self._indexes:
msg = f"index {name} already exists"
raise ValueError(msg)
base = [self._client, "--clientdir", str(self._client_dir)]
base = [self._exe("devpi"), "--clientdir", str(self._client_dir)]
_check_call([*base, "index", "-c", name, *args])
index = Index(f"{self.url}/{self.user}", name, self.user, base)
self._indexes[name] = index
Expand Down
5 changes: 3 additions & 2 deletions tests/demo_pkg_inline/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from io import BytesIO
from pathlib import Path
from textwrap import dedent
from types import MappingProxyType
from typing import Final
from zipfile import ZipFile

Expand All @@ -17,7 +18,7 @@
_METADATA: Final[str] = f"{_DIST_INFO}/METADATA"
_WHEEL: Final[str] = f"{_DIST_INFO}/WHEEL"
_RECORD: Final[str] = f"{_DIST_INFO}/RECORD"
_CONTENT: Final[dict[str, str]] = {
_CONTENT: Final[MappingProxyType[str, str]] = MappingProxyType({
_LOGIC: f"def do():\n print('greetings from {_NAME}')",
_METADATA: f"""
Metadata-Version: 2.1
Expand Down Expand Up @@ -46,7 +47,7 @@
{_DIST_INFO}/top_level.txt,,
{_DIST_INFO}/RECORD,,
""",
}
})


def build_wheel(
Expand Down