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/aspell-dictionaries: fix typecheck failure #204347

Merged
merged 1 commit into from
Jan 15, 2025
Merged

cmd/aspell-dictionaries: fix typecheck failure #204347

merged 1 commit into from
Jan 15, 2025

Conversation

chenrui333
Copy link
Member

@chenrui333 chenrui333 commented Jan 15, 2025

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

seeing some typecheck failure as

  /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/cmd/aspell-dictionaries.rb:26: Method `split` does not exist on `SystemCommand::Result` https://srb.help/7003
      26 |        index_output.split("<tr><td>").each do |line|
                               ^^^^^
    Got `SystemCommand::Result` originating from:
      /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/cmd/aspell-dictionaries.rb:25:
      25 |        index_output, = Utils::Curl.curl_output("#{dictionary_url}/0index.html")
                  ^^^^^^^^^^^^
    Did you mean `plist`? Use `-a` to autocorrect
      /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/cmd/aspell-dictionaries.rb:26: Replace with `plist`
      26 |        index_output.split("<tr><td>").each do |line|
                               ^^^^^
      ./system_command.rb:432: Defined here
       432 |    def plist
                ^^^^^^^^^
  Errors: 1
  Check https://docs.brew.sh/Typechecking for more information on how to resolve these errors.

relates to Homebrew/brew#19077

@github-actions github-actions bot added the automerge-skip `brew pr-automerge` will skip this pull request label Jan 15, 2025
Copy link
Member

@samford samford left a comment

Choose a reason for hiding this comment

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

Thanks! I did a quick search and it looks like this is the only use of a Utils::Curl method in homebrew/core.

@chenrui333 chenrui333 enabled auto-merge January 15, 2025 14:26
@chenrui333 chenrui333 requested a review from samford January 15, 2025 14:26
@chenrui333 chenrui333 marked this pull request as draft January 15, 2025 14:31
auto-merge was automatically disabled January 15, 2025 14:31

Pull request was converted to draft

cmd/aspell-dictionaries.rb Outdated Show resolved Hide resolved
@chenrui333 chenrui333 marked this pull request as ready for review January 15, 2025 14:37
@samford
Copy link
Member

samford commented Jan 15, 2025

How this command handles parsing seems a bit fragile (it may break if the HTML slightly changes). One moment and I'll see if I can improve this (without using T.must).

Edit: I ended up with one T.must call but only because Sorbet doesn't distinguish between required and optional capture groups in regex matches. Values for required capture groups will always exist if the regex matches but Sorbet can't understand that, so you have to either use T.must or handle the values as if it's possible for them to be nil.

@chenrui333
Copy link
Member Author

that works for me 👍

We recently upgraded `utils/curl` to `typed: strict`, which required
us to rework how we handle the return type from some curl methods.
I overlooked tap commands, so this fixes a related Sorbet error.

Co-authored-by: Rui Chen <[email protected]>
@samford
Copy link
Member

samford commented Jan 15, 2025

I spent more time on this than necessary but I reworked the language-finding logic to use a regex, extracting the language and path information from the href attributes that we want. The path URL contains the language (as the directory name), so we can capture both values from the href attribute (i.e., no need to check multiple table cells). You can see this in my branch here: https://github.com/samford/homebrew-core/commits/rework-aspell-dictionaries/

This minimizes our reliance on an overly-specific HTML structure and it uses case-insensitive matching, so it will continue to work if the capitalization of HTML tags/attributes changes or the table cell order changes.

We can technically match within href attributes without worrying about table cells at all (i.e., omitting the leading <td[^>]*?>.* from the regex) but there's one link on the page with a .txt extension that can match if we're not strict about the tarball filename format (or extension). I've made the regex strict enough that it works without matching table cells but I've left that in for now. If we run into issues in the future, it's easy to make changes to the regex with this setup.

The new approach can still fail if the file type changes to something other than a tarball or if the path changes in a way that the regex won't match (or handle correctly). It's not perfect but this approach may be less brittle than the existing logic.

Besides that, I made some changes to raise on error conditions instead of quietly failing with no indication of what went wrong.

If you're good with this approach, feel free to pull the commits from my branch or I can push them here. The first commit covers minimal changes that are necessary here for brew typecheck to past and the other two are refactoring/improvements.

@chenrui333
Copy link
Member Author

yeah, I would just think we should get the CI unblocked first and then do a followup PR on the rework, what do you think?

@samford
Copy link
Member

samford commented Jan 15, 2025

I would just think we should get the CI unblocked first and then do a followup PR on the rework

The rework may need some review, so that makes sense to me 👍

@chenrui333 chenrui333 enabled auto-merge January 15, 2025 17:38
@chenrui333 chenrui333 added this pull request to the merge queue Jan 15, 2025
Merged via the queue into master with commit 781916d Jan 15, 2025
17 checks passed
@chenrui333 chenrui333 deleted the typecheck branch January 15, 2025 17:43
@chenrui333 chenrui333 restored the typecheck branch January 15, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge-skip `brew pr-automerge` will skip this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants