How to list all keg only formulas installed? - homebrew

I want to list all keg-only formulas installed on a machine. Could anybody show me a single command that can do this job? I haven't find a solution to do this task.

I've had success running this command to get formulas that are installed as keg-only:
[$]> brew info --installed --json=v1 | jq 'map(select(.keg_only == true)) | map(.name)'
References:
https://github.com/Homebrew/legacy-homebrew/issues/26903
https://github.com/Homebrew/homebrew-core/issues/26165

Related

Trouble with HomeBrew

I'm having trouble searching for the list of all casks when I run the command for it.
brew search --casks
I get the error you see in the picture.
Error: Invalid usage: This command requires at least 1 text or regex argument.
If anyone has had similar problems please share.
You need at least one string to search for.
$ brew search --casks fire
==> Casks
firefly firealpaca firestorm
firefox-beta firebase-admin firestormos
firefox-developer-edition firebird-emu fireworks
firefox-esr firecamp multifirefox
firefox-nightly firefox ✔ spitfire-audio
If you really need to find all available casks, you can use an empty arg like this:
brew search --casks ''

VersionMismatchWarning: Mismatched versions found - blosc

I cannot do a 'pip install blosc' on windows. I devop on windows and have my workers and schedule running on vm's with dask-docker. Anyone have any ideas? Seem like dask really wants all linux all the time.
blosc
+-----------------------+---------+
| | version |
+-----------------------+---------+
| client | None |
| scheduler | 1.9.1 |
| tcp://127.0.0.1:38323 | 1.9.1 |
+-----------------------+---------+
(venv) D:\dev\code\datacrunch>pip install -U blosc
Collecting blosc
Using cached blosc-1.9.1.tar.gz (809 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Building wheels for collected packages: blosc
Building wheel for blosc (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'd:\dev\code\netsense.support\datacrunch\venv\scripts\python.exe' 'd:\dev\code\netsense.support\datacrunch\venv\lib\site-packages\pip_vendor\pep517_in_process.py' build_wheel 'C:\Users\H166631\AppData\Local\Temp\tmpwgt4t634'
cwd: C:\Users\H166631\AppData\Local\Temp\pip-install-r1476vwy\blosc
Complete output (162 lines):
Not searching for unused variables given on the command line.
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (ENABLE_LANGUAGE):
No CMAKE_C_COMPILER could be found.
The compression has to match throughout the dask cluster and because you don't have blosc installed you run into some issues. As a side note, there is an effort to improve messaging of the error in PR #3742 . I can think of two solutions:
Switch to conda instead of pip (though this is perhaps a non-starter for you)
Use a different compression (one that you have installed or can easily install on your machine)
For 2. you can either set the compression programmatically like the following:
In [1]: import dask
In [2]: import distributed
In [3]: dask.config.set({'distributed.comm.compression': 'lz4'})
Or on the CLI:
DASK_DISTRIBUTED__COMM__COMPRESSION=zlib dask-worker
Or with with the dask config file. For more info, I would recommend reading through: https://docs.dask.org/en/latest/configuration.html and https://docs.dask.org/en/latest/configuration-reference.html#distributed.comm.compression
You can always just not install blosc on your linux machines. Dask is happy to run on Windows. It's even happy (to a certain extent) to mix between Windows and Linux. But it's not happy if you have libraries on some of your machines that you don't have on others. Library uniformity is key.

Homebrew: list the packages installed from taps?

Over time, I've installed a number of packages with Homebrew, mostly from the default repo of formulae (homebrew-core), but some from other locations via brew tap.
Now I'm putting together some install scripts to make my dev environment more reproducible, and I'm trying to figure out which packages can be installed by a simple brew install and which require a brew tap beforehand.
The ability to query brew has proved useful for figuring out which options I used for each package, but not for this tap-related question. Is there a way to do this without manually going through each package and seeing where it's available?
I found a couple ways that work.
brew list --full-name
Slower, but a little more informative:
brew info $(brew list) | grep '^From:' | sort
This expression would return a list of installed 3rd party packages only:
brew list --full-name -1 | grep /
…for the respective list of taps in use, try:
brew list --full-name -1 | grep / | cut -d"/" -f1 -f2 | sort | uniq
The brew list --full-name variants in the other answers did not work for me (in 2022). This, however, does:
brew list -1 | xargs brew info | grep '^From:'
Alternatively, to see only casks, use this:
brew list --cask -1 | xargs brew info --cask | grep '^From:'
... or only leaves:
brew leaves | xargs brew info | grep '^From:'

upgrade or install a homebrew formula

In my CI-setup, i would like to make sure that the newest version of a given formula is installed, regardless of whether it is already installed or not.
i'm currently using something like:
brew update
brew install FORMULA || (brew upgrade FORMULA && brew cleanup FORMULA)
What are the pitfalls with that approach? Is there a nicer approach to the problem (e.g. by first querying whether FORMULA is already installed, rather than relying on brew install to fail only if FORMULA is installed)?
I you want to install a Homebrew package if it does not already exist, and upgrade it otherwise, the best solution is to use Homebrew Bundle which is officially part of the Homebrew family. If that doesn't work for you, and you want to roll your own solution, you should reference at the suggestions below.
There are other situation where a brew install might fail, other than a package already being installed. I'm not sure, but it doesn't look like the brew install command emits an exit status other than 1 on failure, so you have two options:
Search stderr for "not installed" and check against that
Use a different approach
The most common approach I've seen used for this purpose is to check if the package is installed with the command brew ls --versions:
function install_or_upgrade {
if brew ls --versions "$1" >/dev/null; then
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade "$1"
else
HOMEBREW_NO_AUTO_UPDATE=1 brew install "$1"
fi
}
You'll want to use HOMEBREW_NO_AUTO_UPDATE=1 if you're installing multiple packages so that Homebrew does not try to update in between each install/upgrade.
I've been using the following. Depending on the use case, I'll use a shell function as follows:
function smart_brew() {
HOMEBREW_NO_AUTO_UPDATE=1 brew `brew ls --versions "$1" | wc -l | xargs expr | sed 's/0/install/' | sed 's/1/upgrade/'` "$1"
}
and sometimes as a definition in a Makefile:
define smart_brew
HOMEBREW_NO_AUTO_UPDATE=1 brew `brew ls --versions "$(1)" | wc -l | xargs expr | sed 's/0/install/' | sed 's/1/upgrade/'` "$(1)"
endef
dev:
$(call smart_brew,formula)
Same basic idea

Enumerating formulas for Homebrew and Macports

I am trying to count the total number of homebrew formulas. I've done a wildcard search and directed the output to a text file and counted the lines using brew search /.*/ | wc -l.
This produces only 3,142 formulas, 1/5 the number I found for Macports. However, I've noticed that Macports also has a lot of duplicate packages, listing both the meta package and it's various dependent packages. Is there a way to break out those dependent packages in Homebrew? What about Macports, is there a way to filter out the number of redundant dependent packages?
Finally, is there a way to force Homebrew to list versions?
You should be comparing the number of MacPorts source packages to Homebrew. For example
tar tf /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports.tar | grep Portfile | wc -l
Maybe there is a better way.
To get a list of package versions in Homebrew, you can try something like this:
for formula in $(brew search); do brew info $formula | grep "^$formula"; done

Resources