Skip to content

Commit a87211a

Browse files
authored
Merge pull request #66 from codrsquad/sanitize-homebrew
Remove /opt/homebrew mentions from PATH
2 parents 4d05279 + 505bbda commit a87211a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/portable_python/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,16 @@ def compile(self):
680680
runez.decompress(path, self.m_src_build, simplify=True)
681681

682682
env_vars = self._get_env_vars()
683+
if not PPG.config.get_value("allow-homebrew"):
684+
# Remove any mention of /opt/homebrew from PATH (reduce chances of dynamic links to homebrew)
685+
path_env_var = env_vars.get("PATH")
686+
if path_env_var:
687+
_paths = os.environ.get("PATH", "").split(":")
688+
_revised = [p for p in _paths if not p.startswith("/opt/homebrew")]
689+
if _revised != _paths:
690+
LOG.info("Removed /opt/homebrew mentions from PATH")
691+
env_vars["PATH"] = runez.joined(_revised, delimiter=":")
692+
683693
prev_env_vars = {}
684694
for var_name, value in env_vars.items():
685695
LOG.info("env %s=%s", var_name, runez.short(value, size=2048))

0 commit comments

Comments
 (0)