Skip to content

Commit ea222b9

Browse files
committed
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 c355461 commit ea222b9

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

Diff for: Library/Homebrew/formula_cellar_checks.rb

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

146+
def check_global_site_package_usage(formula)
147+
return if !formula.tap.core_tap?
148+
return if !formula.stable.url.start_with?("https://files.pythonhosted.org")
149+
150+
lib = formula.lib
151+
global_site_package_found = Dir["#{lib}/python{3}*/site-packages/"].map { |f| File.dirname(f) }
152+
return if global_site_package_found.empty?
153+
154+
bindings_found = Dir["#{lib}/python{3}*/site-packages/**/*.so"].map { |f| File.dirname(f) }
155+
return if !bindings_found.empty?
156+
157+
<<~EOS
158+
Python-wide site-packages usage detected. This is not allowed in Homebrew (see PEP 668).
159+
Please either vendor this Python library or install it in libexec using a virtualenv.
160+
The offending files are:
161+
#{global_site_package_found * "\n "}
162+
EOS
163+
end
164+
146165
def check_elisp_dirname(share, name)
147166
return unless (share/"emacs/site-lisp").directory?
148167
# Emacs itself can do what it wants
@@ -387,24 +406,25 @@ def check_binary_arches(formula)
387406
def audit_installed
388407
@new_formula ||= false
389408

390-
problem_if_output(check_manpages)
391-
problem_if_output(check_infopages)
392-
problem_if_output(check_jars)
393-
problem_if_output(check_service_command(formula))
394-
problem_if_output(check_non_libraries) if @new_formula
395-
problem_if_output(check_non_executables(formula.bin))
396-
problem_if_output(check_generic_executables(formula.bin))
397-
problem_if_output(check_non_executables(formula.sbin))
398-
problem_if_output(check_generic_executables(formula.sbin))
399-
problem_if_output(check_easy_install_pth(formula.lib))
400-
problem_if_output(check_elisp_dirname(formula.share, formula.name))
401-
problem_if_output(check_elisp_root(formula.share, formula.name))
402-
problem_if_output(check_python_packages(formula.lib, formula.deps))
403-
problem_if_output(check_shim_references(formula.prefix))
404-
problem_if_output(check_plist(formula.prefix, formula.plist))
405-
problem_if_output(check_python_symlinks(formula.name, formula.keg_only?))
406-
problem_if_output(check_cpuid_instruction(formula))
407-
problem_if_output(check_binary_arches(formula))
409+
# problem_if_output(check_manpages)
410+
# problem_if_output(check_infopages)
411+
# problem_if_output(check_jars)
412+
# problem_if_output(check_service_command(formula))
413+
# problem_if_output(check_non_libraries) if @new_formula
414+
# problem_if_output(check_non_executables(formula.bin))
415+
# problem_if_output(check_generic_executables(formula.bin))
416+
# problem_if_output(check_non_executables(formula.sbin))
417+
# problem_if_output(check_generic_executables(formula.sbin))
418+
# problem_if_output(check_easy_install_pth(formula.lib))
419+
problem_if_output(check_global_site_package_usage(formula))
420+
# problem_if_output(check_elisp_dirname(formula.share, formula.name))
421+
# problem_if_output(check_elisp_root(formula.share, formula.name))
422+
# problem_if_output(check_python_packages(formula.lib, formula.deps))
423+
# problem_if_output(check_shim_references(formula.prefix))
424+
# problem_if_output(check_plist(formula.prefix, formula.plist))
425+
# problem_if_output(check_python_symlinks(formula.name, formula.keg_only?))
426+
# problem_if_output(check_cpuid_instruction(formula))
427+
# problem_if_output(check_binary_arches(formula))
408428
end
409429
alias generic_audit_installed audit_installed
410430

0 commit comments

Comments
 (0)