1
1
#!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
2
4
import hashlib
3
5
import http
4
6
import os .path
7
+ import platform
5
8
import stat
6
9
import sys
7
10
import urllib .request
8
- from typing import Tuple
9
11
10
12
from distutils .command .build import build as orig_build
11
13
from distutils .core import Command
12
14
from setuptools import setup
13
15
from setuptools .command .install import install as orig_install
14
16
15
- SHFMT_VERSION = '3.4.3 '
17
+ SHFMT_VERSION = '3.7.0 '
16
18
POSTFIX_SHA256 = {
17
- # TODO(rhee): detect "linux.aarch64" and "linux.armv6hf"
18
- 'linux' : (
19
+ ('linux' , 'armv6hf' ): (
20
+ 'linux_arm' ,
21
+ '3d1f5a1aede8161293bc42007af5b983f16d62857736c789f062346ed839f299' ,
22
+ ),
23
+ ('linux' , 'aarch64' ): (
24
+ 'linux_arm64' ,
25
+ '111612560d15bd53d8e8f8f85731176ce12f3b418ec473d39a40ed6bbec772de' ,
26
+ ),
27
+ ('linux' , 'x86_64' ): (
19
28
'linux_amd64' ,
20
- '713ef49db9a60a00636814a507da851b58da6b4b98a3627188fba0a61b60f9a8 ' ,
29
+ '0264c424278b18e22453fe523ec01a19805ce3b8ebf18eaf3aadc1edc23f42e3 ' ,
21
30
),
22
- 'darwin' : (
31
+ ( 'darwin' , 'x86_64' ) : (
23
32
'darwin_amd64' ,
24
- '22af685075e0448861c5db111e70cc399bdc95cdd7def943bc5adb6783f3e530 ' ,
33
+ 'ae1d1ab961c113fb3dc2ff1150f33c3548983550d91da889b3171a5bcfaab14f ' ,
25
34
),
26
- 'win32' : (
35
+ ('darwin' , 'arm64' ): (
36
+ 'darwin_arm64' ,
37
+ 'ad7ff6f666adba3d801eb17365a15539f07296718d39fb62cc2fde6b527178aa' ,
38
+ ),
39
+ ('win32' , 'AMD64' ): (
27
40
'windows_amd64.exe' ,
28
- 'a6c317a68dddf8efa9fd87d985a807cf7ab2423871d390aac4d3775691565835' ,
41
+ '2807b4af91fbbd961b68716de06c044f1b4f897457fc89fba216e5e2e351c64f' ,
42
+ ),
43
+ ('win32' , 'x86' ): (
44
+ 'windows_386.exe' ,
45
+ '8bd0422554dd6ce5e07d9d17d020d89254b5c056009005df824e39a8cbdcf6aa' ,
29
46
),
30
47
}
48
+ POSTFIX_SHA256 [('cygwin' , 'x86_64' )] = POSTFIX_SHA256 [('win32' , 'AMD64' )]
49
+ POSTFIX_SHA256 [('linux' , 'armv7l' )] = POSTFIX_SHA256 [('linux' , 'armv6hf' )]
31
50
PY_VERSION = '1'
32
51
33
52
34
- def get_download_url () -> Tuple [str , str ]:
35
- postfix , sha256 = POSTFIX_SHA256 [sys .platform ]
53
+ def get_download_url () -> tuple [str , str ]:
54
+ postfix , sha256 = POSTFIX_SHA256 [( sys .platform , platform . machine ()) ]
36
55
url = (
37
56
f'https://github.com/mvdan/sh/releases/download/'
38
57
f'v{ SHFMT_VERSION } /shfmt_v{ SHFMT_VERSION } _{ postfix } '
@@ -58,7 +77,7 @@ def download(url: str, sha256: str) -> bytes:
58
77
def save_executable (data : bytes , base_dir : str ):
59
78
exe = 'shfmt' if sys .platform != 'win32' else 'shfmt.exe'
60
79
output_path = os .path .join (base_dir , exe )
61
- os .makedirs (base_dir )
80
+ os .makedirs (base_dir , exist_ok = True )
62
81
63
82
with open (output_path , 'wb' ) as fp :
64
83
fp .write (data )
0 commit comments