fix clip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from importlib import import_module
|
||||
import sys
|
||||
from importlib import import_module, reload as reload_module
|
||||
from types import ModuleType
|
||||
from typing import Any, Dict, List, Optional
|
||||
import logging
|
||||
@@ -68,7 +69,7 @@ def _normalize_mod_name(mod_name: str) -> str:
|
||||
return normalized
|
||||
|
||||
|
||||
def import_cmd_module(mod_name: str):
|
||||
def import_cmd_module(mod_name: str, *, reload_loaded: bool = False):
|
||||
"""Import a cmdlet/native module from cmdnat or cmdlet packages."""
|
||||
normalized = _normalize_mod_name(mod_name)
|
||||
if not normalized:
|
||||
@@ -81,12 +82,16 @@ def import_cmd_module(mod_name: str):
|
||||
# OSError if system libmpv is missing.
|
||||
if package is None and normalized == "mpv":
|
||||
try:
|
||||
if reload_loaded and "MPV" in sys.modules:
|
||||
return reload_module(sys.modules["MPV"])
|
||||
return import_module("MPV")
|
||||
except ModuleNotFoundError:
|
||||
# Local MPV package not present; fall back to the normal bare import.
|
||||
pass
|
||||
|
||||
qualified = f"{package}.{normalized}" if package else normalized
|
||||
if reload_loaded and qualified in sys.modules:
|
||||
return reload_module(sys.modules[qualified])
|
||||
return import_module(qualified)
|
||||
except ModuleNotFoundError:
|
||||
# Module not available in this package prefix; try the next.
|
||||
|
||||
@@ -2944,6 +2944,29 @@ class PipelineExecutor:
|
||||
continue
|
||||
|
||||
cmd_fn = REGISTRY.get(cmd_name)
|
||||
try:
|
||||
mod = import_cmd_module(cmd_name, reload_loaded=True)
|
||||
data = getattr(mod, "CMDLET", None) if mod else None
|
||||
if data and hasattr(data, "exec") and callable(getattr(data, "exec")):
|
||||
run_fn = getattr(data, "exec")
|
||||
registered_names = set()
|
||||
raw_name = getattr(data, "name", None)
|
||||
if raw_name:
|
||||
registered_names.add(str(raw_name).replace("_", "-").lower())
|
||||
registered_names.add(str(cmd_name).replace("_", "-").lower())
|
||||
for alias_attr in ("alias", "aliases"):
|
||||
alias_values = getattr(data, alias_attr, None)
|
||||
if alias_values:
|
||||
for alias in alias_values:
|
||||
alias_text = str(alias or "").replace("_", "-").lower().strip()
|
||||
if alias_text:
|
||||
registered_names.add(alias_text)
|
||||
for registered_name in registered_names:
|
||||
REGISTRY[registered_name] = run_fn
|
||||
cmd_fn = run_fn
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not cmd_fn:
|
||||
try:
|
||||
mod = import_cmd_module(cmd_name)
|
||||
|
||||
Reference in New Issue
Block a user