Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VukW committed Feb 23, 2024
1 parent 2c0dd9c commit 2b106ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cli/medperf/ui/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABC, abstractmethod, abstractproperty
from abc import ABC, abstractmethod
from contextlib import contextmanager


Expand Down
35 changes: 18 additions & 17 deletions cli/medperf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
from pexpect import spawn
from datetime import datetime
from pydantic.datetime_parse import parse_datetime
from typing import List
from typing import List, Generator
from colorama import Fore, Style
from pexpect.exceptions import TIMEOUT, EOF
from git import Repo, GitCommandError
import medperf.config as config
from medperf.exceptions import ExecutionError, MedperfException, InvalidEntityError
from medperf.ui.cli import CLI
from medperf.ui.interface import UI


Expand Down Expand Up @@ -247,6 +246,21 @@ def check_line(self, line: str) -> bool:
return False


def _read_new_line_from_proc(proc: spawn) -> Generator[str]:
buffer: list[bytes] = []
new_lines = {'\r', '\n'}
try:
while ch := proc.read(1):

if ch.decode('utf-8', 'ignore') in new_lines:
res = b''.join(buffer).decode('utf-8')
buffer = []
yield res
buffer.append(ch)
except EOF:
yield b''.join(buffer).decode('utf-8')


def combine_proc_sp_text(proc: spawn) -> str:
"""Combines the output of a process and the spinner.
Joins any string captured from the process with the
Expand All @@ -260,20 +274,6 @@ def combine_proc_sp_text(proc: spawn) -> str:
str: all non-carriage-return-ending string captured from proc
"""

def _read_new_line_from_proc(proc):
buffer: list[bytes] = []
new_lines = {'\r', '\n'}
try:
while ch := proc.read(1):

if ch.decode('utf-8', 'ignore') in new_lines:
res = b''.join(buffer).decode('utf-8')
buffer = []
yield res
buffer.append(ch)
except EOF:
yield b''.join(buffer).decode('utf-8')

ui: UI = config.ui
ui_was_interactive = ui.is_interactive
ui.stop_interactive()
Expand All @@ -293,7 +293,6 @@ def _read_new_line_from_proc(proc):
ui.print(f"{Fore.WHITE}{Style.DIM}{line}{Style.RESET_ALL}", nl=False)

logging.debug("MLCube process finished")
return proc_out
except TIMEOUT:
logging.error("Process timed out")
raise ExecutionError("Process timed out")
Expand All @@ -302,6 +301,8 @@ def _read_new_line_from_proc(proc):
if ui_was_interactive:
ui.start_interactive()

return proc_out


def get_folders_hash(paths: List[str]) -> str:
"""Generates a hash for all the contents of the fiven folders. This procedure
Expand Down

0 comments on commit 2b106ea

Please sign in to comment.