| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  | # Helper functions for updating PyPI resources. | 
					
						
							| 
									
										
										
										
											2020-08-26 09:39:51 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | module PyPI | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/" | 
					
						
							| 
									
										
										
										
											2020-08-26 09:39:51 +02:00
										 |  |  |   private_constant :PYTHONHOSTED_URL_PREFIX | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @pipgrip_installed = nil | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |   # PyPI Package | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # @api private | 
					
						
							|  |  |  |   class Package | 
					
						
							|  |  |  |     extend T::Sig | 
					
						
							| 
									
										
										
										
											2020-07-31 10:10:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     attr_accessor :name | 
					
						
							|  |  |  |     attr_accessor :extras | 
					
						
							|  |  |  |     attr_accessor :version | 
					
						
							| 
									
										
										
										
											2020-07-31 10:10:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     sig { params(package_string: String, is_url: T::Boolean).void } | 
					
						
							|  |  |  |     def initialize(package_string, is_url: false) | 
					
						
							|  |  |  |       @pypi_info = nil | 
					
						
							| 
									
										
										
										
											2020-07-31 10:10:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |       if is_url | 
					
						
							|  |  |  |         unless package_string.start_with?(PYTHONHOSTED_URL_PREFIX) && | 
					
						
							|  |  |  |                match = File.basename(package_string).match(/^(.+)-([a-z\d.]+?)(?:.tar.gz|.zip)$/) | 
					
						
							|  |  |  |           raise ArgumentError, "package should be a valid PyPI url" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-07-31 10:10:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |         @name = match[1] | 
					
						
							|  |  |  |         @version = match[2] | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @name = package_string | 
					
						
							|  |  |  |       @name, @version = @name.split("==") if @name.include? "==" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return unless match = @name.match(/^(.*?)\[(.+)\]$/) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @name = match[1] | 
					
						
							|  |  |  |       @extras = match[2].split "," | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get name, URL, SHA-256 checksum, and latest version for a given PyPI package. | 
					
						
							|  |  |  |     sig { params(version: T.nilable(T.any(String, Version))).returns(T.nilable(T::Array[String])) } | 
					
						
							|  |  |  |     def pypi_info(version: nil) | 
					
						
							|  |  |  |       return @pypi_info if @pypi_info.present? && version.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       version ||= @version | 
					
						
							|  |  |  |       metadata_url = if version.present? | 
					
						
							|  |  |  |         "https://pypi.org/pypi/#{@name}/#{version}/json" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         "https://pypi.org/pypi/#{@name}/json" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       out, _, status = curl_output metadata_url, "--location" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return unless status.success? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         json = JSON.parse out | 
					
						
							|  |  |  |       rescue JSON::ParserError | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sdist = json["urls"].find { |url| url["packagetype"] == "sdist" } | 
					
						
							|  |  |  |       return json["info"]["name"] if sdist.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @pypi_info = [json["info"]["name"], sdist["url"], sdist["digests"]["sha256"], json["info"]["version"]] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(T::Boolean) } | 
					
						
							|  |  |  |     def valid_pypi_package? | 
					
						
							|  |  |  |       info = pypi_info | 
					
						
							|  |  |  |       info.present? && info.is_a?(Array) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(String) } | 
					
						
							|  |  |  |     def to_s | 
					
						
							|  |  |  |       out = @name | 
					
						
							|  |  |  |       out += "[#{@extras.join(",")}]" if @extras.present? | 
					
						
							|  |  |  |       out += "==#{@version}" if @version.present? | 
					
						
							|  |  |  |       out | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     sig { params(other: Package).returns(T::Boolean) } | 
					
						
							|  |  |  |     def same_package?(other) | 
					
						
							| 
									
										
										
										
											2020-11-29 13:54:13 -05:00
										 |  |  |       @name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero? | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     # Compare only names so we can use .include? on a Package array | 
					
						
							|  |  |  |     sig { params(other: Package).returns(T::Boolean) } | 
					
						
							|  |  |  |     def ==(other) | 
					
						
							|  |  |  |       same_package?(other) | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     sig { params(other: Package).returns(T.nilable(Integer)) } | 
					
						
							|  |  |  |     def <=>(other) | 
					
						
							|  |  |  |       @name <=> other.name | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-07-31 14:21:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |   sig { params(url: String, version: T.any(String, Version)).returns(T.nilable(String)) } | 
					
						
							|  |  |  |   def update_pypi_url(url, version) | 
					
						
							|  |  |  |     package = Package.new url, is_url: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-03 15:00:30 -05:00
										 |  |  |     return unless package.valid_pypi_package? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     _, url = package.pypi_info(version: version) | 
					
						
							|  |  |  |     url | 
					
						
							| 
									
										
										
										
											2020-12-03 15:00:30 -05:00
										 |  |  |   rescue ArgumentError | 
					
						
							|  |  |  |     nil | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  |   # Return true if resources were checked (even if no change). | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |   sig do | 
					
						
							|  |  |  |     params( | 
					
						
							|  |  |  |       formula:                  Formula, | 
					
						
							|  |  |  |       version:                  T.nilable(String), | 
					
						
							|  |  |  |       package_name:             T.nilable(String), | 
					
						
							|  |  |  |       extra_packages:           T.nilable(T::Array[String]), | 
					
						
							|  |  |  |       exclude_packages:         T.nilable(T::Array[String]), | 
					
						
							| 
									
										
										
										
											2020-11-29 22:36:40 +01:00
										 |  |  |       print_only:               T.nilable(T::Boolean), | 
					
						
							|  |  |  |       silent:                   T.nilable(T::Boolean), | 
					
						
							|  |  |  |       ignore_non_pypi_packages: T.nilable(T::Boolean), | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     ).returns(T.nilable(T::Boolean)) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |   def update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil, exclude_packages: nil, | 
					
						
							|  |  |  |                                print_only: false, silent: false, ignore_non_pypi_packages: false) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 16:52:29 -05:00
										 |  |  |     auto_update_list = formula.tap&.pypi_formula_mappings | 
					
						
							| 
									
										
										
										
											2020-11-20 01:55:34 -05:00
										 |  |  |     if auto_update_list.present? && auto_update_list.key?(formula.full_name) && | 
					
						
							|  |  |  |        package_name.blank? && extra_packages.blank? && exclude_packages.blank? | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       list_entry = auto_update_list[formula.full_name] | 
					
						
							|  |  |  |       case list_entry | 
					
						
							|  |  |  |       when false | 
					
						
							| 
									
										
										
										
											2020-11-20 01:55:34 -05:00
										 |  |  |         unless print_only | 
					
						
							|  |  |  |           odie "The resources for \"#{formula.name}\" need special attention. Please update them manually." | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |       when String | 
					
						
							|  |  |  |         package_name = list_entry | 
					
						
							|  |  |  |       when Hash | 
					
						
							|  |  |  |         package_name = list_entry["package_name"] | 
					
						
							|  |  |  |         extra_packages = list_entry["extra_packages"] | 
					
						
							|  |  |  |         exclude_packages = list_entry["exclude_packages"] | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-31 16:42:53 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     main_package = if package_name.present? | 
					
						
							|  |  |  |       Package.new(package_name) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         Package.new(formula.stable.url, is_url: true) | 
					
						
							|  |  |  |       rescue ArgumentError | 
					
						
							|  |  |  |         nil | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     if main_package.blank? | 
					
						
							| 
									
										
										
										
											2020-09-15 12:12:47 -07:00
										 |  |  |       return if ignore_non_pypi_packages | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       odie <<~EOS | 
					
						
							|  |  |  |         Could not infer PyPI package name from URL: | 
					
						
							|  |  |  |           #{Formatter.url(formula.stable.url)} | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     unless main_package.valid_pypi_package? | 
					
						
							|  |  |  |       return if ignore_non_pypi_packages | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |       odie "\"#{main_package}\" is not available on PyPI." | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     main_package.version = version if version.present? | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     extra_packages = (extra_packages || []).map { |p| Package.new p } | 
					
						
							|  |  |  |     exclude_packages = (exclude_packages || []).map { |p| Package.new p } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     input_packages = [main_package] | 
					
						
							|  |  |  |     extra_packages.each do |extra_package| | 
					
						
							|  |  |  |       if !extra_package.valid_pypi_package? && !ignore_non_pypi_packages | 
					
						
							|  |  |  |         odie "\"#{extra_package}\" is not available on PyPI." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       input_packages.each do |existing_package| | 
					
						
							|  |  |  |         if existing_package.same_package?(extra_package) && existing_package.version != extra_package.version | 
					
						
							|  |  |  |           odie "Conflicting versions specified for the `#{extra_package.name}` package: "\ | 
					
						
							|  |  |  |                 "#{existing_package.version}, #{extra_package.version}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |       input_packages << extra_package unless input_packages.include? extra_package | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     formula.resources.each do |resource| | 
					
						
							|  |  |  |       if !print_only && !resource.url.start_with?(PYTHONHOSTED_URL_PREFIX) | 
					
						
							|  |  |  |         odie "\"#{formula.name}\" contains non-PyPI resources. Please update the resources manually." | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 16:56:21 +01:00
										 |  |  |     @pipgrip_installed ||= Formula["pipgrip"].any_version_installed? | 
					
						
							|  |  |  |     odie '"pipgrip" must be installed (`brew install pipgrip`)' unless @pipgrip_installed | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     found_packages = [] | 
					
						
							|  |  |  |     input_packages.each do |package| | 
					
						
							|  |  |  |       ohai "Retrieving PyPI dependencies for \"#{package}\"..." if !print_only && !silent | 
					
						
							|  |  |  |       pipgrip_output = Utils.popen_read Formula["pipgrip"].bin/"pipgrip", "--json", "--no-cache-dir", package.to_s | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |       unless $CHILD_STATUS.success? | 
					
						
							|  |  |  |         odie <<~EOS | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |           Unable to determine dependencies for \"#{package}\" because of a failure when running
 | 
					
						
							|  |  |  |           `pipgrip --json --no-cache-dir #{package}`. | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |           Please update the resources for \"#{formula.name}\" manually.
 | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |       JSON.parse(pipgrip_output).to_h.each do |new_name, new_version| | 
					
						
							|  |  |  |         new_package = Package.new("#{new_name}==#{new_version}") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         found_packages.each do |existing_package| | 
					
						
							|  |  |  |           if existing_package.same_package?(new_package) && existing_package.version != new_package.version | 
					
						
							|  |  |  |             odie "Conflicting versions found for the `#{new_package.name}` resource: "\ | 
					
						
							|  |  |  |                  "#{existing_package.version}, #{new_package.version}" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |         found_packages << new_package unless found_packages.include? new_package | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |     # Remove extra packages that may be included in pipgrip output | 
					
						
							| 
									
										
										
										
											2020-11-29 13:12:09 -05:00
										 |  |  |     exclude_list = %W[#{main_package.name} argparse pip setuptools wheel wsgiref].map { |p| Package.new p } | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |     found_packages.delete_if { |package| exclude_list.include? package } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |     new_resource_blocks = "" | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |     found_packages.sort.each do |package| | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |       if exclude_packages.include? package | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |         ohai "Excluding \"#{package}\"" if !print_only && !silent | 
					
						
							| 
									
										
										
										
											2020-11-18 02:25:55 -05:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:23:43 -05:00
										 |  |  |       ohai "Getting PyPI info for \"#{package}\"" if !print_only && !silent | 
					
						
							|  |  |  |       name, url, checksum = package.pypi_info | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |       # Fail if unable to find name, url or checksum for any resource | 
					
						
							|  |  |  |       if name.blank? | 
					
						
							|  |  |  |         odie "Unable to resolve some dependencies. Please update the resources for \"#{formula.name}\" manually." | 
					
						
							|  |  |  |       elsif url.blank? || checksum.blank? | 
					
						
							|  |  |  |         odie <<~EOS | 
					
						
							|  |  |  |           Unable to find the URL and/or sha256 for the \"#{name}\" resource.
 | 
					
						
							|  |  |  |           Please update the resources for \"#{formula.name}\" manually.
 | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Append indented resource block | 
					
						
							|  |  |  |       new_resource_blocks += <<-EOS
 | 
					
						
							|  |  |  |   resource "#{name}" do | 
					
						
							|  |  |  |     url "#{url}" | 
					
						
							|  |  |  |     sha256 "#{checksum}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if print_only | 
					
						
							|  |  |  |       puts new_resource_blocks.chomp | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 23:22:07 -04:00
										 |  |  |     # Check whether resources already exist (excluding virtualenv dependencies) | 
					
						
							|  |  |  |     if formula.resources.all? { |resource| resource.name.start_with?("homebrew-") } | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |       # Place resources above install method | 
					
						
							|  |  |  |       inreplace_regex = /  def install/ | 
					
						
							|  |  |  |       new_resource_blocks += "  def install" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       # Replace existing resource blocks with new resource blocks | 
					
						
							|  |  |  |       inreplace_regex = /  (resource .* do\s+url .*\s+sha256 .*\s+ end\s*)+/ | 
					
						
							|  |  |  |       new_resource_blocks += "  " | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ohai "Updating resource blocks" unless silent | 
					
						
							|  |  |  |     Utils::Inreplace.inreplace formula.path do |s| | 
					
						
							|  |  |  |       if s.inreplace_string.scan(inreplace_regex).length > 1
 | 
					
						
							|  |  |  |         odie "Unable to update resource blocks for \"#{formula.name}\" automatically. Please update them manually." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       s.sub! inreplace_regex, new_resource_blocks | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-17 21:35:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     true | 
					
						
							| 
									
										
										
										
											2020-07-27 10:37:46 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end |