Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew-file no longer expands custom environment variables for brewfile includes #109

Closed
zcutlip opened this issue Oct 31, 2021 · 6 comments
Closed

Comments

@zcutlip
Copy link

zcutlip commented Oct 31, 2021

I'm not sure if this recent change was intentional or not, but previously I could define custom shell variables in my environment like:

export ARCH=$(uname -m)

And then include appropriate brewfiles using those variables:

Include architecture-specific brewfile
file ./Brewfile.arch_${ARCH}

This seems to no longer work for any custom environment variables I've set.

Another example is that worked until recently:

# unset this to not include "extra" brewfiles such as extra-casks.Brewfile
export HBB_EXTRA="extra"

Then include:

# include "extra" casks only on machines that opt in
file ./${HBB_EXTRA}-casks.Brewfile

Standard variables like $HOSTNAME still seem to work.

@rcmdnk
Copy link
Owner

rcmdnk commented Nov 1, 2021

Thank you for the report.

It seems it does not work in M1 Mac (arm64) environment.

On my Mac (M1 Mac), it works in Rosetta, x86_64 environment, but does not work in arm64 environment.
It also works in Ubuntu (with x86_64).

There is a something wrong in Python's os.environ.get function with arm64?

HOSTNAME is a shell variable and it is taken directly from python module.
Then it works even with arm64.

def expandpath(path):

One question: Do you remember if it works even in arm64 previously?

@zcutlip
Copy link
Author

zcutlip commented Nov 1, 2021

In my case, the problem is happening on both of my Intel Macs. I haven't checked on my M1 Mac, but I assuming it's happening there as well.

❱ python3 --version
Python 3.9.7
❱ uname -a
Darwin osarian 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64

Thank you!

@zcutlip
Copy link
Author

zcutlip commented Nov 1, 2021

I may have misunderstood the issue.

I ran brew-file in vscode, and single stepped in the debugger. It's definitely expanding ${ARCH} and opening & reading Brewfile.arch_x86_64.

I'm not sure what the exact issue is, but what happens is the following:

  • Any new entries in the included brewfile are ignored
  • Any existing entries in the included brewfile that are already installed get added to the main brewfile
  • The included Brewfile.arch_${ARCH} brewfile is not modified in any way, even if entries are moved to the main brewfile, or if it contains entries that are not installed

So even though, in the debugger, I can watch brew-file open the file and completely parse it, it doesn't seem to respect it for installing, uninstalling, and re-initializing.

@zcutlip
Copy link
Author

zcutlip commented Nov 1, 2021

Another data point:

After doing brew file update, I see the following in the output suggesting ${ARCH} is not being expanded:


##########################################################
# Initialize /Users/zach/.dotfiles/brewfile/Brewfile.arch_
##########################################################

However, when I do brew-file get_files, I see that ${ARCH} has been expanded:

brew-file get_files
/Users/zach/.dotfiles/brewfile/Brewfile
/Users/zach/.dotfiles/brewfile/Brewfile.arch_x86_64

@rcmdnk
Copy link
Owner

rcmdnk commented Nov 2, 2021

Thanks for the information!
The problem is that original brew command throws away environmental variables when it calls a subcommand.

I think you have used brew-wrap
and it makes you to call brew-file directly if you call brew file.

But, I'm sorry, the implementation of brew-wrap at v8.5.5 was wrong
and you called brew file directly even if you set brew-wrap.

I fixed it in v8.5.6.

Could you please update brew-file and try it?

$ brew update && brew upgrade
$ source ~/.bashrc # or source ~/.zshrc # or directly, source /usr/local/etc/brew-wrap
$ brew file cat

@zcutlip
Copy link
Author

zcutlip commented Nov 2, 2021

Great, this seems to work on v8.5.6!

Thank you

@zcutlip zcutlip closed this as completed Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants