rcmdnk / homebrew-file

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

support for oldnames #265

Open kromanov-miro opened 7 months ago

kromanov-miro commented 7 months ago

brew-file init fails when installed package name is 'oldname'.

Workaround:

brew uninstall --ignore-dependencies python-cryptography
brew install cryptography

Traceback:

Do you want to set a repository (y)? ((n) for local Brewfile). [y/n]: n
Traceback (most recent call last):
  File "/opt/homebrew/bin/brew-file", line 3639, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/bin/brew-file", line 3626, in main
    b.execute()
  File "/opt/homebrew/bin/brew-file", line 2947, in execute
    _ = self.initialize()
        ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/bin/brew-file", line 2164, in initialize
    self.get_installed_packages()
  File "/opt/homebrew/bin/brew-file", line 1969, in get_installed_packages
    p, info[p]
       ~~~~^^^
KeyError: 'python-cryptography' 
rcmdnk commented 7 months ago

I tried to reproduce the problem but could not. Could you please try following command and show results?

command brew list --formula
command brew info --json=v1 --installed
cat $(command brew file get_files)
konnano commented 7 months ago

This was reproduced below Please also write the output of just the brew command.

diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh
index a00510b400..41fa61d21a 100644
--- a/Library/Homebrew/brew.sh
+++ b/Library/Homebrew/brew.sh
@@ -12,7 +12,7 @@ case "${HOMEBREW_SYSTEM}" in
   Darwin) HOMEBREW_MACOS="1" ;;
   Linux) HOMEBREW_LINUX="1" ;;
 esac
-
+echo Hello
 HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
 HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
 HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
rcmdnk commented 7 months ago

@konnano I'm sorry, but how did you reproduce? Could you please write more details of environment and executed commands?

Above diff seems just a git diff result of /opt/homebrew (or /usr/local/Homebrew) (and result is you added 1 line: echo Hello.)

konnano commented 6 months ago

(Homebrew):git checkout stable Switched to branch 'stable'

(Homebrew):brew developer off

(Homebrew):brew update
==> Updating Homebrew... Already up-to-date.

(Homebrew):brew config

HOMEBREW_VERSION: 4.2.19
ORIGIN: https://github.com/Homebrew/brew
HEAD: 54bea636b41f7953c01a7da5f488f08c1b42ffd1
Last commit: 4 days ago
Core tap HEAD: ac9df29196ce61b983e1088079e3e39c42c39e9e
Core tap last commit: 4 hours ago
Core tap JSON: 26 Apr 08:34 UTC
Core cask tap HEAD: 3d297ec5993a298e56e4c184bdfc56f783536b29
Core cask tap last commit: 2 hours ago
Core cask tap JSON: 26 Apr 08:34 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_NO_INSTALL_FROM_API: set
Homebrew Ruby: 3.1.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: quad-core 64-bit ivybridge
Clang: 10.0.0 build 1000
Git: 2.17.2 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
macOS: 10.13.6-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: 10.1

(Homebrew):brew file init

Do you want to set a repository (y)? ((n) for local Brewfile). [y/n]: n
Traceback (most recent call last):
  File "/usr/local/bin/brew-file", line 3639, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/bin/brew-file", line 3626, in main
    b.execute()
  File "/usr/local/bin/brew-file", line 2947, in execute
    _ = self.initialize()
        ^^^^^^^^^^^^^^^^^
  File "/usr/local/bin/brew-file", line 2164, in initialize
    self.get_installed_packages()
  File "/usr/local/bin/brew-file", line 2010, in get_installed_packages
    "appstore_list", self.get_appstore_list()
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/bin/brew-file", line 1927, in get_appstore_list
    f"{v[0]} {k} {v[1]}" for k, v in self.get_appstore_dict().items()
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/bin/brew-file", line 1916, in get_appstore_dict
    x.split("=")[0].strip(): x.split("=")[1].strip() for x in lines
                             ~~~~~~~~~~~~^^^
IndexError: list index out of range

(Homebrew):cat patch.txt

diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh
index a00510b400..41fa61d21a 100644
--- a/Library/Homebrew/brew.sh
+++ b/Library/Homebrew/brew.sh
@@ -12,7 +12,7 @@ case "${HOMEBREW_SYSTEM}" in
   Darwin) HOMEBREW_MACOS="1" ;;
   Linux) HOMEBREW_LINUX="1" ;;
 esac
-
+echo Hello
 HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
 HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
 HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"

(Homebrew):patch -p1 < patch.txt patching file Library/Homebrew/brew.sh

(Homebrew):brew file init

Hello
Do you want to set a repository (y)? ((n) for local Brewfile). [y/n]: n
Traceback (most recent call last):
  File "/usr/local/bin/brew-file", line 3639, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/bin/brew-file", line 3626, in main
    b.execute()
  File "/usr/local/bin/brew-file", line 2947, in execute
    _ = self.initialize()
        ^^^^^^^^^^^^^^^^^
  File "/usr/local/bin/brew-file", line 2164, in initialize
    self.get_installed_packages()
  File "/usr/local/bin/brew-file", line 1969, in get_installed_packages
    p, info[p]
       ~~~~^^^
KeyError: 'Hello'
rcmdnk commented 6 months ago

@konnano The first erro is related to #267

The second error occurs because brew-file depends on standard output of brew command and the patch gives additional Hello output.

So, they are not related to @konstantin-romanov 's error

mettavi commented 6 months ago

Hi, I have just installed brew-file and I am having the same problem:

brew-file init

You are using Brewfile of git@github.com:mettavi/homebrew-brewfile.
Traceback (most recent call last):
  File "/usr/local/bin/brew-file", line 3639, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/bin/brew-file", line 3626, in main
    b.execute()
  File "/usr/local/bin/brew-file", line 2947, in execute
    _ = self.initialize()
        ^^^^^^^^^^^^^^^^^
  File "/usr/local/bin/brew-file", line 2164, in initialize
    self.get_installed_packages()
  File "/usr/local/bin/brew-file", line 1969, in get_installed_packages
    p, info[p]
       ~~~~^^^
KeyError: 'python-cryptography'

Before this, I had exactly the same problem with "KeyError: 'python-certifi'", which I solved by doing:

brew uninstall --ignore-dependencies python-certifi
brew install certifi

This may be related to another problem I have: after sourcing brew-wrap in my .zshrc, brew file and brew commands do not work. The command line hangs and nothing happens:

Screenshot 2024-05-13 at 2 39 17 pm

The same thing happened when I tried brew set_repo andbrew file set_repo. Instead, I had to use brew-file set_repo to get it to work.

command brew config

HOMEBREW_VERSION: 4.2.21
ORIGIN: https://github.com/Homebrew/brew
HEAD: 82c2e743a5bcea725f9ca1429e3e21c3088ff904
Last commit: 8 days ago
Core tap JSON: 13 May 21:21 UTC
Core cask tap JSON: 13 May 21:21 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_BAT_THEME: tokyonight_night
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 3.1.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: octa-core 64-bit icelake
Clang: 15.0.0 build 1500
Git: 2.44.0 => /usr/local/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 13.6.6-x86_64
CLT: 15.1.0.0.1.1700200546
Xcode: 15.0
mettavi commented 6 months ago

I just went ahead and used the same fix again:

brew uninstall --ignore-dependencies python-cryptography
brew install cryptography

There were no other renamed brew packages, so now brew-file init successfully created the Brewfile. 👍

Now I have to find out why brew-wrap is not working. Perhaps it is a problem with my .zshrc file, because when I source .zshrc after brew-wrap it starts working. 🤔

rcmdnk commented 6 months ago

sorry, but I've not reproduced the problem.

If anyone has a problem and still shows the error, could you please give following information:

command brew list --formula
command brew info --json=v1 --installed
cat $(command brew file get_files)
command brew doctor
env|grep HOMEBREW
rcmdnk commented 6 months ago

This is related to the renamed formulae.

It may work just do:

command brew update & command brew upgrade

before brew-file init.