Add directory of file to run to sys path (#947)

This commit is contained in:
darrenburns
2022-10-18 15:16:46 +01:00
committed by GitHub
parent 417d6e2d33
commit 0f31cc4e45
4 changed files with 8 additions and 8 deletions

View File

@@ -3,6 +3,8 @@ from textual.binding import Binding
from textual.screen import Screen
from textual.widgets import Static, Footer, Input
from some_text import TEXT
class Focusable(Static, can_focus=True):
pass
@@ -10,11 +12,11 @@ class Focusable(Static, can_focus=True):
class CustomScreen(Screen):
def compose(self) -> ComposeResult:
yield Focusable(f"Screen {id(self)} - two")
yield Focusable(f"Screen {id(self)} - two {TEXT}")
yield Focusable(f"Screen {id(self)} - three")
yield Focusable(f"Screen {id(self)} - four")
yield Input(placeholder="Text input")
yield Footer()
# yield Footer()
class ScreensFocusApp(App):
@@ -30,7 +32,7 @@ class ScreensFocusApp(App):
yield Focusable("App - two")
yield Focusable("App - three")
yield Focusable("App - four")
yield Footer()
# yield Footer()
def action_push_new_screen(self):
self.push_screen(CustomScreen())

View File

@@ -0,0 +1 @@
TEXT = "ABCDEFG"

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
import os
import runpy
import shlex
from pathlib import Path
from typing import cast, TYPE_CHECKING
@@ -38,6 +39,7 @@ def import_app(import_name: str) -> App:
if lib.endswith(".py"):
path = os.path.abspath(lib)
sys.path.append(str(Path(path).parent))
try:
global_vars = runpy.run_path(path, {})
except Exception as error:

View File

@@ -1,15 +1,10 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import click
from importlib_metadata import version
from textual.devtools.server import _run_devtools
from textual._import_app import import_app, AppFail
if TYPE_CHECKING:
from textual.app import App
@click.group()
@click.version_option(version("textual"))