summaryrefslogtreecommitdiffstats
path: root/ptpython/entry_points/run_ptpython.py
diff options
context:
space:
mode:
Diffstat (limited to 'ptpython/entry_points/run_ptpython.py')
-rw-r--r--ptpython/entry_points/run_ptpython.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/ptpython/entry_points/run_ptpython.py b/ptpython/entry_points/run_ptpython.py
index 1b4074d..1d4a532 100644
--- a/ptpython/entry_points/run_ptpython.py
+++ b/ptpython/entry_points/run_ptpython.py
@@ -9,6 +9,7 @@ optional arguments:
-h, --help show this help message and exit
--vi Enable Vi key bindings
-i, --interactive Start interactive shell after executing this file.
+ --asyncio Run an asyncio event loop to support top-level "await".
--light-bg Run on a light background (use dark colors for text).
--dark-bg Run on a dark background (use light colors for text).
--config-file CONFIG_FILE
@@ -24,11 +25,12 @@ environment variables:
from __future__ import annotations
import argparse
+import asyncio
import os
import pathlib
import sys
from textwrap import dedent
-from typing import IO, Optional, Tuple
+from typing import IO
import appdirs
from prompt_toolkit.formatted_text import HTML
@@ -69,15 +71,20 @@ def create_parser() -> _Parser:
help="Start interactive shell after executing this file.",
)
parser.add_argument(
+ "--asyncio",
+ action="store_true",
+ help='Run an asyncio event loop to support top-level "await".',
+ )
+ parser.add_argument(
"--light-bg",
action="store_true",
help="Run on a light background (use dark colors for text).",
- ),
+ )
parser.add_argument(
"--dark-bg",
action="store_true",
help="Run on a dark background (use light colors for text).",
- ),
+ )
parser.add_argument(
"--config-file", type=str, help="Location of configuration file."
)
@@ -206,7 +213,7 @@ def run() -> None:
import __main__
- embed(
+ embed_result = embed( # type: ignore
vi_mode=a.vi,
history_filename=history_file,
configure=configure,
@@ -214,8 +221,14 @@ def run() -> None:
globals=__main__.__dict__,
startup_paths=startup_paths,
title="Python REPL (ptpython)",
+ return_asyncio_coroutine=a.asyncio,
)
+ if a.asyncio:
+ print("Starting ptpython asyncio REPL")
+ print('Use "await" directly instead of "asyncio.run()".')
+ asyncio.run(embed_result)
+
if __name__ == "__main__":
run()