11import re
2+ import shutil
3+ import subprocess # nosec B404
24import textwrap
35from typing import (
46 Any ,
1618 TARGET_DARWIN_ARM64 ,
1719 TARGET_LINUX_AMD64 ,
1820 TARGET_LINUX_ARM64 ,
21+ TIMEOUT ,
1922)
2023
2124
@@ -33,6 +36,7 @@ def generate_formula_data(
3336 download_strategy : Optional [str ] = None ,
3437 custom_require : Optional [str ] = None ,
3538 formula_includes : Optional [str ] = None ,
39+ update_python_resources : bool = False ,
3640 version : Optional [str ] = None ,
3741 ) -> str :
3842 """Generates the formula data for Homebrew.
@@ -245,7 +249,9 @@ def match_indent_of(tag: str, text: str) -> str:
245249 )
246250
247251 logger .info ('Homebrew formula generated successfully!' )
248- logger .debug (rendered_template )
252+ # If we are updating python resources, we'll log this later once resources are updated
253+ if not update_python_resources :
254+ logger .debug (rendered_template )
249255
250256 return rendered_template
251257
@@ -265,3 +271,27 @@ def _generate_class_name(repo_name: str) -> str:
265271 repo_name .title (),
266272 ),
267273 )
274+
275+ @staticmethod
276+ def update_python_resources (formula_dir : str , formula_filename : str ) -> None :
277+ """Runs brew update-python-resources on the formula to add Python resources."""
278+ logger = woodchips .get (LOGGER_NAME )
279+
280+ brew_path = shutil .which ('brew' )
281+ if not brew_path :
282+ raise SystemExit ("brew not found in PATH" )
283+
284+ try :
285+ logger .info (f'Running brew update-python-resources for { formula_filename } ...' )
286+ subprocess .check_output (
287+ f'cd { formula_dir } && { brew_path } update-python-resources { formula_filename } ' ,
288+ stderr = subprocess .STDOUT ,
289+ text = True ,
290+ timeout = TIMEOUT ,
291+ shell = True , # nosec
292+ )
293+ logger .info (f'Successfully updated Python resources for { formula_filename } ' )
294+ except subprocess .TimeoutExpired as e :
295+ raise SystemExit from e
296+ except subprocess .CalledProcessError as e :
297+ raise SystemExit (f'An error occurred while updating Python resources: { e } ' ) from e
0 commit comments