diff --git a/aprendizations/tools.py b/aprendizations/tools.py index 77fca0e..d40fded 100644 --- a/aprendizations/tools.py +++ b/aprendizations/tools.py @@ -20,11 +20,6 @@ logger = logging.getLogger(__name__) # ------------------------------------------------------------------------- -# Markdown to HTML renderer with support for LaTeX equations -# ------------------------------------------------------------------------- - - -# ------------------------------------------------------------------------- # Block math: # $$x$$ or \begin{equation}x\end{equation} # ------------------------------------------------------------------------- @@ -172,43 +167,48 @@ def load_yaml(filename: str, default: Any = None) -> Any: # The script is run in another process but this function blocks waiting # for its termination. # --------------------------------------------------------------------------- -def run_script(script: str, - args: List[str] = [], - stdin: str = '', - timeout: int = 2) -> Any: - - script = path.expanduser(script) - try: - cmd = [script] + [str(a) for a in args] - p = subprocess.run(cmd, - input=stdin, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - text=True, # same as universal_newlines=True - timeout=timeout, - ) - except FileNotFoundError: - logger.error(f'Can not execute script "{script}": not found.') - except PermissionError: - logger.error(f'Can not execute script "{script}": wrong permissions.') - except OSError: - logger.error(f'Can not execute script "{script}": unknown reason.') - except subprocess.TimeoutExpired: - logger.error(f'Timeout {timeout}s exceeded while running "{script}".') - except Exception: - logger.error(f'An Exception ocurred running {script}.') - else: - if p.returncode != 0: - logger.error(f'Return code {p.returncode} running "{script}".') - else: - try: - output = yaml.safe_load(p.stdout) - except Exception: - logger.error(f'Error parsing yaml output of "{script}"') - else: - return output - - +# def run_script(script: str, +# args: List[str] = [], +# stdin: str = '', +# timeout: int = 2) -> Any: +# +# script = path.expanduser(script) +# try: +# cmd = [script] + [str(a) for a in args] +# p = subprocess.run(cmd, +# input=stdin, +# stdout=subprocess.PIPE, +# stderr=subprocess.STDOUT, +# text=True, # same as universal_newlines=True +# timeout=timeout, +# ) +# except FileNotFoundError: +# logger.error(f'Can not execute script "{script}": not found.') +# except PermissionError: +# logger.error(f'Can not execute script "{script}": wrong permissions.') +# except OSError: +# logger.error(f'Can not execute script "{script}": unknown reason.') +# except subprocess.TimeoutExpired: +# logger.error(f'Timeout {timeout}s exceeded while running "{script}".') +# except Exception: +# logger.error(f'An Exception ocurred running {script}.') +# else: +# if p.returncode != 0: +# logger.error(f'Return code {p.returncode} running "{script}".') +# else: +# try: +# output = yaml.safe_load(p.stdout) +# except Exception: +# logger.error(f'Error parsing yaml output of "{script}"') +# else: +# return output +# + +# def run_script(script: str, +# args: List[str] = [], +# stdin: str = '', +# timeout: int = 2) -> Any: +# asyncio.run(run_script_async(script, args, stdin, timeout)) # ---------------------------------------------------------------------------- # Same as above, but asynchronous # ---------------------------------------------------------------------------- -- libgit2 0.21.2