mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
Merge pull request #5564 from DDSRem-Dev/dev
This commit is contained in:
@@ -777,9 +777,7 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
|||||||
:return: 远程入口地址
|
:return: 远程入口地址
|
||||||
"""
|
"""
|
||||||
dist_path = dist_path.strip("/")
|
dist_path = dist_path.strip("/")
|
||||||
api_prefix = settings.API_V1_STR.rstrip("/")
|
|
||||||
path = posixpath.join(
|
path = posixpath.join(
|
||||||
api_prefix,
|
|
||||||
"plugin",
|
"plugin",
|
||||||
"file",
|
"file",
|
||||||
plugin_id.lower(),
|
plugin_id.lower(),
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ import aiofiles
|
|||||||
import aioshutil
|
import aioshutil
|
||||||
import httpx
|
import httpx
|
||||||
from anyio import Path as AsyncPath
|
from anyio import Path as AsyncPath
|
||||||
|
from packaging.requirements import Requirement
|
||||||
from packaging.specifiers import SpecifierSet, InvalidSpecifier
|
from packaging.specifiers import SpecifierSet, InvalidSpecifier
|
||||||
from packaging.version import Version, InvalidVersion
|
from packaging.version import Version, InvalidVersion
|
||||||
from pkg_resources import Requirement, working_set
|
from importlib.metadata import distributions
|
||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
from app.core.cache import cached
|
from app.core.cache import cached
|
||||||
@@ -729,18 +730,26 @@ class PluginHelper(metaclass=WeakSingleton):
|
|||||||
def __get_installed_packages(self) -> Dict[str, Version]:
|
def __get_installed_packages(self) -> Dict[str, Version]:
|
||||||
"""
|
"""
|
||||||
获取已安装的包及其版本
|
获取已安装的包及其版本
|
||||||
使用 pkg_resources 获取当前环境中已安装的包,标准化包名并转换版本信息
|
使用 importlib.metadata 获取当前环境中已安装的包,标准化包名并转换版本信息
|
||||||
对于无法解析的版本,记录警告日志并跳过
|
对于无法解析的版本,记录警告日志并跳过
|
||||||
:return: 已安装包的字典,格式为 {package_name: Version}
|
:return: 已安装包的字典,格式为 {package_name: Version}
|
||||||
"""
|
"""
|
||||||
installed_packages = {}
|
installed_packages = {}
|
||||||
try:
|
try:
|
||||||
for dist in working_set:
|
for dist in distributions():
|
||||||
pkg_name = self.__standardize_pkg_name(dist.project_name)
|
name = dist.metadata.get("Name")
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
pkg_name = self.__standardize_pkg_name(name)
|
||||||
|
version_str = dist.metadata.get("Version") or getattr(dist, "version", None)
|
||||||
|
if not version_str:
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
installed_packages[pkg_name] = Version(dist.version)
|
v = Version(version_str)
|
||||||
|
if pkg_name not in installed_packages or v > installed_packages[pkg_name]:
|
||||||
|
installed_packages[pkg_name] = v
|
||||||
except InvalidVersion:
|
except InvalidVersion:
|
||||||
logger.debug(f"无法解析已安装包 '{pkg_name}' 的版本:{dist.version}")
|
logger.debug(f"无法解析已安装包 '{pkg_name}' 的版本:{version_str}")
|
||||||
continue
|
continue
|
||||||
return installed_packages
|
return installed_packages
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -844,12 +853,14 @@ class PluginHelper(metaclass=WeakSingleton):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def __standardize_pkg_name(name: str) -> str:
|
def __standardize_pkg_name(name: str) -> str:
|
||||||
"""
|
"""
|
||||||
标准化包名,将包名转换为小写并将连字符替换为下划线
|
标准化包名,将包名转换为小写,连字符与点替换为下划线(与 PEP 503 归一化风格一致)
|
||||||
|
|
||||||
:param name: 原始包名
|
:param name: 原始包名
|
||||||
:return: 标准化后的包名
|
:return: 标准化后的包名
|
||||||
"""
|
"""
|
||||||
return name.lower().replace("-", "_") if name else name
|
if not name:
|
||||||
|
return name
|
||||||
|
return name.lower().replace("-", "_").replace(".", "_")
|
||||||
|
|
||||||
async def async_get_plugin_package_version(self, pid: str, repo_url: str,
|
async def async_get_plugin_package_version(self, pid: str, repo_url: str,
|
||||||
package_version: Optional[str] = None) -> Optional[str]:
|
package_version: Optional[str] = None) -> Optional[str]:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
setuptools
|
|
||||||
Cython~=3.1.2
|
Cython~=3.1.2
|
||||||
pydantic>=2.0.0,<3.0.0
|
pydantic>=2.0.0,<3.0.0
|
||||||
pydantic-settings>=2.0.0,<3.0.0
|
pydantic-settings>=2.0.0,<3.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user