Port Homebrew::DevCmd::UpdatePythonResources
This commit is contained in:
parent
46d758d5cf
commit
7bef4b010c
@ -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
|
||||
|
||||
@ -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 <formula>.
|
||||
EOS
|
||||
switch "-p", "--print-only",
|
||||
description: "Print the updated resource blocks instead of changing <formula>."
|
||||
switch "-s", "--silent",
|
||||
description: "Suppress any output."
|
||||
switch "--ignore-non-pypi-packages",
|
||||
description: "Don't fail if <formula> is not a PyPI package."
|
||||
switch "--install-dependencies",
|
||||
description: "Install missing dependencies required to update resources."
|
||||
flag "--version=",
|
||||
description: "Use the specified <version> when finding resources for <formula>. " \
|
||||
"If no version is specified, the current version for <formula> will be used."
|
||||
flag "--package-name=",
|
||||
description: "Use the specified <package-name> when finding resources for <formula>. " \
|
||||
"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 <formula>.
|
||||
EOS
|
||||
switch "-p", "--print-only",
|
||||
description: "Print the updated resource blocks instead of changing <formula>."
|
||||
switch "-s", "--silent",
|
||||
description: "Suppress any output."
|
||||
switch "--ignore-non-pypi-packages",
|
||||
description: "Don't fail if <formula> is not a PyPI package."
|
||||
switch "--install-dependencies",
|
||||
description: "Install missing dependencies required to update resources."
|
||||
flag "--version=",
|
||||
description: "Use the specified <version> when finding resources for <formula>. " \
|
||||
"If no version is specified, the current version for <formula> will be used."
|
||||
flag "--package-name=",
|
||||
description: "Use the specified <package-name> when finding resources for <formula>. " \
|
||||
"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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user