Skip to content

Commit

Permalink
Merge pull request #18663 from Homebrew/python-reduce-pth
Browse files Browse the repository at this point in the history
language/python: reduce dependencies added to pth file
  • Loading branch information
MikeMcQuaid authored Oct 31, 2024
2 parents 702bfe1 + fdabc2f commit 90c043e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,21 @@ def virtualenv_create(venv_root, python = "python", formula = T.cast(self, Formu
venv.create(system_site_packages:, without_pip:)

# Find any Python bindings provided by recursive dependencies
formula_deps = formula.recursive_dependencies
pth_contents = formula_deps.filter_map do |d|
next if d.build? || d.test?
pth_contents = []
formula.recursive_dependencies do |dependent, dep|
Dependency.prune if dep.build? || dep.test?
# Apply default filter
Dependency.prune if (dep.optional? || dep.recommended?) && !dependent.build.with?(dep)
# Do not add the main site-package provided by the brewed
# Python formula, to keep the virtual-env's site-package pristine
next if python_names.include? d.name
Dependency.prune if python_names.include? dep.name
# Skip uses_from_macos dependencies as these imply no Python bindings
Dependency.prune if dep.uses_from_macos?

dep_site_packages = Formula[d.name].opt_prefix/Language::Python.site_packages(python)
next unless dep_site_packages.exist?
dep_site_packages = dep.to_formula.opt_prefix/Language::Python.site_packages(python)
Dependency.prune unless dep_site_packages.exist?

"import site; site.addsitedir('#{dep_site_packages}')\n"
pth_contents << "import site; site.addsitedir('#{dep_site_packages}')\n"
end
(venv.site_packages/"homebrew_deps.pth").write pth_contents.join unless pth_contents.empty?

Expand Down

0 comments on commit 90c043e

Please sign in to comment.