aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author苏向夜 <fu050409@163.com>2024-03-08 16:44:09 +0800
committer苏向夜 <fu050409@163.com>2024-03-08 16:44:09 +0800
commite00dcb493586c49d06cd18be06b5523326feb4fa (patch)
tree46a86e9e80d04eb585ce3e20fb4c5da002cd50f7
parent98bd39860fbfae0f9b9284b3120626f6763355f1 (diff)
downloadipm-e00dcb493586c49d06cd18be06b5523326feb4fa.tar.gz
ipm-e00dcb493586c49d06cd18be06b5523326feb4fa.zip
refactor(freeze): set pkgname-version as default root dir in ipk file
-rw-r--r--src/ipm/utils/freeze.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/ipm/utils/freeze.py b/src/ipm/utils/freeze.py
index e865e3c..10fce1f 100644
--- a/src/ipm/utils/freeze.py
+++ b/src/ipm/utils/freeze.py
@@ -1,11 +1,11 @@
from pathlib import Path
from typing import Optional
-from ..exceptions import FileNotFoundError, VerifyFailed
-from ..models.ipk import InfiniProject, InfiniFrozenPackage
-from ..typing import StrPath
-from ..logging import update, info, success, error
-from .hash import ifp_hash, ifp_verify
-from . import _freeze
+from ipm.exceptions import FileNotFoundError, VerifyFailed
+from ipm.models.ipk import InfiniProject, InfiniFrozenPackage
+from ipm.typing import StrPath
+from ipm.logging import update, info, success, error
+from ipm.utils.hash import ifp_hash, ifp_verify
+from ipm.utils import _freeze
import tempfile
import shutil
@@ -13,25 +13,32 @@ import shutil
def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
update("构建开发环境...", echo)
- build_dir = ipk._source_path / "build"
+ project = InfiniProject()
+
+ arcname = f"{project.name}-{project.version}"
+ build_dir = ipk._source_path.joinpath(".ipm-build")
+ arc_dir = build_dir.joinpath(arcname)
src_path = ipk._source_path / "src"
dist_path = ipk._source_path / "dist"
- ifp_path = dist_path / ipk.default_name
+ ifp_path = dist_path.joinpath(ipk.default_name + ".ipk")
if not ipk._source_path.exists():
- raise FileNotFoundError(f"文件或文件夹 [blue]{ipk._source_path.resolve()}[/blue]]不存在!")
- if build_dir.exists():
+ raise FileNotFoundError(
+ f"文件或文件夹 [blue]{ipk._source_path.resolve()}[/blue]]不存在!"
+ )
+ if build_dir.exists() or dist_path.exists():
update("清理构建环境...")
shutil.rmtree(build_dir, ignore_errors=True)
+ shutil.rmtree(dist_path, ignore_errors=True)
success("构建环境清理完毕.")
dist_path.mkdir(parents=True, exist_ok=True)
- build_dir.mkdir(parents=True, exist_ok=True)
+ arc_dir.mkdir(parents=True, exist_ok=True)
success("开发环境构建完毕.", echo)
update("复制工程文件...", echo)
- shutil.copytree(src_path, build_dir / "src")
- shutil.copy2(ipk._source_path / "infini.toml", build_dir / "infini.toml")
+ shutil.copytree(src_path, arc_dir / "src")
+ shutil.copy2(ipk._source_path / "infini.toml", arc_dir / "infini.toml")
success("工程文件复制完毕.", echo)
update("打包 [bold green]ipk[/bold green]文件...", echo)
@@ -39,6 +46,7 @@ def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
str(build_dir),
str(ifp_path),
)
+ shutil.copy2(ifp_path, dist_path.joinpath(ipk.default_name + ".tar.gz"))
success(f"打包文件已存至 [blue]{ifp_path}[/blue].", echo)
update("创建 SHA256 验证文件...", echo)
@@ -51,7 +59,7 @@ def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
echo,
)
- return InfiniFrozenPackage(source_path=ifp_path, **{"name": ipk.name})
+ return InfiniFrozenPackage(ifp_path, ipk.name, version=project.version)
def extract_ipk(