Skip to content
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

python: make python@3.11 the new default for python3 #114154

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Aliases/python
2 changes: 1 addition & 1 deletion Aliases/python-tk
2 changes: 1 addition & 1 deletion Aliases/python3
2 changes: 1 addition & 1 deletion Aliases/python@3
69 changes: 37 additions & 32 deletions Formula/python@3.10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ class PythonAT310 < Formula
skip_clean "bin/easy_install3", "bin/easy_install-3.4", "bin/easy_install-3.5", "bin/easy_install-3.6",
"bin/easy_install-3.7", "bin/easy_install-3.8", "bin/easy_install-3.9"

link_overwrite "bin/2to3"
link_overwrite "bin/idle3"
link_overwrite "bin/pip3"
link_overwrite "bin/pydoc3"
link_overwrite "bin/python3"
link_overwrite "bin/python3-config"
link_overwrite "bin/wheel3"
link_overwrite "share/man/man1/python3.1"
link_overwrite "lib/libpython3.so"
link_overwrite "lib/pkgconfig/python3.pc"
link_overwrite "lib/pkgconfig/python3-embed.pc"
link_overwrite "Frameworks/Python.framework/Headers"
link_overwrite "Frameworks/Python.framework/Python"
link_overwrite "Frameworks/Python.framework/Resources"
link_overwrite "Frameworks/Python.framework/Versions/Current"

# Always update to latest release
resource "setuptools" do
url "https://files.pythonhosted.org/packages/5f/36/7374297692bb9dbd7569a0f84887c7e5e314c41d5d9518cb76fbb130620d/setuptools-67.2.0.tar.gz"
Expand Down Expand Up @@ -226,8 +210,12 @@ def install
system "make"

ENV.deparallelize do
# The `altinstall` target prevents the installation of files with only Python's major
# version in its name. This allows us to link multiple versioned Python formulae.
# https://github.com/python/cpython#installing-multiple-versions
#
# Tell Python not to install into /Applications (default for framework builds)
system "make", "install", "PYTHONAPPSDIR=#{prefix}"
system "make", "altinstall", "PYTHONAPPSDIR=#{prefix}"
system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{pkgshare}" if OS.mac?
end

Expand All @@ -253,10 +241,16 @@ def install
/^LINKFORSHARED=(.*)PYTHONFRAMEWORKDIR(.*)/,
"LINKFORSHARED=\\1PYTHONFRAMEWORKINSTALLDIR\\2"

# Symlink the pkgconfig files into HOMEBREW_PREFIX so they're accessible.
(lib/"pkgconfig").install_symlink pc_dir.children

# Fix for https://github.com/Homebrew/homebrew-core/issues/21212
inreplace lib_cellar/"_sysconfigdata__darwin_darwin.py",
%r{('LINKFORSHARED': .*?)'(Python.framework/Versions/3.\d+/Python)'}m,
"\\1'#{opt_prefix}/Frameworks/\\2'"

