How to check which packages a certain `brew` package is used in? - homebrew

I would expect an API like
brew enables --installed
It seems this information is available, otherwise how does brew autoremove work?

brew uses might be what you are looking for.
E.g. brew uses --installed openssl#1.1 will list all installed packages that use openssl#1.1
brew uses --eval-all openssl#1.1 will list all packages that use openssl#1.1
See the documentation:
Show formulae and casks that specify formula as a dependency; that is, show dependents of formula. When given multiple formula arguments, show the intersection of formulae that use formula. By default, uses shows all formulae and casks that specify formula as a required or recommended dependency for their stable builds.

Related

Homebrew claims cairo depends on Python

When uninstalling the python#3.9 package, Homebrew complains that the cairo package depends on it. This is unlikely to be true:
brew uses python#3.9
lists several packages but not cairo, and
brew deps --tree cairo
shows a tree without any python#*.* in it. On the other hand,
brew uses --installed python#3.9
does list the cairo package, and commands like brew missing and brew doctor create a warning about the missing dependency python#3.9.
I don't know whether the cairo package (see its formula here) somehow depends on python#3.9, but I guess it does not, and the behavior is weird. What's going on and how can it be fixed?
I think I've found what causes the problem, inspired by a comment on an old issue on Homebrew's Github repository:
brew uses --installed uses the dependency resolution information from your installed formulae whereas brew uses alone does not.
Indeed, whereas the formula doesn't contain a dependency on python#3.9, the installed package does: on my system, the file /opt/homebrew/Cellar/cairo/1.16.0_5/INSTALL_RECEIPT.json has a key runtime_dependencies that includes this element:
{
"full_name": "python#3.9",
"version": "3.9.9",
"declared_directly": false
}
In a further comment, the developer explains:
When built from source some things pick up dependencies opportunistically i.e. they link against stuff without us trying to make them do so. The other thing where this kicks in is if you've built a formula with a particular, non-default option. We now store these links in the formula itself and use it for certain commands so you get a result that's correct for your system (i.e. brew uses --installed doesn't miss results that will break things if uninstalled).
This may not be a complete explanation (I'm pretty sure I installed cairo from a binary 'bottle' without any non-standard options), but it does suggest the general area where the issue may have arisen.
The next thing to find out is how to resolve the issue. I don't know whether there's an official workaround, but the options seem to be
Manually remove that part from INSTALL_RECEIPT.json
Uninstall the cairo package while suppressing warnings and removal of dependent packages, and then reinstall it.
I chose 1. and it seems (so far) to work.

Homebrew find installed packages which aren't dependencies of any other installed package

Previously I've had things installed with homebrew which had dependencies which I omitted to remove when I removed the package itself (homebrew of course does not do this automatically for you, for good reason).
Now, to tidy up my system a bit, I'd like to identify all the brew packages which are not required by any other that is installed, so that I can manually identify those which I want to keep vs. those I am happy to remove.
To do this manually, I would do brew list, then, on each item which that outputs, I would do brew uses --installed <name-of-package-from-brew-list>, to check with respect to each package whether it is used by any other installed package (Then, if the answer is none, if I was curious as to why it was originally installed, I could also do brew uses <name-of-installed-package> which might indicate to me which package I used in the past but have since uninstalled actually installed it originally).
This is all very manual and I wondered if xargs could help.
My attempt to use it isn't working:
brew list | xargs brew uses --installed > test.txt
I get no output at all from that command, a blank file (but the command takes several seconds to run).
What am I not doing right with xargs?
It seems like brew leaves would fit your use-case?
% brew leaves --help
Usage: brew leaves
List installed formulae that are not dependencies of another installed formula.
From the question:
brew list | xargs brew uses --installed > test.txt
This command should be spelled xargs -n1 since brew uses with multiple formulae does something quite different:
% brew uses --help
Usage: brew uses [options] formula
Show formulae that specify formula as a dependency. When given multiple
formula arguments, show the intersection of formulae that use formula. By
default, uses shows all formulae that specify formula as a required or
recommended dependency for their stable builds.
brew autoremove --dry-run
Removes all packages that were only installed as a dependency of another formula and are now no longer needed. With the --dry-run flag you can dry run it and just get a list of all packages without uninstalling anything.

How do I configure FFTW3 installed via HomeBrew?

I have installed FFTW3 using HomeBrew which downloads the file located at https://homebrew.bintray.com/bottles/fftw-3.3.8_1.mojave.bottle.tar.gz and installs it on my system which is running on macOS 10.14.6. Now, the installation is fine and gcc is able to compile code that uses the fttw3.h header file.
However, there is supposed to be a ./configure script which I should be able to use to customise my configuration and, unfortunately, it does not exist in /usr/local/Cellar/fftw/3.3.8_1.
Where can I find it? How else should I configure the installation?
The build process of a Homebrew package is defined in a file called formula, which is written in Ruby.
A formula is a package definition written in Ruby. It can be created with brew create <URL> where is a zip or tarball, installed with brew install <formula>.
You can get the formula for fftw from homebrew/core/Formula/fftw.rb.
And the configuration options are defined in the args array.
# https://github.com/Homebrew/homebrew-core/blob/e7c8239a8a7c9b4501c4a18a4028cae82e254984/Formula/fftw.rb#L21-L30
def install
args = [
"--enable-shared",
"--disable-debug",
"--prefix=#{prefix}",
"--enable-threads",
"--disable-dependency-tracking",
"--enable-mpi",
"--enable-openmp",
]
Download the fftw.rb formula file and change the configuration options. After that, install the modified formula by building it from source.
brew install --build-from-source local/path/to/modified-fftw.rb
Extended Reading
To get how to write your own formula. Check
Formula Cookbook
How to Create and Maintain a Tap
FAQ
Why brew edit fftw is not recommended?
Homebrew is made of two parts: the brew command and formula repos. fftw.rb is a formula defined in the built-in, local formula repo homebrew-core. When you use brew edit fftw, you are editing the file from the local repo directly. Unless you're going to contribute to this repo, don't edit files within the homebrew-core repo directly.

I'm trying to install the Arabic data on Tesseract, but when I do, it gives me this:

I'm trying to install the Arabic data on Tesseract using Terminal using this command. I have homebrew installed
brew install tesseract-ocr-[ara]
But I keep getting this error.
Any thoughts?
Error: No available formula with the name "tesseract-ocr-[ara]"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
It suggested that I do a deeper clone since I had only done a shallow clone, so I did that, but it still gave me this same result.
brew info tesseract says:
tesseract: stable 4.1.0 (bottled), HEAD
OCR (Optical Character Recognition) engine
https://github.com/tesseract-ocr/
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/tesseract.rb
==> Dependencies
Build: autoconf, autoconf-archive, automake, libtool, pkg-config
Required: leptonica, libtiff
==> Options
--HEAD
Install HEAD version
==> Caveats
This formula contains only the "eng", "osd", and "snum" language data files.
If you need all the other supported languages, `brew install tesseract-lang`.
This suggests that you need to run brew install tesseract-lang.

How to install apg (password generator) on OSX?

I am unable to install apg via homebrew in OSX. I tried brew install apg but I got No available formula with the name "apg".
Tried looking around but no success so far.
The apg formula for homebrew has been removed because the upstream software doesn't seem to be maintained anymore. The home page of the apg software is not reachable and even on other OS, like Debian, the package will probably be discontinued soon (see the notice at the bottom of the description). That's the reason why a brew install apg is not working for you.
That being said, if you look closely at the discussion around the removal from homebrew, you'll find that someone is now maintaining an updated formula in its own homebrew tap. You can then install apg by first adding his tap:
brew tap jzaleski/homebrew-jzaleski
brew install apg

Resources