Module: Homebrew::Bundle::UvDumper Private

Defined in:
bundle/uv_dumper.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.build_entry(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.

Parameters:

Returns:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'bundle/uv_dumper.rb', line 95

def self.build_entry(package)
  name = T.cast(package[:name], String)
  with = T.cast(package[:with], T::Array[String])

  line = "uv #{quote(name)}"
  options = []
  if with.present?
    formatted_with = with.map { |requirement| quote(requirement) }.join(", ")
    options << "with: [#{formatted_with}]"
  end
  return line if options.empty?

  "#{line}, #{options.join(", ")}"
end

.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.

Parameters:

Returns:

  • (Boolean)


85
86
87
# File 'bundle/uv_dumper.rb', line 85

def self.continuation_constraint?(requirement)
  requirement.match?(/\A(?:<=|>=|!=|==|~=|<|>)\s*\S/)
end

.dumpString

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.

Returns:



25
26
27
28
29
# File 'bundle/uv_dumper.rb', line 25

def self.dump
  packages.map do |package|
    build_entry(package)
  end.join("\n")
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.

Parameters:

Returns:



56
57
58
59
60
61
62
63
# File 'bundle/uv_dumper.rb', line 56

def self.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.

Parameters:

Returns:



90
91
92
# File 'bundle/uv_dumper.rb', line 90

def self.normalize_constraint(requirement)
  requirement.strip.sub(/\A(<=|>=|!=|==|~=|<|>)\s+/, "\\1")
end

.packagesArray<Hash{Symbol => T.untyped}>

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.

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'bundle/uv_dumper.rb', line 13

def self.packages
  @packages ||= T.let(nil, T.nilable(T::Array[T::Hash[Symbol, T.untyped]]))
  @packages ||= if Bundle.uv_installed?
    uv = Bundle.which_uv
    output = `#{uv} tool list --show-with --show-extras 2>/dev/null`
    parse_tool_list(output)
  else
    []
  end
end

.parse_tool_list(output) ⇒ Array<Hash{Symbol => T.untyped}>

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.

Parameters:

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'bundle/uv_dumper.rb', line 32

def self.parse_tool_list(output)
  entries = T.let([], T::Array[T::Hash[Symbol, T.untyped]])

  output.each_line do |line|
    match = line.match(/\A(\S+)\s+v\S+/)
    next unless match

    name = T.must(match[1])
    extras_raw = line[/\[extras:\s*([^\]]+)\]/, 1]
    name = name_with_extras(name, extras_raw)
    with_raw = line[/\[with:\s*([^\]]+)\]/, 1]

    with = parse_with_requirements(with_raw)

    entries << {
      name: name,
      with: with,
    }
  end

  entries.sort_by { |entry| T.cast(entry[:name], String) }
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.

Parameters:

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'bundle/uv_dumper.rb', line 66

def self.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?
      entries[-1] = "#{T.must(entries.last)}, #{normalize_constraint(requirement)}"
    else
      entries << requirement
    end
  end

  entries.uniq.sort
end

.quote(value) ⇒ 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.

Parameters:

Returns:



111
112
113
# File 'bundle/uv_dumper.rb', line 111

def self.quote(value)
  value.inspect
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.



8
9
10
# File 'bundle/uv_dumper.rb', line 8

def self.reset!
  @packages = nil
end