59 Commits

Author SHA1 Message Date
Kevin Montag
06a50eaceb Lazy-load development_tools in fetch_json_api_file 2024-07-18 23:02:51 +02:00
Kevin Montag
74a84a0d12 Fix missing requires for tap-info command
Previously, running `brew tap-info --installed --json` in a github
actions linux runner would throw:

```
Error: uninitialized constant Homebrew::API
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/tap.rb:1359:in `formula_names'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/tap.rb:868:in `to_hash'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/cmd/tap-info.rb:87:in `map'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/cmd/tap-info.rb:87:in `print_tap_json'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/cmd/tap-info.rb:37:in `run'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb:95:in `<main>'
```

After the setup steps:
```
    steps:
      - name: Set up Homebrew
        id: set-up-homebrew
        uses: Homebrew/actions/setup-homebrew@master
        with:
          token: ${{ github.token }}

      - name: Cache Homebrew Bundler RubyGems
        id: cache
        uses: actions/cache@v3
        with:
          path: ${{ steps.set-up-homebrew.outputs.gems-path }}
          key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
          restore-keys: ${{ runner.os }}-rubygems-

      - name: Install Homebrew Bundler RubyGems
        if: steps.cache.outputs.cache-hit != 'true'
        run: brew install-bundler-gems
```
2024-07-16 21:19:37 +02:00
Mike McQuaid
c5dbd3ca24
Rearrange requires
This improves the load time of most brew commands. For an example of
one of the simplest commands this speeds up:

Without Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
  Time (mean ± σ):     525.0 ms ±  35.8 ms    [User: 229.9 ms, System: 113.1 ms]
  Range (min … max):   465.3 ms … 576.6 ms    10 runs

Benchmark 2: git checkout optimise_requires; brew help
  Time (mean ± σ):     383.3 ms ±  25.1 ms    [User: 133.0 ms, System: 72.1 ms]
  Range (min … max):   353.0 ms … 443.6 ms    10 runs

Summary
  git checkout optimise_requires; brew help ran
    1.37 ± 0.13 times faster than git checkout master; brew help
```

With Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
  Time (mean ± σ):     386.0 ms ±  30.9 ms    [User: 130.2 ms, System: 93.8 ms]
  Range (min … max):   359.5 ms … 469.3 ms    10 runs

Benchmark 2: git checkout optimise_requires; brew help
  Time (mean ± σ):     330.2 ms ±  32.4 ms    [User: 93.4 ms, System: 73.0 ms]
  Range (min … max):   302.9 ms … 413.9 ms    10 runs

Summary
  git checkout optimise_requires; brew help ran
    1.17 ± 0.15 times faster than git checkout master; brew help
```
2024-07-14 08:49:39 -04:00
Mike McQuaid
a408da65fc
Hide default gems warnings for Ruby 3.4.
These omit warnings with Ruby 3.3 and are required for Ruby 3.4. We'll
fix them when we're upgrading to 3.4 instead.
2024-05-17 14:42:44 +09:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
apainintheneck
200fe2a6b7 api/formula: Add tests for internal JSON v3
These tests cover both generating and loading formulae from the JSON
bundle. The tests are not comprehensive but they do provide a nice
sanity check that things are working as expected.
2024-02-27 20:55:16 -08:00
apainintheneck
d64de40e52 Update api code to load internal JSON v3 file 2024-02-27 20:55:16 -08:00
Markus Reiter
a6a6a74c48
Fix API::tap_from_source_download for relative paths. 2024-02-16 23:36:09 +01:00
Bo Anderson
1c3c64a743
api: use freeze option for JSON parsing 2024-01-09 19:07:36 +00:00
apainintheneck
984dcf8c11 API: Load casks/formula from JSON with missing keys
We'd like to reduce the size of the API JSON and to do that we are
going to remove unused and/or blank elements from the cask/formula
definition. This will reduce the amount of data that has to go
over the wire and make it easier to load this data into memory.
2024-01-01 19:10:48 -08:00
apainintheneck
b61d74f176 api: require base64
This was required previously by the `plist` gem and we were requiring
it indirectly. It got removed in v1.7.1 of that gem because it will
no longer be included in the standard library as of Ruby 3.4.

Since we're not currently running on Ruby 3.3 and 3.4 is not out yet,
we can punt on this for now but we'll need to figure out a better
alternative before upgrading to Ruby 3.4.

Related:
- https://github.com/patsplat/plist/pull/63
2023-12-27 20:04:15 -08:00
Eric Knibbe
8646b2cf1f
api: ignore HTTPS errors if minimum curl version isn't installed 2023-10-04 22:24:57 -04:00
Mike McQuaid
8ba389817f
api: retry manually without curl_args defaults.
Co-authored-by: Kevin <apainintheneck@gmail.com>
2023-09-03 09:10:25 -04:00
Mike McQuaid
d5a1f3e02c
api: use Utils::Curl.curl_args
This sets user-agent nicely and avoids some duplication.
2023-09-02 21:31:01 -04:00
Eric Knibbe
70e676c176
api: ignore HTTPS errors if required certs aren't installed 2023-08-22 17:41:46 -04:00
Mike McQuaid
27dda52a5d
Download tap_migrations.json files from the API
Download the previously stored tap migrations files for homebrew/core
and homebrew/cask from the formulae.brew.sh API.

