1+ from __future__ import annotations
2+
13import os
24import platform
5+ import shutil
36import sys
4- from hatchling .builders .hooks .plugin .interface import BuildHookInterface
5- from typing import Any
6- from pathlib import Path
7+ import tarfile
78import tempfile
9+ from pathlib import Path
10+ from typing import Any
811from urllib import request
9- import tarfile
10- import shutil
12+
13+ from hatchling . builders . hooks . plugin . interface import BuildHookInterface
1114
1215
1316class SpecialBuildHook (BuildHookInterface ):
@@ -29,9 +32,7 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
2932 if target_arch not in ["x86_64" , "arm64" , "aarch64" , "i386" ]:
3033 raise NotImplementedError (f"no support arch: { target_arch } " )
3134
32- if not any (
33- os_name in target_os_info for os_name in ["linux" , "darwin" , "macos" , "win" ]
34- ):
35+ if not any (os_name in target_os_info for os_name in ["linux" , "darwin" , "macos" , "win" ]):
3536 raise NotImplementedError (f"no support os: { target_os_info } " )
3637
3738 # 检查系统和架构的组合
@@ -59,9 +60,7 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
5960 # TODO: 加一个 sum 校验
6061 bin_path = self .temp_dir / self .BIN_NAME
6162 assert bin_path .is_file (), f"{ self .BIN_NAME } not found"
62- build_data ["force_include" ][f"{ bin_path .resolve ()} " ] = (
63- f"yamlfmt/{ self .BIN_NAME } "
64- )
63+ build_data ["force_include" ][f"{ bin_path .resolve ()} " ] = f"yamlfmt/{ self .BIN_NAME } "
6564
6665 def download_yamlfmt (self , target_os_info : str , target_arch : str ) -> None :
6766 """Download the yamlfmt binary for the specified OS and architecture."""
@@ -74,15 +73,11 @@ def download_yamlfmt(self, target_os_info: str, target_arch: str) -> None:
7473 "amd64" : "x86_64" ,
7574 "aarch64" : "arm64" ,
7675 }
77- file_path = (
78- self .temp_dir / f"{ self .BIN_NAME } _{ target_os_info } _{ target_arch } .tar.gz"
79- )
76+ file_path = self .temp_dir / f"{ self .BIN_NAME } _{ target_os_info } _{ target_arch } .tar.gz"
8077 request .urlretrieve (
8178 self .YAMLFMT_REPO .format (
8279 version = self .metadata .version ,
83- target_os_info = target_os_info_to_go_os .get (
84- target_os_info , target_os_info
85- ),
80+ target_os_info = target_os_info_to_go_os .get (target_os_info , target_os_info ),
8681 target_arch = target_arch_to_go_arch .get (target_arch , target_arch ),
8782 ),
8883 file_path ,
0 commit comments