Skip to content

Instantly share code, notes, and snippets.

@axtl
Created April 9, 2014 05:27
Show Gist options
  • Save axtl/10228610 to your computer and use it in GitHub Desktop.
Save axtl/10228610 to your computer and use it in GitHub Desktop.
homebrew reverse dependencies
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import sys
if len(sys.argv) < 2:
raise SystemExit('need a brew to check reverse deps for')
check_brew = sys.argv[1]
brews = subprocess.check_output(['brew', 'list', '-1']).split()
if check_brew not in brews:
raise SystemExit('brew not actually installed, moving on')
# skip the brew itself
brews.remove(check_brew)
for brew in brews:
try:
deps = subprocess.check_output(['brew', 'deps', brew]).split()
except subprocess.CalledProcessError:
# possible issue calling brew deps due to 'fake formulas'
continue
if check_brew in deps:
print('[*] {}'.format(brew))
@vinyar
Copy link

vinyar commented Jan 15, 2021

I found the answer in 2021 for these who read this in 2027.. brew leaves
you may have to run it a few times to get rid of everything, but it works!

@grigorye
Copy link

grigorye commented Feb 8, 2021

brew uses --installed still works in 2020. (You can use it with --recursive as necessary). Thanks @lepistone! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment