Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7abc6c7

Browse files
committedFeb 15, 2024
audit: check for Python-wide site-package usage
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.
1 parent 9475258 commit 7abc6c7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎Library/Homebrew/formula_cellar_checks.rb

+13
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ def check_easy_install_pth(lib)
143143
EOS
144144
end
145145

146+
def check_global_site_package_usage(lib)
147+
install_found = Dir["#{lib}/python{3}*/site-packages/"].map { |f| File.dirname(f) }
148+
return if install_found.empty?
149+
150+
<<~EOS
151+
Python-wide site-packages usage detected. This is not allowed in Homebrew (see PEP 668).
152+
Please either vendor this Python library or install it in libexec using a virtualenv.
153+
The offending files are:
154+
#{install_found * "site-packages/\n "}
155+
EOS
156+
end
157+
146158
def check_elisp_dirname(share, name)
147159
return unless (share/"emacs/site-lisp").directory?
148160
# Emacs itself can do what it wants
@@ -397,6 +409,7 @@ def audit_installed
397409
problem_if_output(check_non_executables(formula.sbin))
398410
problem_if_output(check_generic_executables(formula.sbin))
399411
problem_if_output(check_easy_install_pth(formula.lib))
412+
problem_if_output(check_global_site_package_usage(formula.lib))
400413
problem_if_output(check_elisp_dirname(formula.share, formula.name))
401414
problem_if_output(check_elisp_root(formula.share, formula.name))
402415
problem_if_output(check_python_packages(formula.lib, formula.deps))

0 commit comments

Comments
 (0)
Please sign in to comment.