Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pydantic version 2 #372

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
No more procrunner
  • Loading branch information
stephen-riggs committed Aug 30, 2024
commit ab06896e2f42a439549d04df469b0f29ed0f029e
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ cicd = [
"pytest-cov", # Used by Azure Pipelines for PyTest coverage reports
]
client = [
"procrunner",
"textual==0.42.0",
"websocket-client",
"xmltodict",
4 changes: 2 additions & 2 deletions src/murfey/cli/transfer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import argparse
import subprocess
from pathlib import Path
from urllib.parse import urlparse

import procrunner
import requests
from rich.console import Console
from rich.prompt import Confirm
@@ -78,6 +78,6 @@ def run():
cmd.extend(list(Path(args.source or ".").glob("*")))
cmd.append(f"{murfey_url.hostname}::{args.destination}")

result = procrunner.run(cmd)
result = subprocess.run(cmd)
if result.returncode:
console.print(f"[red]rsync failed returning code {result.returncode}")
33 changes: 16 additions & 17 deletions src/murfey/client/rsync.py
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
from typing import List, NamedTuple
from urllib.parse import ParseResult

import procrunner

from murfey.client.tui.status_bar import StatusBar
from murfey.util import Observer

@@ -408,28 +406,29 @@ def parse_stderr(line: str):
result: subprocess.CompletedProcess | None = None
success = True
if rsync_stdin:
result = procrunner.run(
result = subprocess.run(
rsync_cmd,
callback_stdout=parse_stdout,
callback_stderr=parse_stderr,
working_directory=str(self._basepath),
stdin=rsync_stdin,
print_stdout=False,
print_stderr=False,
cwd=str(self._basepath),
capture_output=True,
input=rsync_stdin,
)
success = result.returncode == 0 if result else False
for stdout_line in result.stdout.decode("utf8", "replace").split("\n"):
parse_stdout(stdout_line)
for stderr_line in result.stderr.decode("utf8", "replace").split("\n"):
parse_stderr(stderr_line)
success = result.returncode == 0

if rsync_stdin_remove:
rsync_cmd.insert(-2, "--remove-source-files")
result = procrunner.run(
result = subprocess.run(
rsync_cmd,
callback_stdout=parse_stdout,
callback_stderr=parse_stderr,
working_directory=str(self._basepath),
stdin=rsync_stdin_remove,
print_stdout=False,
print_stderr=False,
cwd=str(self._basepath),
input=rsync_stdin_remove,
)
for stdout_line in result.stdout.decode("utf8", "replace").split("\n"):
parse_stdout(stdout_line)
for stderr_line in result.stderr.decode("utf8", "replace").split("\n"):
parse_stderr(stderr_line)

if success:
success = result.returncode == 0 if result else False
4 changes: 2 additions & 2 deletions src/murfey/client/tui/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import logging
import subprocess
from datetime import datetime
from functools import partial
from pathlib import Path
from queue import Queue
from typing import Awaitable, Callable, Dict, List, OrderedDict, TypeVar
from urllib.parse import urlparse

import procrunner
import requests
from textual.app import App
from textual.reactive import reactive
@@ -203,7 +203,7 @@ def _start_rsyncer(
if self._environment:
self._environment.default_destinations[source] = destination
if self._environment.gain_ref and visit_path:
gain_rsync = procrunner.run(
gain_rsync = subprocess.run(
[
"rsync",
str(self._environment.gain_ref),
4 changes: 2 additions & 2 deletions src/murfey/client/tui/screens.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

# import contextlib
import logging
import subprocess
from datetime import datetime
from functools import partial
from pathlib import Path
@@ -17,7 +18,6 @@
TypeVar,
)

import procrunner
import requests
from pydantic import BaseModel, ValidationError
from rich.box import SQUARE
@@ -844,7 +844,7 @@ def on_button_pressed(self, event):
if self.app._environment.demo:
log.info(f"Would perform {' '.join(cmd)}")
else:
gain_rsync = procrunner.run(cmd)
gain_rsync = subprocess.run(cmd)
if gain_rsync.returncode:
log.warning(
f"Gain reference file {self._dir_tree._gain_reference} was not successfully transferred to {visit_path}/processing"
23 changes: 10 additions & 13 deletions src/murfey/util/rsync.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import logging
import subprocess
from pathlib import Path
from typing import Callable, Dict, List, Optional, Tuple, Union

import procrunner

from murfey.util import Processor
from murfey.util.file_monitor import Monitor

@@ -32,7 +31,7 @@ def __init__(
self.received_bytes = 0
self.byte_rate: float = 0
self.total_size = 0
self.runner_return: List[procrunner.ReturnObject] = []
self.runner_return: List[subprocess.CompletedProcess] = []
self._root = root
self._sub_structure: Optional[Path] = None
self._notify = notify or (lambda f: None)
@@ -53,7 +52,7 @@ def _run_rsync(
retry: bool = True,
):
"""
Run rsync -v on a list of files using procrunner.
Run rsync -v on a list of files using subprocess run.

:param root: root path of files for transferring; structure below the root is preserved
:type root: pathlib.Path object
@@ -109,11 +108,11 @@ def _single_rsync(
else:
cmd.append(str(self._finaldir / sub_struct) + "/")
self._transferring = True
runner = procrunner.run(
cmd,
callback_stdout=self._parse_rsync_stdout,
callback_stderr=self._parse_rsync_stderr,
)

runner = subprocess.run(cmd, capture_output=True)
self._parse_rsync_stdout(runner.stdout)
self._parse_rsync_stderr(runner.stderr)

self.runner_return.append(runner)
self.failed.extend(root / sub_struct / f for f in self._failed_tmp)
if retry:
@@ -127,8 +126,7 @@ def _parse_rsync_stdout(self, stdout: bytes):
:param stdout: stdout of rsync process
:type stdout: bytes
"""
stringy_stdout = str(stdout)
if stringy_stdout:
for stringy_stdout in stdout.decode("utf8", "replace").split("\n"):
if self._transferring:
if stringy_stdout.startswith("sent"):
self._transferring = False
@@ -165,8 +163,7 @@ def _parse_rsync_stderr(self, stderr: bytes):
:param stderr: stderr of rsync process
:type stderr: bytes
"""
stringy_stderr = str(stderr)
if stringy_stderr:
for stringy_stderr in stderr.decode("utf8", "replace").split("\n"):
if (
stringy_stderr.startswith("rsync: link_stat")
and "failed" in stringy_stderr