From 51b16585fb32f2d33a3ec7dd8d6ca5d6e0d844c7 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Mon, 20 Nov 2023 14:03:50 +0000 Subject: [PATCH] formula_creator: Remove `path` attr to reduce code complexity `path` attribute is used only once, and it is easier to calculate it on the fly than to update its state after different methods. --- Library/Homebrew/dev-cmd/create.rb | 4 ++-- Library/Homebrew/formula_creator.rb | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index f02b61769a..36ae89bd49 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -200,7 +200,7 @@ module Homebrew end end - fc.generate! + path = fc.generate! formula = Homebrew.with_no_api_env do Formula[fc.name] @@ -208,7 +208,7 @@ module Homebrew PyPI.update_python_resources! formula, ignore_non_pypi_packages: true if args.python? puts "Please run `brew audit --new #{fc.name}` before submitting, thanks." - fc.path + path end def __gets diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index 05679630e2..f90eb4be0b 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -10,7 +10,7 @@ module Homebrew # @api private class FormulaCreator attr_reader :args, :url, :sha256, :desc, :homepage - attr_accessor :name, :version, :tap, :path, :mode, :license + attr_accessor :name, :version, :tap, :mode, :license def initialize(args) @args = args @@ -34,7 +34,6 @@ module Homebrew @name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1] end end - update_path @version = if @version Version.new(@version) else @@ -42,12 +41,6 @@ module Homebrew end end - def update_path - return if @name.nil? || @tap.nil? - - @path = @tap.new_formula_path(@name) - end - def fetch? !args.no_fetch? end @@ -57,6 +50,7 @@ module Homebrew end def generate! + path = @tap.new_formula_path(@name) raise "#{path} already exists" if path.exist? if version.nil? || version.null? @@ -86,6 +80,7 @@ module Homebrew path.dirname.mkpath path.write ERB.new(template, trim_mode: ">").result(binding) + path end sig { returns(String) }