From 7bef4b010cb725773938def8e43bc463550897d3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 21 Mar 2024 22:10:12 -0700 Subject: [PATCH] Port Homebrew::DevCmd::UpdatePythonResources --- .../Homebrew/dev-cmd/update-maintainers.rb | 95 ++++++++++--------- .../dev-cmd/update-python-resources.rb | 87 +++++++++-------- .../test/dev-cmd/update-maintainers_spec.rb | 3 +- .../dev-cmd/update-python-resources_spec.rb | 3 +- 4 files changed, 95 insertions(+), 93 deletions(-) diff --git a/Library/Homebrew/dev-cmd/update-maintainers.rb b/Library/Homebrew/dev-cmd/update-maintainers.rb index 75811fd79f..1bb8734f55 100644 --- a/Library/Homebrew/dev-cmd/update-maintainers.rb +++ b/Library/Homebrew/dev-cmd/update-maintainers.rb @@ -1,68 +1,69 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "cli/parser" require "utils/github" require "manpages" require "system_command" module Homebrew - extend SystemCommand::Mixin + module DevCmd + class UpdateMaintainers < AbstractCommand + include SystemCommand::Mixin - sig { returns(CLI::Parser) } - def self.update_maintainers_args - Homebrew::CLI::Parser.new do - description <<~EOS - Update the list of maintainers in the `Homebrew/brew` README. - EOS + cmd_args do + description <<~EOS + Update the list of maintainers in the `Homebrew/brew` README. + EOS - named_args :none - end - end + named_args :none + end - def self.update_maintainers - update_maintainers_args.parse + sig { override.void } + def run + # We assume that only public members wish to be included in the README + public_members = GitHub.public_member_usernames("Homebrew") + maintainers = GitHub.members_by_team("Homebrew", "maintainers") - # We assume that only public members wish to be included in the README - public_members = GitHub.public_member_usernames("Homebrew") - maintainers = GitHub.members_by_team("Homebrew", "maintainers") + HOMEBREW_MAINTAINER_JSON.write(maintainers.keys.to_json) + maintainer_json_relative_path = HOMEBREW_MAINTAINER_JSON.relative_path_from(HOMEBREW_REPOSITORY).to_s - HOMEBREW_MAINTAINER_JSON.write(maintainers.keys.to_json) - maintainer_json_relative_path = HOMEBREW_MAINTAINER_JSON.relative_path_from(HOMEBREW_REPOSITORY).to_s + members = { + plc: GitHub.members_by_team("Homebrew", "plc"), + tsc: GitHub.members_by_team("Homebrew", "tsc"), + maintainers:, + } - members = { - plc: GitHub.members_by_team("Homebrew", "plc"), - tsc: GitHub.members_by_team("Homebrew", "tsc"), - maintainers:, - } + sentences = {} + members.each do |group, hash| + hash.replace(hash.slice(*public_members)) + hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" } + sentences[group] = hash.values.sort.to_sentence + end - sentences = {} - members.each do |group, hash| - hash.replace(hash.slice(*public_members)) - hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" } - sentences[group] = hash.values.sort.to_sentence - end + readme = HOMEBREW_REPOSITORY/"README.md" - readme = HOMEBREW_REPOSITORY/"README.md" + content = readme.read + content.gsub!(/(Homebrew's \[Project Leadership Committee.*) is .*\./, + "\\1 is #{sentences[:plc]}.") + content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./, + "\\1 is #{sentences[:tsc]}.") + content.gsub!(/(Homebrew's maintainers are).*\./, + "\\1 #{sentences[:maintainers]}.") - content = readme.read - content.gsub!(/(Homebrew's \[Project Leadership Committee.*) is .*\./, - "\\1 is #{sentences[:plc]}.") - content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./, - "\\1 is #{sentences[:tsc]}.") - content.gsub!(/(Homebrew's maintainers are).*\./, - "\\1 #{sentences[:maintainers]}.") + File.write(readme, content) - File.write(readme, content) - - diff = system_command "git", args: [ - "-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", "README.md", maintainer_json_relative_path - ] - if diff.status.success? - ofail "No changes to list of maintainers." - else - Manpages.regenerate_man_pages(quiet: true) - puts "List of maintainers updated in the README and the generated man pages." + diff = system_command "git", args: [ + "-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", "README.md", maintainer_json_relative_path + ] + if diff.status.success? + ofail "No changes to list of maintainers." + else + Manpages.regenerate_man_pages(quiet: true) + puts "List of maintainers updated in the README and the generated man pages." + end + end end end end diff --git a/Library/Homebrew/dev-cmd/update-python-resources.rb b/Library/Homebrew/dev-cmd/update-python-resources.rb index 169dede9da..50fc287cbe 100644 --- a/Library/Homebrew/dev-cmd/update-python-resources.rb +++ b/Library/Homebrew/dev-cmd/update-python-resources.rb @@ -1,55 +1,54 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "cli/parser" require "utils/pypi" module Homebrew - module_function + module DevCmd + class UpdatePythonResources < AbstractCommand + cmd_args do + description <<~EOS + Update versions for PyPI resource blocks in . + EOS + switch "-p", "--print-only", + description: "Print the updated resource blocks instead of changing ." + switch "-s", "--silent", + description: "Suppress any output." + switch "--ignore-non-pypi-packages", + description: "Don't fail if is not a PyPI package." + switch "--install-dependencies", + description: "Install missing dependencies required to update resources." + flag "--version=", + description: "Use the specified when finding resources for . " \ + "If no version is specified, the current version for will be used." + flag "--package-name=", + description: "Use the specified when finding resources for . " \ + "If no package name is specified, it will be inferred from the formula's stable URL." + comma_array "--extra-packages", + description: "Include these additional packages when finding resources." + comma_array "--exclude-packages", + description: "Exclude these packages when finding resources." - sig { returns(CLI::Parser) } - def update_python_resources_args - Homebrew::CLI::Parser.new do - description <<~EOS - Update versions for PyPI resource blocks in . - EOS - switch "-p", "--print-only", - description: "Print the updated resource blocks instead of changing ." - switch "-s", "--silent", - description: "Suppress any output." - switch "--ignore-non-pypi-packages", - description: "Don't fail if is not a PyPI package." - switch "--install-dependencies", - description: "Install missing dependencies required to update resources." - flag "--version=", - description: "Use the specified when finding resources for . " \ - "If no version is specified, the current version for will be used." - flag "--package-name=", - description: "Use the specified when finding resources for . " \ - "If no package name is specified, it will be inferred from the formula's stable URL." - comma_array "--extra-packages", - description: "Include these additional packages when finding resources." - comma_array "--exclude-packages", - description: "Exclude these packages when finding resources." + named_args :formula, min: 1, without_api: true + end - named_args :formula, min: 1, without_api: true - end - end - - def update_python_resources - args = update_python_resources_args.parse - - args.named.to_formulae.each do |formula| - PyPI.update_python_resources! formula, - version: args.version, - package_name: args.package_name, - extra_packages: args.extra_packages, - exclude_packages: args.exclude_packages, - install_dependencies: args.install_dependencies?, - print_only: args.print_only?, - silent: args.silent?, - verbose: args.verbose?, - ignore_non_pypi_packages: args.ignore_non_pypi_packages? + sig { override.void } + def run + args.named.to_formulae.each do |formula| + PyPI.update_python_resources! formula, + version: args.version, + package_name: args.package_name, + extra_packages: args.extra_packages, + exclude_packages: args.exclude_packages, + install_dependencies: args.install_dependencies?, + print_only: args.print_only?, + silent: args.silent?, + verbose: args.verbose?, + ignore_non_pypi_packages: args.ignore_non_pypi_packages? + end + end end end end diff --git a/Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb b/Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb index a58eed3bc6..2b953c399f 100644 --- a/Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb +++ b/Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "dev-cmd/update-maintainers" -RSpec.describe "brew update-maintainers" do +RSpec.describe Homebrew::DevCmd::UpdateMaintainers do it_behaves_like "parseable arguments" end diff --git a/Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb b/Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb index 9b304adf39..2487d8eced 100644 --- a/Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb +++ b/Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "dev-cmd/update-python-resources" -RSpec.describe "brew update-python-resources" do +RSpec.describe Homebrew::DevCmd::UpdatePythonResources do it_behaves_like "parseable arguments" end