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

Refactor CaskLoader::for. #16609

Merged
merged 6 commits into from Feb 8, 2024
Merged

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Feb 7, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Revert #16608 and refactor CaskLoader::for to use the same logic for full and short names, which hopefully also fixes #16607 properly.

Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

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

I left a bunch of nits but of course you can ignore those. Other than the use of Tap#ensure_installed! that I'm a bit worried about this looks very good and helps clean up a lot of the code.

Library/Homebrew/cask/cask_loader.rb Show resolved Hide resolved
Comment on lines 52 to +53
class FromContentLoader < AbstractContentLoader
def self.can_load?(ref)
def self.try_new(ref, warn: false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach but I am 50/50 on the name. I don't have any better ideas though.

Would this approach make it easier to streamline formula loading as well? The current #can_load? style logic doesn't really work well for formulae since we need a bunch of workarounds and extra checks when deciding what to load.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I hope we can use the same pattern for formulae as well.

Comment on lines -72 to +75
@content = content.force_encoding("UTF-8")
@content = content.dup.force_encoding("UTF-8")
Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt the String#dup is really necessary here. Are we relying on the original string encoding anywhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some tests were failing here because they pass in string literals. It is surprising that this is necessary only now though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, we were only testing can_load? before, not the constructor.

Comment on lines 54 to +56
return false unless ref.respond_to?(:to_str)

content = ref.to_str
content = T.unsafe(ref).to_str
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit surprised that Sorbet can't figure this one out. sigh

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, unfortunate, but it does make sense: https://sorbet.org/docs/flow-sensitive#what-about-respond_to

You cannot deduce a type by its methods alone. We could just use is_a?(String) here though, because anything else doesn't make sense anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way is fine for me. Thanks for explaining it to me.

Library/Homebrew/cask/cask_loader.rb Show resolved Hide resolved
Library/Homebrew/cask/cask_loader.rb Outdated Show resolved Hide resolved
Library/Homebrew/cask/cask_loader.rb Show resolved Hide resolved
Library/Homebrew/cask/cask_loader.rb Outdated Show resolved Hide resolved
Co-authored-by: Kevin <apainintheneck@gmail.com>
reitermarkus and others added 2 commits February 7, 2024 14:02
Co-authored-by: Kevin <apainintheneck@gmail.com>
Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

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

Looks good to me now, thanks!

Comment on lines 54 to +56
return false unless ref.respond_to?(:to_str)

content = ref.to_str
content = T.unsafe(ref).to_str
Copy link
Contributor

Choose a reason for hiding this comment

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

Either way is fine for me. Thanks for explaining it to me.

@reitermarkus reitermarkus merged commit c9934ef into Homebrew:master Feb 8, 2024
24 checks passed
@reitermarkus reitermarkus deleted the cask-loader-for branch February 8, 2024 10:43
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 10, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Brew search returns "invalid tap name"
3 participants