Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update homebrew python version
  • Loading branch information
bebound committed Aug 15, 2023
commit 8ae6369ef63c2078ef0ba59f1d3bafdc6397f364
24 changes: 16 additions & 8 deletions scripts/release/homebrew/docker/formula_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
import bisect
import argparse

TEMPLATE_FILE_NAME='formula_template.txt'
CLI_VERSION=os.environ['CLI_VERSION']
HOMEBREW_UPSTREAM_URL=os.environ['HOMEBREW_UPSTREAM_URL']
HOMEBREW_FORMULAR_LATEST="https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/azure-cli.rb"
TEMPLATE_FILE_NAME = 'formula_template.txt'
CLI_VERSION = os.environ['CLI_VERSION']
HOMEBREW_UPSTREAM_URL = os.environ['HOMEBREW_UPSTREAM_URL']
HOMEBREW_FORMULAR_LATEST = "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/azure-cli.rb"
PYTHON_VERSION = '3.11'


def main():
print('Generate formula for Azure CLI homebrew release.')

parser = argparse.ArgumentParser(prog='formula_generator.py')
parser.set_defaults(func=generate_formula)
parser.add_argument('-b', dest='build_method', choices=['update_existing', 'use_template'], help='The build method, default is update_existing, the other option is use_template.')
parser.add_argument('-b', dest='build_method', choices=['update_existing', 'use_template'],
help='The build method, default is update_existing, the other option is use_template.')
args = parser.parse_args()
args.func(**vars(args))


def generate_formula(build_method: str, **_):
content = ''
if build_method is None or build_method == 'update_existing':
Expand Down Expand Up @@ -82,7 +85,8 @@ def collect_resources() -> str:

def collect_resources_dict() -> dict:
nodes = make_graph('azure-cli')
filtered_nodes = {nodes[node_name]['name']: nodes[node_name] for node_name in sorted(nodes) if resource_filter(node_name)}
filtered_nodes = {nodes[node_name]['name']: nodes[node_name] for node_name in sorted(nodes) if
resource_filter(node_name)}
return filtered_nodes


Expand Down Expand Up @@ -121,6 +125,10 @@ def update_formula() -> str:
resp.raise_for_status()
text = resp.text

# update python version
text = re.sub('depends_on "python@.*"', f'depends_on "python@{PYTHON_VERSION}"', text, 1)
text = re.sub(r'virtualenv_create\(libexec, "python.*"', f'virtualenv_create(libexec, "python{PYTHON_VERSION}"', text, 1) # pylint: disable=line-too-long

Comment on lines +128 to +131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these lines be dropped in the next release? It is really inconvenient to make any change to the formula.

Or, can we just keep the formula as is and make the change when a PR is submitted for https://github.com/Homebrew/homebrew-core/blob/master/Formula/a/azure-cli.rb ?

In my thought, the Azure CLI repo should be self-contained - it should never depend on external resources to build and install.

Copy link
Contributor Author

@bebound bebound Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it here for two reasons.

  1. TestHomebrewFormula can check whether new formula works with new Python.
  2. Homebrew users can use the new Python version as soon as possible.

For other changes like the without_pip: false in #27186, we can create a PR for homebrew.

Sometimes the Homebrew community update our formula, which cause a conflict, so we modify the external formula. This behavior is introduced in #11964

# update url and sha256 of azure-cli
text = re.sub('url ".*"', 'url "{}"'.format(HOMEBREW_UPSTREAM_URL), text, 1)
upstream_sha = compute_sha256(HOMEBREW_UPSTREAM_URL)
Expand Down Expand Up @@ -148,7 +156,7 @@ def update_formula() -> str:
node_index_dict[pack] = idx
elif pack is not None:
if line.startswith(" url"):
#update the url of package
# update the url of package
if pack in nodes.keys():
url_match = re.search(r'url "(.*)"', line)
if url_match is not None and nodes[pack]['url'] != url_match.group(1):
Expand All @@ -157,7 +165,7 @@ def update_formula() -> str:
else:
packs_to_remove.add(pack)
elif line.startswith(" sha256"):
#update the sha256 of package
# update the sha256 of package
if pack in nodes.keys():
lines[idx] = re.sub('sha256 ".*"', 'sha256 "{}"'.format(nodes[pack]['checksum']), line, 1)
del nodes[pack]
Expand Down