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

cmd/info: show size information #18172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
switch "--github",
description: "Open the GitHub source page for <formula> and <cask> in a browser. " \
"To view the history locally: `brew log -p` <formula> or <cask>"
switch "--github-manifest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with --json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. Haven't had time to look at that code path. Also need to figure out the path to get information to formulae.brew.sh, which may be similar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, it's that code path. If it doesn't work for now: might be worth marking as conflicting?

description: "Fetch Github package manifest for extra information when <formula> is not installed."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: "Fetch Github package manifest for extra information when <formula> is not installed."
description: "Fetch GitHub package manifest for extra information when <formula> is not installed."

flag "--json",
description: "Print a JSON representation. Currently the default value for <version> is `v1` for " \
"<formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the " \
Expand Down Expand Up @@ -303,6 +305,17 @@
]
if kegs.empty?
puts "Not installed"
if args.github_manifest? && !(bottle = formula.bottle).nil?
begin
bottle.fetch_tab(quiet: !args.debug?)
bottle_size = bottle.bottle_size

Check warning on line 311 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L311

Added line #L311 was not covered by tests
puts "Bottle size: #{disk_usage_readable(bottle_size)}" if bottle_size.positive?
installed_size = bottle.installed_size

Check warning on line 313 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L313

Added line #L313 was not covered by tests
puts "Installed size: #{disk_usage_readable(installed_size)}" if installed_size.positive?
Comment on lines +311 to +314
Copy link
Member Author

@cho-m cho-m Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently looks like

Bottle size: 5MB
Installed size: 16.0MB

For comparison

Also, mainly an approximate if pouring bottle into non-standard prefix.

rescue RuntimeError => e
odebug e

Check warning on line 316 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L316

Added line #L316 was not covered by tests
end
end
else
puts "Installed"
kegs.each do |keg|
Expand Down
11 changes: 9 additions & 2 deletions Library/Homebrew/downloadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ def downloader
end
end

sig { params(verify_download_integrity: T::Boolean, timeout: T.nilable(T.any(Integer, Float))).returns(Pathname) }
def fetch(verify_download_integrity: true, timeout: nil)
sig {
params(
verify_download_integrity: T::Boolean,
timeout: T.nilable(T.any(Integer, Float)),
quiet: T::Boolean,
).returns(Pathname)
}
def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
cache.mkpath

begin
downloader.quiet! if quiet
downloader.fetch(timeout:)
rescue ErrorDuringExecution, CurlDownloadStrategyError => e
raise DownloadError.new(self, e)
Expand Down
32 changes: 23 additions & 9 deletions Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
Partial.new(self, files)
end

def fetch(verify_download_integrity: true)
def fetch(verify_download_integrity: true, quiet: false)
fetch_patches

super
Expand Down Expand Up @@ -286,6 +286,27 @@
end

def tab
tab = manifest_annotations["sh.brew.tab"]

Check warning on line 289 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L289

Added line #L289 was not covered by tests
raise Error, "Couldn't find tab from manifest." if tab.blank?

begin
JSON.parse(tab)

Check warning on line 293 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L293

Added line #L293 was not covered by tests
rescue JSON::ParserError
raise Error, "Couldn't parse tab JSON."

Check warning on line 295 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L295

Added line #L295 was not covered by tests
end
end

def bottle_size
manifest_annotations["sh.brew.bottle.size"].to_i

Check warning on line 300 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L300

Added line #L300 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
manifest_annotations["sh.brew.bottle.size"].to_i
manifest_annotations.fetch("sh.brew.bottle.size").to_i

or

Suggested change
manifest_annotations["sh.brew.bottle.size"].to_i
manifest_annotations["sh.brew.bottle.size"]&.to_i

depending on whether manifest_annotations is supposed to always have that key.

end

def installed_size
manifest_annotations["sh.brew.bottle.installed_size"].to_i

Check warning on line 304 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L304

Added line #L304 was not covered by tests
end

private

def manifest_annotations
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe to cache?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think so?

json = begin
JSON.parse(cached_download.read)
rescue JSON::ParserError
Expand All @@ -308,14 +329,7 @@
end
raise Error, "Couldn't find manifest matching bottle checksum." if manifest_annotations.blank?

tab = manifest_annotations["sh.brew.tab"]
raise Error, "Couldn't find tab from manifest." if tab.blank?

begin
JSON.parse(tab)
rescue JSON::ParserError
raise Error, "Couldn't parse tab JSON."
end
manifest_annotations

Check warning on line 332 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L332

Added line #L332 was not covered by tests
end
end

Expand Down
18 changes: 16 additions & 2 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@
resource.downloader.stage
end

def fetch_tab
def fetch_tab(quiet: false)
return if github_packages_manifest_resource.blank?

github_packages_manifest_resource.fetch
github_packages_manifest_resource.fetch(quiet:)

Check warning on line 394 in Library/Homebrew/software_spec.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L394

Added line #L394 was not covered by tests
rescue DownloadError
raise unless fallback_on_error

Expand All @@ -410,6 +410,20 @@
github_packages_manifest_resource.tab
end

sig { returns(Integer) }
def bottle_size
return 0 unless github_packages_manifest_resource&.downloaded?

github_packages_manifest_resource.bottle_size

Check warning on line 417 in Library/Homebrew/software_spec.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L417

Added line #L417 was not covered by tests
end

sig { returns(Integer) }
def installed_size
return 0 unless github_packages_manifest_resource&.downloaded?

github_packages_manifest_resource.installed_size

Check warning on line 424 in Library/Homebrew/software_spec.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L424

Added line #L424 was not covered by tests
end

sig { returns(Filename) }
def filename
Filename.create(resource.owner, @tag, @spec.rebuild)
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/info.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.