aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/backend/proc.py
diff options
context:
space:
mode:
authorDmitrii Agibov <dmitrii.agibov@arm.com>2022-09-08 14:24:39 +0100
committerDmitrii Agibov <dmitrii.agibov@arm.com>2022-09-09 17:21:48 +0100
commitf5b293d0927506c2a979a091bf0d07ecc78fa181 (patch)
tree4de585b7cb6ed34da8237063752270189a730a41 /src/mlia/backend/proc.py
parentcde0c6ee140bd108849bff40467d8f18ffc332ef (diff)
downloadmlia-f5b293d0927506c2a979a091bf0d07ecc78fa181.tar.gz
MLIA-386 Simplify typing in the source code
- Enable deferred annotations evaluation - Use builtin types for type hints whenever possible - Use | syntax for union types - Rename mlia.core._typing into mlia.core.typing Change-Id: I3f6ffc02fa069c589bdd9e8bddbccd504285427a
Diffstat (limited to 'src/mlia/backend/proc.py')
-rw-r--r--src/mlia/backend/proc.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/mlia/backend/proc.py b/src/mlia/backend/proc.py
index 911d672..7b3e92a 100644
--- a/src/mlia/backend/proc.py
+++ b/src/mlia/backend/proc.py
@@ -5,6 +5,8 @@
This module contains all classes and functions for dealing with Linux
processes.
"""
+from __future__ import annotations
+
import datetime
import logging
import shlex
@@ -13,9 +15,6 @@ import tempfile
import time
from pathlib import Path
from typing import Any
-from typing import List
-from typing import Optional
-from typing import Tuple
from sh import Command
from sh import CommandNotFound
@@ -38,12 +37,12 @@ class ShellCommand:
self,
cmd: str,
*args: str,
- _cwd: Optional[Path] = None,
+ _cwd: Path | None = None,
_tee: bool = True,
_bg: bool = True,
_out: Any = None,
_err: Any = None,
- _search_paths: Optional[List[Path]] = None,
+ _search_paths: list[Path] | None = None,
) -> RunningCommand:
"""Run the shell command with the given arguments.
@@ -72,7 +71,7 @@ class ShellCommand:
return command(_out=out, _err=err, _tee=_tee, _bg=_bg, _bg_exc=False)
@classmethod
- def get_stdout_stderr_paths(cls, cmd: str) -> Tuple[Path, Path]:
+ def get_stdout_stderr_paths(cls, cmd: str) -> tuple[Path, Path]:
"""Construct and returns the paths of stdout/stderr files."""
timestamp = datetime.datetime.now().timestamp()
base_path = Path(tempfile.mkdtemp(prefix="mlia-", suffix=f"{timestamp}"))
@@ -88,7 +87,7 @@ class ShellCommand:
return stdout, stderr
-def parse_command(command: str, shell: str = "bash") -> List[str]:
+def parse_command(command: str, shell: str = "bash") -> list[str]:
"""Parse command."""
cmd, *args = shlex.split(command, posix=True)
@@ -130,13 +129,13 @@ def run_and_wait(
terminate_on_error: bool = False,
out: Any = None,
err: Any = None,
-) -> Tuple[int, bytearray, bytearray]:
+) -> tuple[int, bytearray, bytearray]:
"""
Run command and wait while it is executing.
Returns a tuple: (exit_code, stdout, stderr)
"""
- running_cmd: Optional[RunningCommand] = None
+ running_cmd: RunningCommand | None = None
try:
running_cmd = execute_command(command, cwd, bg=True, out=out, err=err)
return running_cmd.exit_code, running_cmd.stdout, running_cmd.stderr