perf: 用 autoflake 删除无用依赖

没想到居然能意外地大幅提升启动速度
This commit is contained in:
2026-04-22 06:44:59 +08:00
parent e65db69fc6
commit 7278cba258
38 changed files with 184 additions and 703 deletions

View File

@@ -2,9 +2,9 @@ from time import sleep, perf_counter
print("欢迎使用基本用户界面!")
print("加载配置与上下文... ", end="", flush=True)
_start1 = perf_counter()
_start = perf_counter()
from heurams.context import *
_start_all = perf_counter()
_start = _start_all
from heurams.context import rootdir, workdir, config_var
_end = perf_counter()
print(f"已完成! (耗时: {round(1000 * (_end - _start))}ms)")
@@ -32,14 +32,13 @@ print(f"已完成! (耗时: {round(1000 * (_end - _start))}ms)")
print(f"组件目录: {rootdir}")
print(f"工作目录: {workdir}")
_end1 = perf_counter()
print(f"前置工作共计耗时: {round(1000 * (_end1 - _start1))}ms")
_end_all = perf_counter()
print(f"前置工作共计耗时: {round(1000 * (_end_all - _start_all))}ms")
class HeurAMSApp(App):
TITLE = "潜进"
CSS_PATH = "css/main.tcss"
css_dir = pathlib.Path("css").resolve()
CSS_PATH = rootdir / "interface" / "css" / "main.tcss"
SUB_TITLE = "启发式辅助记忆调度器"
BINDINGS = [
("q", "go_back", "退出"),
@@ -63,24 +62,26 @@ class HeurAMSApp(App):
def on_mount(self) -> None:
self.push_screen("dashboard")
def on_button_pressed(self, event: Button.Pressed) -> None:
pass
# self.exit(event.button.id)
def action_go_back(self) -> None:
quit()
self.exit() # go_back 在最顶层是退出, Screen 会再次定义为返回, 键位都是 q, 免得不一样
def action_do_nothing(self):
self.refresh()
def action_do_nothing(self) -> None: # 用来给没使用/禁用的快捷键占位, 因为 Binding 删除不了
pass
# 移除烦人的 "rich traceback"
# Textual 官方不会管这破事, 写 Rich 写入脑了导致的
# 不知道哪来的自信改标准库的 traceback
# https://github.com/Textualize/textual/discussions/6255
# NOTE: 进行 textual 版本升级时, 确保查看过上游代码, 尤其是 App 的 _exception
# 如果行为变了就把下面的删了 (虽然有 fallback)
def _fatal_error(self):
self._close_messages_no_wait()
raise self._exception
if hasattr(self, "_exception"):
self._close_messages_no_wait()
raise self._exception
super()._fatal_error() # fallback
def panic(self, *args):
self._close_messages_no_wait()
raise self._exception
if hasattr("_exception"):
self._close_messages_no_wait()
raise self._exception
super().panic(*args) # ditto