From 1720c613e515a09870be27047a7f2b3e244e04b6 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 9 Nov 2022 19:32:35 +0300 Subject: [PATCH] Finish command checking & Reformat --- interactive_runner/assignment.py | 3 ++- interactive_runner/helpers.py | 10 ++++++---- interactive_runner/language.py | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/interactive_runner/assignment.py b/interactive_runner/assignment.py index 962e274..e4a3b3f 100644 --- a/interactive_runner/assignment.py +++ b/interactive_runner/assignment.py @@ -3,9 +3,10 @@ from __future__ import annotations __all__ = ("Assignment",) from functools import cached_property -from toml import loads as decode_toml from typing import TYPE_CHECKING, TypedDict +from toml import loads as decode_toml + from .helpers import command if TYPE_CHECKING: diff --git a/interactive_runner/helpers.py b/interactive_runner/helpers.py index fcbeb10..2b1e3af 100644 --- a/interactive_runner/helpers.py +++ b/interactive_runner/helpers.py @@ -1,13 +1,15 @@ __all__ = ("command", "chalk_from_int", "command_exists") -from subprocess import DEVNULL as NULL, call as sys_command +from subprocess import DEVNULL as NULL, call as sys_command, getstatusoutput as sys_get_out_err from chalky import Chalk, TrueColor +from .constants import OS + def command(s: str, /, *, quiet: bool) -> int: return sys_command( - s.split(" "), **(dict(stdout=NULL, stderr=NULL, stdin=NULL) if quiet else {}) + s.split(" "), shell=True, **(dict(stdout=NULL, stderr=NULL, stdin=NULL) if quiet else {}) ) @@ -26,5 +28,5 @@ def chalk_from_int(foreground: int, background: int = None, /) -> Chalk: def command_exists(s: str, /) -> bool: - """TODO""" - return False + prefix = "Get-Command" if OS == "windows" else "command -v" + return sys_get_out_err(f"{prefix} {s}")[0] == 0 diff --git a/interactive_runner/language.py b/interactive_runner/language.py index 3c3644d..90b18c0 100644 --- a/interactive_runner/language.py +++ b/interactive_runner/language.py @@ -3,9 +3,10 @@ from __future__ import annotations __all__ = ("Language",) from functools import cached_property -from toml import loads as decode_toml from typing import TYPE_CHECKING, TypedDict +from toml import loads as decode_toml + from .assignment import Assignment from .constants import OS from .helpers import chalk_from_int, command_exists