mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
pass through unprocessed args (#2374)
* pass through unprocesses args * omit symbols * extract args * posix exception * timer updates * another update * just work on windows damn it * remove updates
This commit is contained in:
@@ -109,12 +109,12 @@ def resolve_box_models(
|
||||
box_models: list[BoxModel | None] = [
|
||||
(
|
||||
None
|
||||
if dimension is not None and dimension.is_fraction
|
||||
if _dimension is not None and _dimension.is_fraction
|
||||
else widget._get_box_model(
|
||||
size, viewport_size, fraction_width, fraction_height
|
||||
)
|
||||
)
|
||||
for (dimension, widget) in zip(dimensions, widgets)
|
||||
for (_dimension, widget) in zip(dimensions, widgets)
|
||||
]
|
||||
|
||||
if dimension == "width":
|
||||
|
||||
@@ -2,7 +2,7 @@ from asyncio import sleep
|
||||
from time import monotonic, process_time
|
||||
|
||||
SLEEP_GRANULARITY: float = 1 / 50
|
||||
SLEEP_IDLE: float = SLEEP_GRANULARITY / 10.0
|
||||
SLEEP_IDLE: float = SLEEP_GRANULARITY / 20.0
|
||||
|
||||
|
||||
async def wait_for_idle(
|
||||
|
||||
@@ -10,14 +10,9 @@ from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import os
|
||||
import platform
|
||||
import shlex
|
||||
import sys
|
||||
from string import Template
|
||||
from typing import NoReturn
|
||||
|
||||
WINDOWS = platform.system() == "Windows"
|
||||
"""True if we're running on Windows."""
|
||||
from typing import NoReturn, Sequence
|
||||
|
||||
EXEC_SCRIPT = Template(
|
||||
"""\
|
||||
@@ -38,7 +33,9 @@ class ExecImportError(Exception):
|
||||
"""Raised if a Python import is invalid."""
|
||||
|
||||
|
||||
def run_app(command_args: str, environment: dict[str, str] | None = None) -> None:
|
||||
def run_app(
|
||||
import_name: str, args: Sequence[str], environment: dict[str, str] | None = None
|
||||
) -> None:
|
||||
"""Run a textual app.
|
||||
|
||||
Note:
|
||||
@@ -48,7 +45,6 @@ def run_app(command_args: str, environment: dict[str, str] | None = None) -> Non
|
||||
command_args: Arguments to pass to the Textual app.
|
||||
environment: Environment variables, or None to use current process.
|
||||
"""
|
||||
import_name, *args = shlex.split(command_args, posix=not WINDOWS)
|
||||
if environment is None:
|
||||
app_environment = dict(os.environ)
|
||||
else:
|
||||
@@ -91,7 +87,7 @@ def _flush() -> None:
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def exec_python(args: list[str], environment: dict[str, str]) -> NoReturn:
|
||||
def exec_python(args: Sequence[str], environment: dict[str, str]) -> NoReturn:
|
||||
"""Execute a Python script.
|
||||
|
||||
Args:
|
||||
@@ -102,7 +98,9 @@ def exec_python(args: list[str], environment: dict[str, str]) -> NoReturn:
|
||||
os.execvpe(sys.executable, ["python", *args], environment)
|
||||
|
||||
|
||||
def exec_command(command: str, environment: dict[str, str]) -> NoReturn:
|
||||
def exec_command(
|
||||
command: str, args: Sequence[str], environment: dict[str, str]
|
||||
) -> NoReturn:
|
||||
"""Execute a command with the given environment.
|
||||
|
||||
Args:
|
||||
@@ -110,7 +108,6 @@ def exec_command(command: str, environment: dict[str, str]) -> NoReturn:
|
||||
environment: Environment variables.
|
||||
"""
|
||||
_flush()
|
||||
command, *args = shlex.split(command, posix=not WINDOWS)
|
||||
os.execvpe(command, [command, *args], environment)
|
||||
|
||||
|
||||
@@ -134,7 +131,7 @@ def check_import(module_name: str, app_name: str) -> bool:
|
||||
|
||||
|
||||
def exec_import(
|
||||
import_name: str, args: list[str], environment: dict[str, str]
|
||||
import_name: str, args: Sequence[str], environment: dict[str, str]
|
||||
) -> NoReturn:
|
||||
"""Import and execute an app.
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import platform
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
from ..constants import DEVTOOLS_PORT
|
||||
@@ -13,6 +15,9 @@ except ImportError:
|
||||
|
||||
from importlib_metadata import version
|
||||
|
||||
WINDOWS = platform.system() == "Windows"
|
||||
"""True if we're running on Windows."""
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version("textual"))
|
||||
@@ -129,12 +134,14 @@ def _pre_run_warnings() -> None:
|
||||
help="Show any return value on exit.",
|
||||
is_flag=True,
|
||||
)
|
||||
@click.argument("extra_args", nargs=-1, type=click.UNPROCESSED)
|
||||
def _run_app(
|
||||
import_name: str,
|
||||
dev: bool,
|
||||
port: int | None,
|
||||
press: str | None,
|
||||
screenshot: int | None,
|
||||
extra_args: tuple[str],
|
||||
command: bool = False,
|
||||
show_return: bool = False,
|
||||
) -> None:
|
||||
@@ -154,14 +161,14 @@ def _run_app(
|
||||
|
||||
textual run module.foo:MyApp
|
||||
|
||||
If you are running a file and want to pass command line arguments, wrap the filename and arguments
|
||||
in quotes:
|
||||
Add the --dev switch to enable the textual console.
|
||||
|
||||
textual run "foo.py arg --option"
|
||||
textual run --dev foo.py
|
||||
|
||||
Use the -c switch to run a command that launches a Textual app.
|
||||
|
||||
textual run -c "textual colors"
|
||||
textual run -c textual colors
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
@@ -187,10 +194,12 @@ def _run_app(
|
||||
|
||||
_pre_run_warnings()
|
||||
|
||||
import_name, *args = [*shlex.split(import_name, posix=not WINDOWS), *extra_args]
|
||||
|
||||
if command:
|
||||
exec_command(import_name, environment)
|
||||
exec_command(import_name, args, environment)
|
||||
else:
|
||||
run_app(import_name, environment)
|
||||
run_app(import_name, args, environment)
|
||||
|
||||
|
||||
@run.command("borders")
|
||||
|
||||
Reference in New Issue
Block a user