From 02677763cbcd31678bed1b553a6089c65f40bc4e Mon Sep 17 00:00:00 2001 From: qixinbo Date: Fri, 3 Apr 2026 22:59:15 +0800 Subject: [PATCH] fix: bug for dev mode deployment --- backend/hatch_build.py | 37 +++++++++++++++++++++++++++++++++++++ backend/pyproject.toml | 11 +++-------- 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 backend/hatch_build.py diff --git a/backend/hatch_build.py b/backend/hatch_build.py new file mode 100644 index 0000000..64d753d --- /dev/null +++ b/backend/hatch_build.py @@ -0,0 +1,37 @@ +from hatchling.builders.hooks.plugin.interface import BuildHookInterface +import os + +class CustomHook(BuildHookInterface): + def initialize(self, version, build_data): + target = self.target_name + force_include = build_data.setdefault("force_include", {}) + + # Check if we are in original source tree or in an sdist + is_sdist_build = os.path.exists(os.path.join(self.root, "PKG-INFO")) or os.path.exists(os.path.join(self.root, "frontend", "dist")) + + if is_sdist_build: + frontend_dist = os.path.join(self.root, "frontend", "dist") + nanobot_dir = os.path.join(self.root, "nanobot") + else: + frontend_dist = os.path.join(self.root, "..", "frontend", "dist") + nanobot_dir = os.path.join(self.root, "..", "nanobot", "nanobot") + + main_py = os.path.join(self.root, "main.py") + + if target == "wheel": + if os.path.exists(frontend_dist): + force_include[frontend_dist] = "app/webui" + if os.path.exists(nanobot_dir): + force_include[nanobot_dir] = "nanobot" + if os.path.exists(main_py): + force_include[main_py] = "main.py" + + elif target == "sdist": + # For sdist, we only pack them if we are in the original source tree + if not is_sdist_build: + if os.path.exists(frontend_dist): + force_include[frontend_dist] = "frontend/dist" + if os.path.exists(nanobot_dir): + force_include[nanobot_dir] = "nanobot" + if os.path.exists(main_py): + force_include[main_py] = "main.py" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 20c12db..a217b22 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -76,12 +76,7 @@ packages = ["app"] [tool.hatch.build.targets.wheel.sources] "app" = "app" -[tool.hatch.build.targets.wheel.force-include] -"../frontend/dist" = "app/webui" -"../nanobot/nanobot" = "nanobot" -"main.py" = "main.py" -[tool.hatch.build.targets.sdist.force-include] -"../frontend/dist" = "frontend/dist" -"../nanobot/nanobot" = "nanobot" -"main.py" = "main.py" +[tool.hatch.build.hooks.custom] +path = "hatch_build.py" +