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

tap: allow sharding of fonts in Homebrew/cask #17239

Closed
wants to merge 1 commit into from

Conversation

p-linnane
Copy link
Member

  • 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?

We want to migrate Homebrew/cask-fonts into the main Homebrew/cask repo. There are ~2,200 font casks that need to be put into sharded subdirectories. This PR allows for paths such as Casks/fonts/font-a/font-apple.rb.

Library/Homebrew/tap.rb Outdated Show resolved Hide resolved
Library/Homebrew/tap.rb Outdated Show resolved Hide resolved
Library/Homebrew/tap.rb Outdated Show resolved Hide resolved
Signed-off-by: Patrick Linnane <patrick@linnane.io>

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
@krehel
Copy link
Member

krehel commented May 9, 2024

Throwing a comment here to poll the group. I made similar changes that is more code, but don't need to rename Casks. Not sure I like it though.

Effectively a new def in tap.rb for font paths specifc rather than using the existing new_cask_path def. This can be shortened for brevity.

  def new_font_path(token)
    font_first_letter = token.split("-").second[0].to_s
    cask_subdir = "fonts/font-#{token.split("-").second[0].to_s}"
    cask_dir/cask_subdir/"#{token.downcase}.rb"
  end

Then in cask/audit.rb, updated the path audit to check explicitly for font artifacts:

 def audit_cask_path
  return unless cask.tap.core_cask_tap?

  expected_path = if cask.artifacts.none? { |k| k.is_a?(Artifact::Font) }
                    cask.tap.new_cask_path(cask.token)
                  else
                    cask.tap.new_font_path(cask.token)
                  end

  return if cask.sourcefile_path.to_s.end_with?(expected_path)

  add_error "Cask should be located in '#{expected_path}'"
end

If there's a better way I could've shared these changes please let me know! I didn't want to open a competing PR and I didn't want to clobber the existing PR.

@p-linnane
Copy link
Member Author

@krehel Can you benchmark your proposal? Want to see how it affects performance.

@krehel
Copy link
Member

krehel commented May 9, 2024

I did locally with hyperfine. I saw no difference.

Edit, fwiw:

My changes:

> hyperfine --warmup 5 "brew audit --only cask_path visual-studio-code"
Benchmark 1: brew audit --only cask_path visual-studio-code
  Time (mean ± σ):      2.535 s ±  0.016 s    [User: 1.896 s, System: 0.515 s]
  Range (min … max):    2.518 s …  2.570 s    10 runs


> hyperfine --warmup 5 "brew audit --only cask_path font-3270"
Benchmark 1: brew audit --only cask_path font-3270
  Time (mean ± σ):      2.562 s ±  0.031 s    [User: 1.915 s, System: 0.520 s]
  Range (min … max):    2.538 s …  2.644 s    10 runs

This PR:

> hyperfine --warmup 5 "brew audit --only cask_path visual-studio-code"
Benchmark 1: brew audit --only cask_path visual-studio-code
  Time (mean ± σ):      2.564 s ±  0.031 s    [User: 1.912 s, System: 0.519 s]
  Range (min … max):    2.531 s …  2.611 s    10 runs

> hyperfine --warmup 5 "brew audit --only cask_path font-3270"
Benchmark 1: brew audit --only cask_path font-3270
  Time (mean ± σ):      2.585 s ±  0.075 s    [User: 1.932 s, System: 0.518 s]
  Range (min … max):    2.506 s …  2.748 s    10 runs

@p-linnane
Copy link
Member Author

@carlocab @MikeMcQuaid If you can weigh in on the above it would be appreciated. I want to make sure we're using the right approach here.

@krehel
Copy link
Member

krehel commented May 9, 2024

Indeed. Feel free to tell me it's terrible or not 😄 (also: I am genuinely curious which is preferred)

@reitermarkus
Copy link
Member

reitermarkus commented May 9, 2024

As I said in Homebrew/homebrew-cask#173366 (comment), I'm against disallowing normal casks to start with font-, so I think basing this on the actual artifacts rather than the cask name, as @krehel suggested, is the better approach.

@p-linnane
Copy link
Member Author

Sounds good. @krehel I'm going to close this and the cask PR. Can you open a PR with your proposed change? Thanks!

@p-linnane p-linnane closed this May 9, 2024
@p-linnane p-linnane deleted the tap-shard-fonts branch May 9, 2024 23:10
@krehel
Copy link
Member

krehel commented May 10, 2024

@p-linnane will do. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants