From dccece702ce38d209f7a8ce4f981790712cfb921 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 20 Oct 2020 09:44:11 -0400 Subject: [PATCH 1/2] audit: avoid python symlink conflict --- Library/Homebrew/formula_cellar_checks.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 7d7a31b179..9a0eb1ef77 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -265,6 +265,20 @@ module FormulaCellarChecks EOS end + PYTHON_SYMLINK_ALLOWED_FORMULA = "python@3.8" + + def check_python_symlinks(name) + return unless name.start_with? "python" + return if name == PYTHON_SYMLINK_ALLOWED_FORMULA + + return if %w[pip3 wheel3].none? do |l| + link = HOMEBREW_PREFIX/"bin"/l + link.exist? && File.realpath(link).start_with?(HOMEBREW_CELLAR/name) + end + + "Only `#{PYTHON_SYMLINK_ALLOWED_FORMULA}` should create symlinks for `pip3` and `wheel3`" + end + def audit_installed @new_formula ||= false @@ -282,6 +296,7 @@ module FormulaCellarChecks problem_if_output(check_python_packages(formula.lib, formula.deps)) problem_if_output(check_shim_references(formula.prefix)) problem_if_output(check_plist(formula.prefix, formula.plist)) + problem_if_output(check_python_symlinks(formula.name)) end alias generic_audit_installed audit_installed From 6e82f77108c326ede038d11a81fc6e9d9c229886 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 20 Oct 2020 12:46:23 -0400 Subject: [PATCH 2/2] audit: allow python symlinks based on keg-only status --- Library/Homebrew/formula_cellar_checks.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 9a0eb1ef77..f896caaf47 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -265,18 +265,16 @@ module FormulaCellarChecks EOS end - PYTHON_SYMLINK_ALLOWED_FORMULA = "python@3.8" - - def check_python_symlinks(name) + def check_python_symlinks(name, keg_only) + return unless keg_only return unless name.start_with? "python" - return if name == PYTHON_SYMLINK_ALLOWED_FORMULA return if %w[pip3 wheel3].none? do |l| link = HOMEBREW_PREFIX/"bin"/l link.exist? && File.realpath(link).start_with?(HOMEBREW_CELLAR/name) end - "Only `#{PYTHON_SYMLINK_ALLOWED_FORMULA}` should create symlinks for `pip3` and `wheel3`" + "Python formulae that are keg-only should not create `pip3` and `wheel3` symlinks" end def audit_installed @@ -296,7 +294,7 @@ module FormulaCellarChecks problem_if_output(check_python_packages(formula.lib, formula.deps)) problem_if_output(check_shim_references(formula.prefix)) problem_if_output(check_plist(formula.prefix, formula.plist)) - problem_if_output(check_python_symlinks(formula.name)) + problem_if_output(check_python_symlinks(formula.name, formula.keg_only?)) end alias generic_audit_installed audit_installed