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

brew.packages doesn't handle packages from third-party taps in an idempotent way #1280

Open
karlicoss opened this issue Jan 26, 2025 · 0 comments

Comments

@karlicoss
Copy link
Contributor

karlicoss commented Jan 26, 2025

To Reproduce

Consider this command -- if you run it for the first time, it succeeds without issues:

pyinfra @local brew.packages koekeishiya/formulae/skhd

Now if you run it again:

pyinfra @local brew.packages koekeishiya/formulae/skhd
...
--> Detected changes:
    Operation                                   Change       Conditional Change
    brew.packages (koekeishiya/formulae/skhd)   1 (@local)   -

As you can see, it suggests that something is due to change, even though the package is already installed!

However, I'd expect this to report no changes! E.g. similar to running brew.packages git twice.

Why this happens

I looked at the code -- facts.brew.BrewPackages is using brew list --versions command to get information about packages

def command(self) -> str:
return "brew list --versions"

But this lists packages without full name (which is koekeishiya/formulae/skhd or koekeishiya/formulae/yabai in this case)

$ brew list --versions | egrep 'skhd|yabai'
skhd 0.3.9
yabai 7.1.6

There list brew list --full-name, but it's mutually exclusive with --versions, sadly.

Possibly the most robust way is to use brew info --json --installed for BrewPackages fact.
This contains both full_name attribute and versions (and perhpas better to use json than plaintext parsing anyway).

Switching to full_name might break things though, e.g. if someone had the appropriate brew tap already, they could simply use brew.packages skhd. So BrewPackages fact would need to somehow handle both full and short name which could be awkward... Or maybe it's fine to break backwards compatibility for third party taps, and always switch to using full names (it wouldn't affect "default" tap, since for them name and full_name are the same). But don't really have an opinion here, not a heavy brew user, so don't know what was the intent there!

Possible workaround/improvements

I guess I could explicitly specify brew.tap koekeishiya/formulae, and then use brew.packages skhd, so both operations are idempotent and correctly detect no changes.

Maybe it's worth documenting this as a more consistent approach, and/or warn if user executes brew.packages package/name/with/slashes, suggesting to setup tap and use the short name to avoid inconsistencies.

Meta

Using latest version of pyinfra (3.2)

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

No branches or pull requests

1 participant