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.
|
||||
|
||||
Reference in New Issue
Block a user