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

Fails when the brew command is not available #158

Closed
S-zebra opened this issue Jul 11, 2022 · 5 comments
Closed

Fails when the brew command is not available #158

S-zebra opened this issue Jul 11, 2022 · 5 comments
Assignees

Comments

@S-zebra
Copy link

S-zebra commented Jul 11, 2022

Distutils tries to get the output of brew --prefix, but it fails if Homebrew is not installed on the system, or when brew command is not available.

homebrew_prefix = subprocess.check_output(['brew', '--prefix'], text=True).strip()

@dflems
Copy link

dflems commented Jul 13, 2022

See also #159 and #155 (comment)

@jaraco

@jaraco
Copy link
Member

jaraco commented Jul 13, 2022

At first, I was going to use this diff:

diff --git a/distutils/command/_framework_compat.py b/distutils/command/_framework_compat.py
index e032603..c2849a1 100644
--- a/distutils/command/_framework_compat.py
+++ b/distutils/command/_framework_compat.py
@@ -7,6 +7,7 @@ import sys
 import os
 import functools
 import subprocess
+import contextlib
 
 
 @functools.lru_cache()
@@ -39,7 +40,10 @@ schemes = dict(
 def vars():
     if not enabled():
         return {}
-    homebrew_prefix = subprocess.check_output(['brew', '--prefix'], text=True).strip()
+    with contextlib.suppress(FileNotFoundError):
+        homebrew_prefix = subprocess.check_output(
+            ['brew', '--prefix'], text=True
+        ).strip()
     return locals()

But then I realized that will only cause a different error because {homebrew_prefix} will be in the scheme but undefined. The enabled() function needs to detect whether the install is a homebrew one.

@jaraco
Copy link
Member

jaraco commented Jul 13, 2022

Maybe the presence of "Cellar" in the projectbase config var is a good indicator?

>>> pprint.pprint({k:v for k, v in sysconfig.get_config_vars().items() if isinstance(v, str) and 'Cellar' in v})
{'projectbase': '/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/bin',
 'srcdir': '/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin'}

@jaraco jaraco closed this as completed in 1845a34 Jul 13, 2022
@jaraco
Copy link
Member

jaraco commented Jul 13, 2022

Fix is rolling out is 63.2.0.

This was referenced Jul 14, 2022
This was referenced Aug 4, 2022
carlocab added a commit to carlocab/homebrew-core that referenced this issue Aug 10, 2022
@carlocab
Copy link

You can have "Cellar" in sysconfig.get_config_var('projectbase') return True but have the call to brew still return an error because brew is not in your PATH.

You might want to do this, for instance, when you wish to isolate a build from the contents of $(brew --prefix)/bin.

carlocab added a commit to Homebrew/homebrew-core that referenced this issue Aug 10, 2022
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

4 participants