diff --git a/cli/medperf/__main__.py b/cli/medperf/__main__.py index db7c3dbfa..5a7955622 100644 --- a/cli/medperf/__main__.py +++ b/cli/medperf/__main__.py @@ -19,6 +19,7 @@ import medperf.commands.profile as profile from medperf.utils import ( set_custom_config, + validate_config, set_unique_tmp_config, init_storage, setup_logging, @@ -100,6 +101,8 @@ def main( # Set inline parameters inline_args = ctx.params set_custom_config(inline_args) + validate_config() + set_unique_tmp_config() init_storage() diff --git a/cli/medperf/entities/cube.py b/cli/medperf/entities/cube.py index 13da6d20f..e5d71d47e 100644 --- a/cli/medperf/entities/cube.py +++ b/cli/medperf/entities/cube.py @@ -1,11 +1,16 @@ import os +import sys import yaml -import pexpect import logging from typing import List, Dict, Optional, Union from pydantic import Field from pathlib import Path +if sys.platform == "win32": + import wexpect as pexpect +else: + import pexpect + from medperf.utils import combine_proc_sp_text, list_files, storage_path, verify_hash from medperf.entities.interface import Entity, Uploadable from medperf.entities.schemas import MedperfSchema, DeployableSchema @@ -283,7 +288,7 @@ def run( proc_out = combine_proc_sp_text(proc) proc.close() logging.debug(proc_out) - if proc.exitstatus != 0: + if proc.exitstatus: raise ExecutionError("There was an error while executing the cube") logging.debug(list_files(config.storage)) diff --git a/cli/medperf/utils.py b/cli/medperf/utils.py index ffe246f00..7b05f0b77 100644 --- a/cli/medperf/utils.py +++ b/cli/medperf/utils.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys import re import os import yaml @@ -14,12 +15,16 @@ import json from pathlib import Path import shutil -from pexpect import spawn from datetime import datetime from typing import List from colorama import Fore, Style from pexpect.exceptions import TIMEOUT +if sys.platform == "win32": + from wexpect import spawn +else: + from pexpect import spawn + import medperf.config as config from medperf.logging.filters.redacting_filter import RedactingFilter from medperf.exceptions import ExecutionError, MedperfException, InvalidEntityError @@ -28,7 +33,7 @@ def setup_logging(log_lvl): log_fmt = "%(asctime)s | %(levelname)s: %(message)s" log_file = storage_path(config.log_file) - handler = handlers.RotatingFileHandler(log_file, backupCount=20) + handler = handlers.RotatingFileHandler(log_file, backupCount=20, encoding="utf-8") handler.setFormatter(logging.Formatter(log_fmt)) logging.basicConfig( level=log_lvl, @@ -82,6 +87,13 @@ def set_custom_config(args: dict): setattr(config, param, val) +def validate_config(): + """Validates the configuration is valid for the current machine""" + if config.platform == "singularity" and sys.platform == "win32": + raise MedperfException("Windows doesn't support singularity runner") + # Add additional checks here + + def storage_path(subpath: str): """Helper function that converts a path to deployment storage-related path""" server_path = config.server.split("//")[1] @@ -372,7 +384,8 @@ def combine_proc_sp_text(proc: spawn) -> str: except TIMEOUT: logging.error("Process timed out") raise ExecutionError("Process timed out") - line = line.decode("utf-8", "ignore") + if line is not None and not isinstance(line, str): + line = line.decode("utf-8", "ignore") if line: proc_out += line ui.print(f"{Fore.WHITE}{Style.DIM}{line.strip()}{Style.RESET_ALL}") diff --git a/cli/requirements.txt b/cli/requirements.txt index e5af407b9..1c2f9c799 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -1,4 +1,5 @@ -typer~=0.6.0 +typer~=0.6.0; sys_platform != "win32" +typer<0.5.0; sys_platform == "win32" rich~=12.5.0 PyYAML>=5.4,<6 requests>=2.26.0 @@ -6,13 +7,14 @@ pydantic==1.10.2 yaspin==2.1.0 tabulate==0.8.9 pexpect==4.8.0 +wexpect==4.0.0; sys_platform == "win32" colorama==0.4.4 time-machine==2.4.0 pytest-mock==1.13.0 pyfakefs==5.0.0 mlcube @ git+https://github.com/mlcommons/mlcube@fb371c960938b495e939bf38b161199d529cf912#subdirectory=mlcube mlcube-docker @ git+https://github.com/mlcommons/mlcube@fb371c960938b495e939bf38b161199d529cf912#subdirectory=runners/mlcube_docker -mlcube-singularity @ git+https://github.com/mlcommons/mlcube@fb371c960938b495e939bf38b161199d529cf912#subdirectory=runners/mlcube_singularity +mlcube-singularity @ git+https://github.com/mlcommons/mlcube@fb371c960938b495e939bf38b161199d529cf912#subdirectory=runners/mlcube_singularity ; sys_platform != "win32" validators==0.18.2 merge-args==0.1.4 synapseclient==2.7.0