v0.166.0
 1import sys
 2from pathlib import Path
 3
 4from plain.cli.runtime import get_running_command
 5
 6
 7def has_pyproject_toml(target_path: str | Path) -> bool:
 8    return (Path(target_path) / "pyproject.toml").exists()
 9
10
11def running_command() -> str | None:
12    """
13    The top-level `plain` command this process is running. None for a bare
14    `plain` or `plain --help`.
15
16    Whoever started the command says which it is: the `plain` CLI when it
17    dispatches one, and `python -m plain.testing` for itself, where the arguments
18    name test targets and not a command. A process nobody told (a server
19    worker, a script that calls `setup()`) is read from its arguments.
20
21    Only the top-level command, so `plain docs testing` isn't taken for
22    `plain test`.
23    """
24    told = get_running_command()
25    if told is not None:
26        return told
27
28    arguments = [a for a in sys.argv[1:] if not a.startswith("-")]
29    if not arguments:
30        return None
31    return arguments[0]