-
-
Notifications
You must be signed in to change notification settings - Fork 13.2k
python-setuptools: build once and symlink #251186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,41 +7,51 @@ class PythonSetuptools < Formula | |
| revision 1 | ||
|
|
||
| bottle do | ||
| sha256 cellar: :any_skip_relocation, all: "90d1373d4b921632e3da896be98326b463867c0a4f9e742c6a98c09caae96fd7" | ||
| rebuild 1 | ||
| sha256 cellar: :any_skip_relocation, all: "3f1216774825c551075a7a28ca8c7412e56ddb635f495275e5c231801d3a5abd" | ||
| end | ||
|
|
||
| depends_on "[email protected]" => [:build, :test] | ||
| depends_on "[email protected]" => [:build, :test] | ||
| depends_on "[email protected]" => [:build, :test] | ||
| depends_on "[email protected]" => :test # keep on oldest python to support (externally managed and not EOL) | ||
|
|
||
| def pythons | ||
| deps.map(&:to_formula) | ||
| .select { |f| f.name.match?(/^python@\d\.\d+$/) } | ||
| .map { |f| f.opt_libexec/"bin/python" } | ||
| deps.filter_map { |dep| dep.to_formula if dep.name.start_with?("python@") } | ||
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| def install | ||
| inreplace_paths = %w[ | ||
| _distutils/compilers/C/unix.py | ||
| _vendor/platformdirs/unix.py | ||
| ] | ||
|
|
||
| pythons.each do |python| | ||
| system python, "-m", "pip", "install", *std_pip_args, "." | ||
|
|
||
| # Ensure uniform bottles | ||
| setuptools_site_packages = prefix/Language::Python.site_packages(python)/"setuptools" | ||
| inreplace setuptools_site_packages/"_vendor/platformdirs/macos.py", "/opt/homebrew", HOMEBREW_PREFIX | ||
|
|
||
| inreplace_files = inreplace_paths.map { |file| setuptools_site_packages/file } | ||
| inreplace_files += setuptools_site_packages.glob("_vendor/platformdirs-*dist-info/METADATA") | ||
| inreplace inreplace_files, "/usr/local", HOMEBREW_PREFIX | ||
| odie "Need exactly 2 python dependencies!" if pythons.count != 2 | ||
| oldest_python, python = pythons.sort_by(&:version) | ||
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| python_exe = python.opt_libexec/"bin/python" | ||
| system python_exe, "-m", "pip", "install", *std_pip_args, "." | ||
|
|
||
| # Pure python setuptools installation can be used on different Python versions | ||
| site_packages = prefix/Language::Python.site_packages(python_exe) | ||
| python.versioned_formulae.each do |extra_python| | ||
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| next if extra_python.version < oldest_python.version | ||
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Cannot use Python.site_packages as that requires formula to be installed | ||
| extra_site_packages = lib/"python#{extra_python.version.major_minor}/site-packages" | ||
| site_packages.find do |path| | ||
| next unless path.file? | ||
|
|
||
| target = extra_site_packages/path.relative_path_from(site_packages) | ||
| target.dirname.install_symlink path | ||
| end | ||
cho-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| # Ensure uniform bottles | ||
| setuptools_site_packages = site_packages/"setuptools" | ||
| inreplace_files = %W[ | ||
| #{setuptools_site_packages}/_distutils/compilers/C/unix.py | ||
| #{setuptools_site_packages}/_vendor/platformdirs/unix.py | ||
| ] + setuptools_site_packages.glob("_vendor/platformdirs-*dist-info/METADATA") | ||
| inreplace inreplace_files, "/usr/local", HOMEBREW_PREFIX | ||
| inreplace setuptools_site_packages/"_vendor/platformdirs/macos.py", "/opt/homebrew", HOMEBREW_PREFIX | ||
| end | ||
|
|
||
| test do | ||
| pythons.each do |python| | ||
| system python, "-c", "import setuptools" | ||
| system python.opt_libexec/"bin/python", "-c", "import setuptools" | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.