6
6
import shutil
7
7
import struct
8
8
import subprocess
9
- import sys
10
9
import tarfile
11
10
import tempfile
12
11
import time
13
- from enum import IntEnum
12
+ from collections . abc import Iterator
14
13
from dataclasses import dataclass , field , replace
14
+ from enum import IntEnum
15
15
16
16
17
17
def fetch (url : str , path : str ) -> None :
@@ -38,7 +38,7 @@ def get_platform() -> str:
38
38
39
39
40
40
@contextlib .contextmanager
41
- def chdir (path ) :
41
+ def chdir (path : str ) -> Iterator [ None ] :
42
42
"""
43
43
Changes to a directory and returns to the original directory at exit.
44
44
"""
@@ -51,28 +51,22 @@ def chdir(path):
51
51
52
52
53
53
@contextlib .contextmanager
54
- def log_group (title ) :
54
+ def log_group (title : str ) -> Iterator [ None ] :
55
55
"""
56
56
Starts a log group and ends it at exit.
57
57
"""
58
58
start_time = time .time ()
59
59
success = False
60
- log_print (f"::group::{ title } " )
60
+ print (f"::group::{ title } " , flush = True )
61
61
try :
62
62
yield
63
63
success = True
64
64
finally :
65
65
duration = time .time () - start_time
66
66
outcome = "ok" if success else "failed"
67
- start_color = "\033 [32m" if success else "\033 [31m"
68
- end_color = "\033 [0m"
69
- log_print ("::endgroup::" )
70
- log_print (f"{ start_color } { outcome } { end_color } { duration :.2f} s" .rjust (78 ))
71
-
72
-
73
- def log_print (msg : str ) -> None :
74
- sys .stdout .write (msg + "\n " )
75
- sys .stdout .flush ()
67
+ start_color = "[32m" if success else "[31m"
68
+ ok_str = f"\033 { start_color } { outcome } \033 [0m { duration :.2f} s" .rjust (78 )
69
+ print (f"::endgroup::\n { ok_str } " , flush = True )
76
70
77
71
78
72
def make_args (* , parallel : bool ) -> list [str ]:
@@ -87,16 +81,16 @@ def make_args(*, parallel: bool) -> list[str]:
87
81
return args
88
82
89
83
90
- def prepend_env (env , name , new , separator = " " ):
84
+ def prepend_env (env , name : str , new : str , separator : str = " " ) -> None :
91
85
old = env .get (name )
92
86
if old :
93
87
env [name ] = new + separator + old
94
88
else :
95
89
env [name ] = new
96
90
97
91
98
- def run (cmd , env = None ):
99
- log_print (f"- Running: { cmd } " )
92
+ def run (cmd : list [ str ] , env = None ) -> None :
93
+ print (f"- Running: { cmd } " , flush = True )
100
94
try :
101
95
subprocess .run (cmd , check = True , env = env , stderr = subprocess .PIPE , text = True )
102
96
except subprocess .CalledProcessError as e :
@@ -111,7 +105,7 @@ def correct_configure(file_path: str) -> None:
111
105
old_string = "test_cmd $pkg_config --exists --print-errors $pkg_version || return"
112
106
new_string = 'test_cmd $pkg_config --exists --print-errors "$pkg_version" || return'
113
107
114
- with open (file_path , "r" ) as file :
108
+ with open (file_path ) as file :
115
109
content = file .read ()
116
110
117
111
updated_content = content .replace (old_string , new_string )
@@ -127,7 +121,7 @@ class When(IntEnum):
127
121
always = 3
128
122
129
123
130
- @dataclass
124
+ @dataclass ( slots = True )
131
125
class Package :
132
126
name : str
133
127
source_url : str
@@ -184,9 +178,9 @@ def build(self, package: Package, *, for_builder: bool = False):
184
178
def create_directories (self ) -> None :
185
179
# print debugging information
186
180
if platform .system () == "Darwin" :
187
- log_print ("Environment variables" )
181
+ print ("Environment variables" )
188
182
for var in ("ARCHFLAGS" , "MACOSX_DEPLOYMENT_TARGET" ):
189
- log_print (f" - { var } : { os .environ [var ]} " )
183
+ print (f" - { var } : { os .environ [var ]} " )
190
184
191
185
# delete build directory
192
186
if os .path .exists (self .build_dir ):
0 commit comments