fix run on Windows

This commit is contained in:
Will McGugan
2023-04-28 20:29:21 -07:00
parent c5053eca81
commit ecee8ef837

View File

@@ -8,12 +8,16 @@ This means that (if they succeed) they will never return.
from __future__ import annotations from __future__ import annotations
import importlib
import os import os
import sys import sys
import platform
from string import Template from string import Template
import subprocess
from typing import NoReturn, Sequence from typing import NoReturn, Sequence
WINDOWS = platform.system() == "Windows"
EXEC_SCRIPT = Template( EXEC_SCRIPT = Template(
"""\ """\
from textual.app import App from textual.app import App
@@ -91,7 +95,7 @@ def _flush() -> None:
sys.stdout.flush() sys.stdout.flush()
def exec_python(args: Sequence[str], environment: dict[str, str]) -> NoReturn: def exec_python(args: Sequence[str], environment: dict[str, str]) -> None:
"""Execute a Python script. """Execute a Python script.
Args: Args:
@@ -99,12 +103,15 @@ def exec_python(args: Sequence[str], environment: dict[str, str]) -> NoReturn:
environment: Environment variables. environment: Environment variables.
""" """
_flush() _flush()
os.execvpe(sys.executable, ["python", *args], environment) if WINDOWS:
subprocess.call([sys.executable, *args], env=environment)
else:
os.execvpe(sys.executable, ["python", *args], environment)
def exec_command( def exec_command(
command: str, args: Sequence[str], environment: dict[str, str] command: str, args: Sequence[str], environment: dict[str, str]
) -> NoReturn: ) -> None:
"""Execute a command with the given environment. """Execute a command with the given environment.
Args: Args:
@@ -112,7 +119,10 @@ def exec_command(
environment: Environment variables. environment: Environment variables.
""" """
_flush() _flush()
os.execvpe(command, [command, *args], environment) if WINDOWS:
subprocess.call([command, *args], env=environment)
else:
os.execvpe(command, [command, *args], environment)
def exec_import( def exec_import(