2024-05-20 11:12:03 +08:00
|
|
|
# noqa: INP001
|
2024-05-22 20:22:38 +01:00
|
|
|
import os
|
2024-05-20 11:12:03 +08:00
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
from sys import stderr
|
|
|
|
|
|
|
|
|
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomBuildHook(BuildHookInterface):
|
|
|
|
|
def initialize(self, version, build_data):
|
|
|
|
|
super().initialize(version, build_data)
|
2026-03-17 17:58:01 -05:00
|
|
|
stderr.write('>>> Building Open Webui frontend\n')
|
|
|
|
|
npm = shutil.which('npm')
|
2024-05-20 11:12:03 +08:00
|
|
|
if npm is None:
|
2026-03-17 17:58:01 -05:00
|
|
|
raise RuntimeError('NodeJS `npm` is required for building Open Webui but it was not found')
|
|
|
|
|
stderr.write('### npm install\n')
|
|
|
|
|
subprocess.run([npm, 'install', '--force'], check=True) # noqa: S603
|
|
|
|
|
stderr.write('\n### npm run build\n')
|
|
|
|
|
os.environ['APP_BUILD_HASH'] = version
|
|
|
|
|
subprocess.run([npm, 'run', 'build'], check=True) # noqa: S603
|