Class: Homebrew::Bundle::Uv Private
- Inherits:
-
Extension
- Object
- Checker::Base
- Extension
- Homebrew::Bundle::Uv
- Defined in:
- bundle/extensions/uv.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Constant Summary collapse
- WithOptions =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { T::Hash[Symbol, T::Array[String]] }
- Tool =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { { name: String, with: T::Array[String] } }
- Checkable =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { { name: String, options: WithOptions } }
- ToolEntry =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { T.any(Tool, Checkable) }
- PACKAGE_TYPE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:uv- PACKAGE_TYPE_NAME =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"uv Tool"- BANNER_NAME =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"uv tools"
Constants inherited from Extension
Class Method Summary collapse
- .continuation_constraint?(requirement) ⇒ Boolean private
- .dump_name(package) ⇒ String private
- .dump_with(package) ⇒ Array<String>? private
- .entry(name, options = {}) ⇒ Dsl::Entry private
- .install_package!(name, with: nil, verbose: false) ⇒ Boolean private
- .installed_packages ⇒ Array<Tool> private
- .name_with_extras(name, extras_raw) ⇒ String private
- .normalize_constraint(requirement) ⇒ String private
- .normalize_name(name) ⇒ String private
- .normalize_with(with) ⇒ Array<String> private
- .normalized_options(name, with:) ⇒ Tool private
- .package_name(package) ⇒ String private
- .package_record(name, with: nil) ⇒ Object private
- .package_with(package) ⇒ Array<String>? private
- .packages ⇒ Array<Tool> private
- .parse_tool_list(output) ⇒ Array<Tool> private
- .parse_with_requirements(with_raw) ⇒ Array<String> private
- .reset! ⇒ void private
Instance Method Summary collapse
Methods inherited from Extension
add_supported?, banner_name, check, check_label, cleanup!, cleanup_heading, cleanup_items, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_supported?, #failure_reason, flag, inherited, install!, install_supported?, #installed_and_up_to_date?, package_description, package_installed?, package_manager_executable, package_manager_installed?, package_manager_name, predicate_method, preinstall!, quote, remove_supported?, switch_description, type
Methods inherited from Checker::Base
#checkable_entries, #exit_early_check, #failure_reason, #find_actionable, #full_check, #installed_and_up_to_date?
Class Method Details
.continuation_constraint?(requirement) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
154 155 156 |
# File 'bundle/extensions/uv.rb', line 154 def continuation_constraint?(requirement) requirement.match?(/\A(?:<=|>=|!=|==|~=|<|>)\s*\S/) end |
.dump_name(package) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
59 60 61 |
# File 'bundle/extensions/uv.rb', line 59 def dump_name(package) package_name(T.cast(package, ToolEntry)) end |
.dump_with(package) ⇒ Array<String>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
64 65 66 |
# File 'bundle/extensions/uv.rb', line 64 def dump_with(package) package_with(T.cast(package, ToolEntry)) end |
.entry(name, options = {}) ⇒ Dsl::Entry
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'bundle/extensions/uv.rb', line 20 def entry(name, = {}) = .keys - [:with] raise "unknown options(#{.inspect}) for uv" if .present? with = [:with] if !with.nil? && (!with.is_a?(Array) || with.any? { |requirement| !requirement.is_a?(String) }) raise "options[:with](#{with.inspect}) should be an Array of String objects" end = {} normalized_with = normalize_with(with || []) [:with] = normalized_with if normalized_with.present? Dsl::Entry.new(:uv, name, ) end |
.install_package!(name, with: nil, verbose: false) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'bundle/extensions/uv.rb', line 75 def install_package!(name, with: nil, verbose: false) uv = package_manager_executable return false if uv.nil? args = ["tool", "install", name] normalize_with(with || []).each do |requirement| args << "--with" args << requirement end Bundle.system(uv.to_s, *args, verbose:) end |
.installed_packages ⇒ Array<Tool>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
89 90 91 92 93 94 |
# File 'bundle/extensions/uv.rb', line 89 def installed_packages installed_packages = @installed_packages return installed_packages if installed_packages @installed_packages = packages.dup end |
.name_with_extras(name, extras_raw) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
122 123 124 125 126 127 128 129 |
# File 'bundle/extensions/uv.rb', line 122 def name_with_extras(name, extras_raw) return name if extras_raw.blank? extras = extras_raw.split(",").map(&:strip).reject(&:empty?).uniq.sort return name if extras.empty? "#{name}[#{extras.join(",")}]" end |
.normalize_constraint(requirement) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
160 161 162 |
# File 'bundle/extensions/uv.rb', line 160 def normalize_constraint(requirement) requirement.strip.sub(/\A(<=|>=|!=|==|~=|<|>)\s+/, "\\1") end |
.normalize_name(name) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'bundle/extensions/uv.rb', line 172 def normalize_name(name) match = name.strip.match(/\A(?<base>[^\[\]]+)(?:\[(?<extras>[^\]]+)\])?\z/) return name.strip unless match base = match[:base] return name.strip if base.nil? extras_raw = match[:extras] return base.strip if extras_raw.blank? extras = extras_raw.split(",").map(&:strip).reject(&:empty?).uniq.sort return base.strip if extras.empty? "#{base.strip}[#{extras.join(",")}]" end |
.normalize_with(with) ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
166 167 168 |
# File 'bundle/extensions/uv.rb', line 166 def normalize_with(with) with.map(&:strip).reject(&:empty?).uniq.sort end |
.normalized_options(name, with:) ⇒ Tool
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
195 196 197 198 199 200 |
# File 'bundle/extensions/uv.rb', line 195 def (name, with:) { name: normalize_name(name), with: normalize_with(with), } end |
.package_name(package) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
204 205 206 |
# File 'bundle/extensions/uv.rb', line 204 def package_name(package) package[:name] end |
.package_record(name, with: nil) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
190 191 192 |
# File 'bundle/extensions/uv.rb', line 190 def package_record(name, with: nil) (name, with: with || []) end |
.package_with(package) ⇒ Array<String>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
210 211 212 213 214 215 216 |
# File 'bundle/extensions/uv.rb', line 210 def package_with(package) if package.key?(:with) package[:with] else package[:options].fetch(:with, []) end end |
.packages ⇒ Array<Tool>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'bundle/extensions/uv.rb', line 43 def packages packages = @packages return packages if packages @packages = if Bundle.uv_installed? uv = Bundle.which_uv return [] if uv.nil? output = `#{uv} tool list --show-with --show-extras 2>/dev/null` parse_tool_list(output) else [] end end |
.parse_tool_list(output) ⇒ Array<Tool>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'bundle/extensions/uv.rb', line 97 def parse_tool_list(output) entries = T.let([], T::Array[Tool]) output.each_line do |line| match = line.match(/\A(\S+)\s+v\S+/) next unless match name = match[1] next if name.nil? extras_raw = line[/\[extras:\s*([^\]]+)\]/, 1] name = name_with_extras(name, extras_raw) with_raw = line[/\[with:\s*([^\]]+)\]/, 1] entries << { name: name, with: parse_with_requirements(with_raw), } end entries.sort_by { |entry| entry[:name].to_s } end |
.parse_with_requirements(with_raw) ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'bundle/extensions/uv.rb', line 133 def parse_with_requirements(with_raw) return [] if with_raw.blank? entries = T.let([], T::Array[String]) with_raw.split(", ").each do |token| requirement = token.strip next if requirement.empty? if continuation_constraint?(requirement) && entries.any? last_requirement = entries.pop entries << "#{last_requirement}, #{normalize_constraint(requirement)}" if last_requirement else entries << requirement end end entries.uniq.sort end |
.reset! ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
37 38 39 40 |
# File 'bundle/extensions/uv.rb', line 37 def reset! @packages = T.let(nil, T.nilable(T::Array[Tool])) @installed_packages = T.let(nil, T.nilable(T::Array[Tool])) end |
Instance Method Details
#format_checkable(entries) ⇒ Array<Object>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'bundle/extensions/uv.rb', line 221 def format_checkable(entries) checkable_entries(entries).map do |entry| entry = T.cast(entry, Dsl::Entry) with = if entry..is_a?(Hash) value = entry.[:with] value.is_a?(Array) ? value : [] else [] end self.class.package_record(entry.name, with:) end end |