@@ -99,19 +99,29 @@ def select_asset(release: dict[str, Any], asset_name: str) -> dict[str, Any]:
9999 for asset in release .get ("assets" , []):
100100 if asset .get ("name" ) == asset_name :
101101 return asset
102- available = ", " .join (asset .get ("name" , "<unnamed>" ) for asset in release .get ("assets" , []))
103- raise SystemExit (f"Release asset not found: { asset_name } . Available assets: { available } " )
102+ available = ", " .join (
103+ asset .get ("name" , "<unnamed>" ) for asset in release .get ("assets" , [])
104+ )
105+ raise SystemExit (
106+ f"Release asset not found: { asset_name } . Available assets: { available } "
107+ )
104108
105109
106- def select_archive_asset (release : dict [str , Any ], target_platform : str ) -> dict [str , Any ]:
107- pattern = re .compile (rf"^mpi-extensions-openmpi-.+-{ re .escape (target_platform )} \.tar\.gz$" )
110+ def select_archive_asset (
111+ release : dict [str , Any ], target_platform : str
112+ ) -> dict [str , Any ]:
113+ pattern = re .compile (
114+ rf"^mpi-extensions-openmpi-.+-{ re .escape (target_platform )} \.tar\.gz$"
115+ )
108116 matches = [
109117 asset
110118 for asset in release .get ("assets" , [])
111119 if pattern .match (str (asset .get ("name" , "" )))
112120 ]
113121 if len (matches ) != 1 :
114- available = ", " .join (asset .get ("name" , "<unnamed>" ) for asset in release .get ("assets" , []))
122+ available = ", " .join (
123+ asset .get ("name" , "<unnamed>" ) for asset in release .get ("assets" , [])
124+ )
115125 raise SystemExit (
116126 f"Expected exactly one nightly archive for { target_platform } , "
117127 f"found { len (matches )} . Available assets: { available } "
@@ -148,30 +158,43 @@ def safe_extract(archive: Path, destination: Path) -> Path:
148158 continue
149159 roots .add (parts [0 ])
150160 target = (destination / member .name ).resolve ()
151- if target != resolved_destination and resolved_destination not in target .parents :
161+ if (
162+ target != resolved_destination
163+ and resolved_destination not in target .parents
164+ ):
152165 raise SystemExit (f"Archive contains unsafe path: { member .name } " )
153166 if len (roots ) != 1 :
154- raise SystemExit (f"Expected archive to contain one top-level directory, found: { roots } " )
167+ raise SystemExit (
168+ f"Expected archive to contain one top-level directory, found: { roots } "
169+ )
155170 tar .extractall (destination , members = members )
156171 return destination / roots .pop ()
157172
158173
159174def install_tree (source_root : Path , prefix : Path , force : bool ) -> None :
160175 required_tools = ["mpicc" , "mpicxx" , "mpirun" , "mpiexec" ]
161- missing_tools = [tool for tool in required_tools if not (source_root / "bin" / tool ).exists ()]
176+ missing_tools = [
177+ tool for tool in required_tools if not (source_root / "bin" / tool ).exists ()
178+ ]
162179 if missing_tools :
163- raise SystemExit (f"Archive is missing required MPI tools: { ', ' .join (missing_tools )} " )
180+ raise SystemExit (
181+ f"Archive is missing required MPI tools: { ', ' .join (missing_tools )} "
182+ )
164183
165184 if prefix .exists ():
166185 if not force and any (prefix .iterdir ()):
167- raise SystemExit (f"Installation prefix is not empty: { prefix } . Use --force to replace it." )
186+ raise SystemExit (
187+ f"Installation prefix is not empty: { prefix } . Use --force to replace it."
188+ )
168189 shutil .rmtree (prefix )
169190 prefix .parent .mkdir (parents = True , exist_ok = True )
170191 shutil .copytree (source_root , prefix , symlinks = True )
171192
172193
173194def run_tool (command : list [str ]) -> subprocess .CompletedProcess [str ]:
174- return subprocess .run (command , check = False , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
195+ return subprocess .run (
196+ command , check = False , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True
197+ )
175198
176199
177200def otool_lines (path : Path ) -> list [str ]:
@@ -185,7 +208,9 @@ def patch_macos_install_names(prefix: Path) -> None:
185208 if platform .system () != "Darwin" :
186209 return
187210 if not shutil .which ("install_name_tool" ) or not shutil .which ("otool" ):
188- raise SystemExit ("macOS install_name_tool and otool are required to install mpi-extensions" )
211+ raise SystemExit (
212+ "macOS install_name_tool and otool are required to install mpi-extensions"
213+ )
189214
190215 lib_dir = prefix / "lib"
191216 if not lib_dir .exists ():
@@ -208,12 +233,19 @@ def patch_macos_install_names(prefix: Path) -> None:
208233 result = run_tool (["otool" , "-D" , str (path )])
209234 if result .returncode != 0 :
210235 continue
211- install_names = [line .strip () for line in result .stdout .splitlines ()[1 :] if line .strip ()]
236+ install_names = [
237+ line .strip () for line in result .stdout .splitlines ()[1 :] if line .strip ()
238+ ]
212239 if install_names :
213240 local_name = local_libs .get (Path (install_names [0 ]).name )
214241 if local_name :
215242 subprocess .run (
216- ["install_name_tool" , "-id" , f"@rpath/{ local_name .name } " , str (path )],
243+ [
244+ "install_name_tool" ,
245+ "-id" ,
246+ f"@rpath/{ local_name .name } " ,
247+ str (path ),
248+ ],
217249 check = True ,
218250 )
219251
@@ -231,7 +263,13 @@ def patch_macos_install_names(prefix: Path) -> None:
231263 else :
232264 replacement = f"@rpath/{ local_dependency .name } "
233265 subprocess .run (
234- ["install_name_tool" , "-change" , dependency , replacement , str (path )],
266+ [
267+ "install_name_tool" ,
268+ "-change" ,
269+ dependency ,
270+ replacement ,
271+ str (path ),
272+ ],
235273 check = True ,
236274 )
237275
@@ -258,10 +296,14 @@ def main() -> int:
258296
259297 session = requests .Session ()
260298 session .headers .update (github_headers ())
261- release_url = f"https://api.github.com/repos/{ args .repo } /releases/tags/{ NIGHTLY_TAG } "
299+ release_url = (
300+ f"https://api.github.com/repos/{ args .repo } /releases/tags/{ NIGHTLY_TAG } "
301+ )
262302 release = get_json (session , release_url )
263303 if release .get ("tag_name" ) != NIGHTLY_TAG or not release .get ("prerelease" ):
264- raise SystemExit (f"Release { args .repo } @{ NIGHTLY_TAG } is not the nightly prerelease" )
304+ raise SystemExit (
305+ f"Release { args .repo } @{ NIGHTLY_TAG } is not the nightly prerelease"
306+ )
265307
266308 archive_asset = select_archive_asset (release , target_platform )
267309 archive_name = archive_asset ["name" ]
@@ -271,7 +313,10 @@ def main() -> int:
271313 temp_dir = Path (temp_dir_text )
272314 archive_path = temp_dir / archive_name
273315 checksum_path = temp_dir / f"{ archive_name } .sha256"
274- print (f"Downloading { archive_name } from { args .repo } @{ NIGHTLY_TAG } " , file = sys .stderr )
316+ print (
317+ f"Downloading { archive_name } from { args .repo } @{ NIGHTLY_TAG } " ,
318+ file = sys .stderr ,
319+ )
275320 download (session , archive_asset ["browser_download_url" ], archive_path )
276321 download (session , checksum_asset ["browser_download_url" ], checksum_path )
277322
0 commit comments