diff --git a/sandbox/will/basic.py b/sandbox/will/basic.py index d4e583323..47d9b23a6 100644 --- a/sandbox/will/basic.py +++ b/sandbox/will/basic.py @@ -130,7 +130,7 @@ class BasicApp(App, css_path="basic.css"): classes="scrollable", ), table, - Widget(DirectoryTree("~/projects/textual"), id="tree-container"), + Widget(DirectoryTree("~/"), id="tree-container"), Error(), Tweet(TweetBody(), classes="scrollbar-size-custom"), Warning(), diff --git a/src/textual/cli/cli.py b/src/textual/cli/cli.py index 9626d005a..f91df0e78 100644 --- a/src/textual/cli/cli.py +++ b/src/textual/cli/cli.py @@ -1,5 +1,7 @@ from __future__ import annotations +import os +import runpy from typing import cast, TYPE_CHECKING from importlib_metadata import version @@ -57,16 +59,12 @@ def import_app(import_name: str) -> App: lib, _colon, name = import_name.partition(":") if lib.endswith(".py"): - # We're assuming the user wants to load a .py file + path = os.path.abspath(lib) try: - with open(lib) as python_file: - py_code = python_file.read() + global_vars = runpy.run_path(path) except Exception as error: raise AppFail(str(error)) - global_vars: dict[str, object] = {} - exec(py_code, global_vars) - if name: # User has given a name, use that try: