rcmdnk / homebrew-file

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

"on-request" no longer lists all formulae installed on request #209

Closed zcutlip closed 1 year ago

zcutlip commented 1 year ago

I'm not sure if this is expected, but formulae that were installed on request, but are also dependencies of later installed formulae are removed from and/or not added to the brew file.

I believe the commit that resulted in this change is here: https://github.com/rcmdnk/homebrew-file/commit/32871fab290738a87ab44cf72ccc8647aee8fcaa

If we run brew leaves --installed-on-request, it omits packages that are dependencies of other packages even if they initially were installed on request. Note that 'python@3.11' is not listed:

$ brew leaves --installed-on-request | grep 'python@3'
python@3.10
python@3.8
python@3.9

However, if we run brew info to list installed packages and use jq to show us, installed_on_request packages, python@3.11 is listed:

$ brew info --json=v2 --installed \
    | jq -r '.formulae[]|select(any(.installed[]; .installed_on_request)).full_name' | grep python@3
python@3.10
python@3.11
python@3.8
python@3.9

I've tried forcibly uninstalling python 3.11, ignoring dependencies, and reinstalling to ensure it is most recently installed on request. However this doesn't help. It is still not considered a leaf formula.

zcutlip commented 1 year ago

I should add this is a problem because a formulae in a machine-specific brewfile can cause other formulae in a common brewfile to stop being leaves. Those will be removed removed from the common brewfile. This impacts other machines that also share the common brewfile

rcmdnk commented 1 year ago

Thank you for the report. I did not intend to change the behavior and this case is not checked well, sorry. Let's give me a time to check.

zcutlip commented 1 year ago

No worries. Thank you for looking into it

rcmdnk commented 1 year ago

The problem is conformed.

$ brew ls
$
$ brew install python@10
...
$ brew install python@11
...
$ brew leaves --installed-on-request | grep 'python@3'
python@3.10
python@3.11
$  brew info --json=v2 --installed | jq -r '.formulae[]|select(any(.installed[]; .installed_on_request)).full_name' | grep python@3
python@3.10
python@3.11
$ brew install virtualenv # depends on python@3.11
...
$ brew leaves --installed-on-request | grep 'python@3'
python@3.10
$  brew info --json=v2 --installed | jq -r '.formulae[]|select(any(.installed[]; .installed_on_request)).full_name' | grep python@3
python@3.10
python@3.11
$ brew rm virtualenv
...
$ brew leaves --installed-on-request | grep 'python@3'
python@3.10
python@3.11
$ brew leaves --installed-as-dependency
pkg-config
$ brew install virtualenv
...
$ brew deps --tree --installed
ca-certificates

gdbm

mpdecimal

openssl@3
└── ca-certificates

pkg-config

python@3.10
├── gdbm
├── mpdecimal
├── openssl@3
│   └── ca-certificates
├── readline
├── sqlite
│   └── readline
└── xz

python@3.11
├── mpdecimal
├── openssl@3
│   └── ca-certificates
├── sqlite
│   └── readline
└── xz

readline

sqlite
└── readline

virtualenv
└── python@3.11
    ├── mpdecimal
    ├── openssl@3
    │   └── ca-certificates
    ├── sqlite
    │   └── readline
    └── xz

xz

I mistakenly thought that "leaves" always included "on request" items.

so, the following options should be independent:

If HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST=1, then brew leaves --installed-on-request is used.

rcmdnk commented 1 year ago

@zcutlip From v9.0.14, the following packages are listed in the Brewfile:

1. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =0 (default): `brew ls`
2. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =0          : `brew leaves`
3. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew ls` and brew info <packages>.installed_on_request = True
4. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew leaves --installed-on-request`

So, 1, 2, and 3 are the same as v9.0.12 and beforehand. 4 (and 1,2) is the same as v9.0.13.

At v9.0.13:

1. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =0 (default): `brew ls`
2. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =0          : `brew leaves`
3. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew leaves --installed-on-request`
4. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew leaves --installed-on-request`

before v9.0.12:

1. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =0 (default): `brew ls`
2. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =0          : `brew leaves`
3. HOMEBREW_BREWFILE_LEAVES=0 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew ls` and brew info <packages>.installed_on_request = True
4. HOMEBREW_BREWFILE_LEAVES=1 & HOMEBREW_BREWFILE_ON_REQUEST =1          : `brew ls` and brew info <packages>.installed_on_request = True

My mistake was thinking that brew ls and brew info <packages>.installed_on_request = True was the same as brew leaves --installed-on-request

zcutlip commented 1 year ago

as of v9.0.14 things are back to working as expected. thank you for looking into this

zcutlip commented 1 year ago

closing this issue as it seems to work as expected now