This adds a much longer stale time (24 hours) to decide whether or not
the migrations files need downloaded from the API in Ruby land.
`brew update` will still update them every time.

Requires https://github.com/Homebrew/brew/pull/15628
Fixes https://github.com/Homebrew/brew/issues/14897
2023-07-05 17:18:12 +01:00
Bo Anderson
68289f1165
Add without_api specifier for CLI named args 2023-06-22 01:57:28 +01:00
Bo Anderson
44f058edb5
Refactor formula, cask and Ruby source downloads to use shared code 2023-04-27 23:23:07 +01:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Markus Reiter
844db75361
Add source paths to API. 2023-04-07 15:20:01 +02:00
Mike McQuaid
5631310653
Auto-update from the API less often
Instead of doing so literally whenever we query for a formula, Instead
do so only when we're in an auto-updateable command.

This better fits the existing behaviour while still updating when it's
most important to do so.
2023-03-10 17:53:15 +00:00
Nanda H Krishna
51329635d9
api: fix merge_variations 2023-03-07 14:12:41 -05:00
Nanda H Krishna
bb4f41ea43
api: fix bottle_tag identification 2023-03-07 14:12:40 -05:00
Mike McQuaid
57ef4afe57
api: improve root messaging.
Co-authored-by: Bo Anderson <mail@boanderson.me>
2023-02-23 12:48:18 +00:00
Mike McQuaid
2884b1649b
api: don't download files as root when Homebrew's not owned by root.
This was mentioned in a random comment. While we're here, make some
helper functions to query this a bit more nicely elsewhere when we do
it.
2023-02-23 10:04:50 +00:00
Bo Anderson
e663f532a6
Checksum Ruby source file downloads 2023-02-22 22:50:24 +00:00
Bo Anderson
b7d6d00c34
api: use signed endpoint 2023-02-22 21:53:32 +00:00
Mike McQuaid
853b33bcda
Merge pull request #14742 from apainintheneck/respect-quiet-with-api-downloads
api: respect --quiet
2023-02-21 09:23:07 +00:00
apainintheneck
0b3b54e75d api: respect --quiet 2023-02-20 23:23:42 -08:00
Bo Anderson
c2342eca91
Further improvements to API handling in shell 2023-02-19 05:38:13 +00:00
Bo Anderson
ab6bef261c
api: avoid unnecessary file write operation 2023-02-16 16:23:13 +00:00
Mike McQuaid
f7f04bae26
api: use formulae.brew.sh for cask-source API again.
GitHub's raw endpoint is proving hilariously unreliable for us here.
2023-02-16 12:05:38 +00:00
Douglas Eichelberger
95742f4cfd Enabling typing in Homebrew::API module 2023-02-13 21:33:04 -08:00
Rylan Polster
f7fa5937d8
Allow brew info --json=v2 without taps with JSON API 2023-02-12 12:03:40 +00:00
Mike McQuaid
75a20689b1
Add HOMEBREW_API_AUTO_UPDATE_SECS
This sets the default and allows customising how often we try to
download files from the API.

This does not affect `brew update` as we want to always check every time
on an explicit call.
2023-02-11 07:22:50 +00:00
Mike McQuaid
e301fe8fd8
brew.sh: move shared curl speed limit settings here.
This avoids duplication and potentially allows it to be used for various
other `curl` calls.
2023-02-10 17:27:10 +00:00
Bo Anderson
15c291f054
api: don't add --time-cond on retries 2023-02-09 18:26:37 +00:00
Bo Anderson
a26a2d71a8
Use --speed-time over --max-time for API downloads 2023-02-09 18:25:52 +00:00
Flier Lu
f08c1e836d increase JSON_API_MAX_TIME 2023-02-09 21:06:46 +08:00
Xuehai Pan
4322e57dd0 utils/curl: make --show-error optional 2023-02-04 13:05:41 +00:00
Xuehai Pan
ba3bccf9ed api: download from HOMEBREW_API_DOMAIN 2023-02-04 13:05:20 +00:00
Mike McQuaid
082e75e692
Merge pull request #14500 from MikeMcQuaid/remove_api_versions
api/versions: remove.
2023-02-04 13:59:43 +01:00
Mike McQuaid
9ba6aef820
api: improve exception handling. 2023-02-04 13:22:15 +01:00
Mike McQuaid
2a01529cad
api/versions: remove.
We no longer (never?) need/use these APIs so can remove them from here
and from Homebrew/formulae.brew.sh.
2023-02-04 13:09:59 +01:00
Rylan Polster
cbda171c2b
Fix JSON file download failure fallback 2023-02-04 01:46:50 +01:00
Mike McQuaid
9a13f53cbb
Merge branch 'master' into remove-fetch-print 2023-02-03 13:10:19 +00:00
Rylan Polster
c30b489525
Homebrew::API::fetch_file_source: remove debug line 2023-02-03 11:48:02 +01:00
Mike McQuaid
561e520467
api: warn rather than fail if we've got a cached version.
Rather than failing every time we fail to update (breaking most usage
while offline) instead only fail if we cannot obtain the JSON and we
don't have a valid local file we can use.

Also tweak the timeout and retry logic and values to make a bit more
sense in this context and not be so noisy when offline.
2023-02-03 10:22:50 +00:00
Rylan Polster
2c78840f57
Fix typecheck issue 2023-01-28 02:16:09 -06:00