Skip to content

Commit

Permalink
audit: check for Python-wide site-package usage
Browse files Browse the repository at this point in the history
See Homebrew#16662

We would like to enforce vendoring for Python libraries,
or the usage of a virtualenv in the formula's libexec directory,
using a virtualenv.
  • Loading branch information
iMichka committed Feb 15, 2024
1 parent 9475258 commit 3ab092f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Library/Homebrew/formula_cellar_checks.rb
Expand Up @@ -143,6 +143,25 @@ def check_easy_install_pth(lib)
EOS
end

def check_global_site_package_usage(formula)
return if !formula.tap.core_tap?
return if !formula.stable.url.match?("https://files.pythonhosted.org")

lib = formula.lib
global_site_package_found = Dir["#{lib}/python{3}*/site-packages/"].map { |f| File.dirname(f) }
return if global_site_package_found.empty?

bindings_found = Dir["#{lib}/python{3}*/site-packages/**/*.so"].map { |f| File.dirname(f) }
return if !bindings_found.empty?

<<~EOS
Python-wide site-packages usage detected. This is not allowed in Homebrew (see PEP 668).
Please either vendor this Python library or install it in libexec using a virtualenv.
The offending files are:
#{global_site_package_found * "\n "}
EOS
end

def check_elisp_dirname(share, name)
return unless (share/"emacs/site-lisp").directory?
# Emacs itself can do what it wants
Expand Down Expand Up @@ -397,6 +416,7 @@ def audit_installed
problem_if_output(check_non_executables(formula.sbin))
problem_if_output(check_generic_executables(formula.sbin))
problem_if_output(check_easy_install_pth(formula.lib))
problem_if_output(check_global_site_package_usage(formula))
problem_if_output(check_elisp_dirname(formula.share, formula.name))
problem_if_output(check_elisp_root(formula.share, formula.name))
problem_if_output(check_python_packages(formula.lib, formula.deps))
Expand Down

0 comments on commit 3ab092f

Please sign in to comment.