Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula_creator: Remove path attr to reduce code complexity #16244

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ def create_formula(args:)
end
end

fc.generate!
path = fc.generate!

formula = Homebrew.with_no_api_env do
Formula[fc.name]
end
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
Expand Down
11 changes: 3 additions & 8 deletions Library/Homebrew/formula_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,20 +34,13 @@ def url=(url)
@name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1]
end
end
update_path
@version = if @version
Version.new(@version)
else
Version.detect(url)
end
end

def update_path
return if @name.nil? || @tap.nil?

@path = @tap.new_formula_path(@name)
end

def fetch?
!args.no_fetch?
end
Expand All @@ -57,6 +50,7 @@ def head?
end

def generate!
abitrolly marked this conversation as resolved.
Show resolved Hide resolved
path = @tap.new_formula_path(@name)
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
raise "#{path} already exists" if path.exist?

if version.nil? || version.null?
Expand Down Expand Up @@ -86,6 +80,7 @@ def generate!

path.dirname.mkpath
path.write ERB.new(template, trim_mode: ">").result(binding)
path
end

sig { returns(String) }
Expand Down
Loading