rcmdnk / homebrew-file

Brewfile manager for Homebrew
http://homebrew-file.readthedocs.io/
MIT License
356 stars 29 forks source link

refactor brew info related functions #283

Closed rcmdnk closed 1 month ago

rcmdnk commented 2 months ago

To get json list by brew info, currently --eval-all option is used:

https://github.com/rcmdnk/homebrew-file/blob/2c762a31c3d4fec3c1539608ff2e34fda34732dc/src/brew_file/brew_helper.py#L249 https://github.com/rcmdnk/homebrew-file/blob/2c762a31c3d4fec3c1539608ff2e34fda34732dc/src/brew_file/brew_helper.py#L287

This is needed at least for tapall: https://github.com/rcmdnk/homebrew-file/blob/2c762a31c3d4fec3c1539608ff2e34fda34732dc/src/brew_file/brew_info.py#L267

But not necessary for most of cases. Maybe it can be replaced by --installed option and use --eval-all only for tapall and something else which needs all non-installed formulae/cask information (is there any?)?

It could be better to get list one by one for installed formulae/cask, as some formula can have problem and brew info --eval-all --json=v1 does not work with it (ref #282).

(if there is a such formula, tapall is disabled to work and just show warning?)

rcmdnk commented 1 month ago

https://github.com/rcmdnk/homebrew-file/blob/a81631376cd0151202b79c851289f754a7a55ce1/src/brew_file/brew_helper.py#L245-L263

https://github.com/rcmdnk/homebrew-file/blob/a81631376cd0151202b79c851289f754a7a55ce1/src/brew_file/brew_helper.py#L283-L301

In these functions, info was taken by from json file of API cache in addition to brew info result.

This was added because brew info --installed or brew info --eval-all lacks packages when API method was implemented (maybe there was a bug?).

For now, as long as I tested, it seems brew info always returns all information and no need to check json file.

rcmdnk commented 1 month ago

https://github.com/rcmdnk/homebrew-file/blob/a81631376cd0151202b79c851289f754a7a55ce1/src/brew_file/brew_info.py#L483 https://github.com/rcmdnk/homebrew-file/blob/a81631376cd0151202b79c851289f754a7a55ce1/src/brew_file/brew_info.py#L509

get_tap_xxx functions are used in write function, too.

These tap information can be taken from each package information directly, and it should be faster (maybe)

rcmdnk commented 1 month ago

brew tap-info is now available.

brew tap-info --installed --json gives all taps (including homebrew/core, cask) and their formula_names and cask_tokens (including username/tapname)