# Remove symlinks that conflict with the main Python formula.
rm %w[Headers Python Resources Versions/Current].map { |subdir| frameworks/"Python.framework"/subdir }
else
# Prevent third-party packages from building against fragile Cellar paths
inreplace Dir[lib_cellar/"**/_sysconfigdata_*linux_x86_64-*.py",
Expand All @@ -268,6 +262,9 @@ def install
inreplace bin/"python#{version.major_minor}-config",
'prefix_real=$(installed_prefix "$0")',
"prefix_real=#{opt_prefix}"

# Remove symlinks that conflict with the main Python formula.
rm lib/"libpython3.so"
end

# Remove the site-packages that Python created in its Cellar.
Expand Down Expand Up @@ -309,12 +306,16 @@ def install
# Write out sitecustomize.py
(lib_cellar/"sitecustomize.py").atomic_write(sitecustomize)

# Install unversioned symlinks in libexec/bin.
# Install unversioned and major-versioned symlinks in libexec/bin.
{
"idle" => "idle#{version.major_minor}",
"pydoc" => "pydoc#{version.major_minor}",
"python" => "python#{version.major_minor}",
"python-config" => "python#{version.major_minor}-config",
"idle" => "idle#{version.major_minor}",
"idle3" => "idle#{version.major_minor}",
"pydoc" => "pydoc#{version.major_minor}",
"pydoc3" => "pydoc#{version.major_minor}",
"python" => "python#{version.major_minor}",
"python3" => "python#{version.major_minor}",
"python-config" => "python#{version.major_minor}-config",
"python3-config" => "python#{version.major_minor}-config",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end
Expand Down Expand Up @@ -368,20 +369,21 @@ def post_install
mv (site_packages/"bin").children, bin
rmdir site_packages/"bin"

rm_rf bin/"pip"
rm_rf bin.glob("pip{,3}")
mv bin/"wheel", bin/"wheel#{version.major_minor}"
bin.install_symlink "wheel#{version.major_minor}" => "wheel3"

# Install unversioned symlinks in libexec/bin.
# Install unversioned and major-versioned symlinks in libexec/bin.
{
"pip" => "pip#{version.major_minor}",
"wheel" => "wheel#{version.major_minor}",
"pip" => "pip#{version.major_minor}",
"pip3" => "pip#{version.major_minor}",
"wheel" => "wheel#{version.major_minor}",
"wheel3" => "wheel#{version.major_minor}",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end

# post_install happens after link
%W[wheel3 pip3 wheel#{version.major_minor} pip#{version.major_minor}].each do |e|
%W[wheel#{version.major_minor} pip#{version.major_minor}].each do |e|
(HOMEBREW_PREFIX/"bin").install_symlink bin/e
end
end
Expand Down Expand Up @@ -445,20 +447,23 @@ def sitecustomize
def caveats
<<~EOS
Python has been installed as
#{HOMEBREW_PREFIX}/bin/python3
#{HOMEBREW_PREFIX}/bin/python#{version.major_minor}

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
Unversioned and major-versioned symlinks `python`, `python3`, `python-config`, `python3-config`, `pip`, `pip3`, etc. pointing to
`python#{version.major_minor}`, `python#{version.major_minor}-config`, `pip#{version.major_minor}` etc., respectively, have been installed into
#{opt_libexec}/bin

You can install Python packages with
pip3 install <package>
pip#{version.major_minor} install <package>
They will install into the site-package directory
#{HOMEBREW_PREFIX}/lib/python#{version.major_minor}/site-packages

tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@#{version.major_minor}

If you do not need a specific version of Python, and always want Homebrew's `python3` in your PATH:
brew install python3

See: https://docs.brew.sh/Homebrew-and-Python
EOS
end
Expand Down
66 changes: 32 additions & 34 deletions Formula/python@3.11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ class PythonAT311 < Formula
skip_clean "bin/easy_install3", "bin/easy_install-3.4", "bin/easy_install-3.5", "bin/easy_install-3.6",
"bin/easy_install-3.7", "bin/easy_install-3.8", "bin/easy_install-3.9", "bin/easy_install-3.10"

link_overwrite "bin/2to3"
link_overwrite "bin/idle3"
link_overwrite "bin/pip3"
link_overwrite "bin/pydoc3"
link_overwrite "bin/python3"
link_overwrite "bin/python3-config"
link_overwrite "bin/wheel3"
link_overwrite "share/man/man1/python3.1"
link_overwrite "lib/libpython3.so"
link_overwrite "lib/pkgconfig/python3.pc"
link_overwrite "lib/pkgconfig/python3-embed.pc"
link_overwrite "Frameworks/Python.framework/Headers"
link_overwrite "Frameworks/Python.framework/Python"
link_overwrite "Frameworks/Python.framework/Resources"
link_overwrite "Frameworks/Python.framework/Versions/Current"

# Always update to latest release
resource "setuptools" do
url "https://files.pythonhosted.org/packages/b6/21/cb9a8d0b2c8597c83fce8e9c02884bce3d4951e41e807fc35791c6b23d9a/setuptools-65.6.3.tar.gz"
Expand Down Expand Up @@ -213,12 +229,8 @@ def install
system "make"

ENV.deparallelize do
# The `altinstall` target prevents the installation of files with only Python's major
# version in its name. This allows us to link multiple versioned Python formulae.
# https://github.com/python/cpython#installing-multiple-versions
#
# Tell Python not to install into /Applications (default for framework builds)
system "make", "altinstall", "PYTHONAPPSDIR=#{prefix}"
system "make", "install", "PYTHONAPPSDIR=#{prefix}"
system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{pkgshare}" if OS.mac?
end

Expand Down Expand Up @@ -251,9 +263,6 @@ def install
inreplace lib_cellar/"_sysconfigdata__darwin_darwin.py",
%r{('LINKFORSHARED': .*?)'(Python.framework/Versions/3.\d+/Python)'}m,
"\\1'#{opt_prefix}/Frameworks/\\2'"

# Remove symlinks that conflict with the main Python formula.
rm %w[Headers Python Resources Versions/Current].map { |subdir| frameworks/"Python.framework"/subdir }
else
# Prevent third-party packages from building against fragile Cellar paths
inreplace Dir[lib_cellar/"**/_sysconfigdata_*linux_x86_64-*.py",
Expand All @@ -265,9 +274,6 @@ def install
inreplace bin/"python#{version.major_minor}-config",
'prefix_real=$(installed_prefix "$0")',
"prefix_real=#{opt_prefix}"

# Remove symlinks that conflict with the main Python formula.
rm lib/"libpython3.so"
end

# Remove the site-packages that Python created in its Cellar.
Expand Down Expand Up @@ -309,16 +315,12 @@ def install
# Write out sitecustomize.py
(lib_cellar/"sitecustomize.py").atomic_write(sitecustomize)

# Install unversioned and major-versioned symlinks in libexec/bin.
# Install unversioned symlinks in libexec/bin.
{
"idle" => "idle#{version.major_minor}",
"idle3" => "idle#{version.major_minor}",
"pydoc" => "pydoc#{version.major_minor}",
"pydoc3" => "pydoc#{version.major_minor}",
"python" => "python#{version.major_minor}",
"python3" => "python#{version.major_minor}",
"python-config" => "python#{version.major_minor}-config",
"python3-config" => "python#{version.major_minor}-config",
"idle" => "idle#{version.major_minor}",
"pydoc" => "pydoc#{version.major_minor}",
"python" => "python#{version.major_minor}",
"python-config" => "python#{version.major_minor}-config",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end
Expand Down Expand Up @@ -372,21 +374,20 @@ def post_install
mv (site_packages/"bin").children, bin
rmdir site_packages/"bin"

rm_rf bin.glob("pip{,3}")
rm_rf bin/"pip"
mv bin/"wheel", bin/"wheel#{version.major_minor}"
bin.install_symlink "wheel#{version.major_minor}" => "wheel3"

# Install unversioned and major-versioned symlinks in libexec/bin.
# Install unversioned symlinks in libexec/bin.
{
"pip" => "pip#{version.major_minor}",
"pip3" => "pip#{version.major_minor}",
"wheel" => "wheel#{version.major_minor}",
"wheel3" => "wheel#{version.major_minor}",
"pip" => "pip#{version.major_minor}",
"wheel" => "wheel#{version.major_minor}",
}.each do |short_name, long_name|
(libexec/"bin").install_symlink (bin/long_name).realpath => short_name
end

# post_install happens after link
%W[wheel#{version.major_minor} pip#{version.major_minor}].each do |e|
%W[wheel3 pip3 wheel#{version.major_minor} pip#{version.major_minor}].each do |e|
(HOMEBREW_PREFIX/"bin").install_symlink bin/e
end
end
Expand Down Expand Up @@ -451,17 +452,14 @@ def sitecustomize
def caveats
<<~EOS
Python has been installed as
#{HOMEBREW_PREFIX}/bin/python#{version.major_minor}
#{HOMEBREW_PREFIX}/bin/python3

Unversioned and major-versioned symlinks `python`, `python3`, `python-config`, `python3-config`, `pip`, `pip3`, etc. pointing to
`python#{version.major_minor}`, `python#{version.major_minor}-config`, `pip#{version.major_minor}` etc., respectively, have been installed into
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
#{opt_libexec}/bin

If you do not need a specific version of Python, and always want Homebrew's `python3` in your PATH:
brew install python3

You can install Python packages with
pip#{version.major_minor} install <package>
pip3 install <package>
They will install into the site-package directory
#{HOMEBREW_PREFIX}/lib/python#{version.major_minor}/site-packages

Expand Down