mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 13:12:24 +00:00
Add plugin related interfaces (#535)
* Add plugin related interfaces * Update interface auth * Add build plugin zip service
This commit is contained in:
+24
-15
@@ -13,6 +13,7 @@ import rtoml
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.core.conf import settings
|
||||
from backend.core.path_conf import PLUGIN_DIR
|
||||
from backend.utils.import_parse import import_module_cached
|
||||
|
||||
@@ -156,13 +157,21 @@ def install_requirements() -> None:
|
||||
else:
|
||||
try:
|
||||
subprocess.run([sys.executable, '-m', 'ensurepip', '--upgrade'])
|
||||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', requirements_file])
|
||||
pip_requirements = [sys.executable, '-m', 'pip', 'install', '-r', requirements_file]
|
||||
if settings.PLUGIN_PIP_CHINA:
|
||||
pip_requirements.extend(['-i', settings.PLUGIN_PIP_INDEX_URL])
|
||||
subprocess.check_call(pip_requirements)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise PluginInjectError(f'插件 {plugin} 依赖安装失败:{e}') from e
|
||||
|
||||
|
||||
async def install_requirements_async() -> None:
|
||||
"""异步安装插件依赖"""
|
||||
async def install_requirements_async(wait: bool = True) -> None:
|
||||
"""
|
||||
异步安装插件依赖
|
||||
|
||||
:param wait: 是否等待结果并校验,开启将造成 IO 阻塞
|
||||
:return:
|
||||
"""
|
||||
plugins = get_plugins()
|
||||
for plugin in plugins:
|
||||
requirements_file = os.path.join(PLUGIN_DIR, plugin, 'requirements.txt')
|
||||
@@ -177,19 +186,19 @@ async def install_requirements_async() -> None:
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
_, ensurepip_stderr = await ensurepip_process.communicate()
|
||||
if ensurepip_process.returncode != 0:
|
||||
raise PluginInjectError(f'ensurepip 安装失败:{ensurepip_stderr}')
|
||||
if wait:
|
||||
_, ensurepip_stderr = await ensurepip_process.communicate()
|
||||
if ensurepip_process.returncode != 0:
|
||||
raise PluginInjectError(f'ensurepip 安装失败:{ensurepip_stderr}')
|
||||
pip_requirements = [sys.executable, '-m', 'pip', 'install', '-r', requirements_file]
|
||||
if settings.PLUGIN_PIP_CHINA:
|
||||
pip_requirements.extend(['-i', settings.PLUGIN_PIP_INDEX_URL])
|
||||
pip_process = await async_subprocess.create_subprocess_exec(
|
||||
sys.executable,
|
||||
'-m',
|
||||
'pip',
|
||||
'install',
|
||||
'-r',
|
||||
requirements_file,
|
||||
*pip_requirements,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
_, pip_stderr = await pip_process.communicate()
|
||||
if pip_process.returncode != 0:
|
||||
raise PluginInjectError(f'插件 {plugin} 依赖包安装失败:{pip_stderr}')
|
||||
if wait:
|
||||
_, pip_stderr = await pip_process.communicate()
|
||||
if pip_process.returncode != 0:
|
||||
raise PluginInjectError(f'插件 {plugin} 依赖包安装失败:{pip_stderr}')
|
||||
|
||||
Reference in New Issue
Block a user