Team Ai
Modelpublic

apriltwentieth/python3.rb

sourceHugging Faceupdated 9d agoView on Hugging Face
0likes
python3.rb405 linesDownload Raw Back to root
1class Python3 < Formula2  desc "Interpreted, interactive, object-oriented programming language"3  homepage "https://www.python.org/"4  #url "https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz"5  #url "https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tar.xz"6  url "https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz"7  sha256 "5a99f8e7a6a11a7b98b4e75e0d1303d3832cada5534068f69c7b6222a7b1b002"8 9  bottle do10    revision 211    sha256 "41179565238d894d6b36e7b43eae2f00e6d774b8bebad2f8bf7e04519f8ab2c7" => :el_capitan12    sha256 "290b97611927bfb0b1b8ca7bd117ec14c895ec564d12f1e9847a1ad5a2401e85" => :yosemite13    sha256 "597726c76865052c9797b8542495c58182b25cd7335ce63e551d9dfbdbc0e2d0" => :mavericks14  end15 16  head "https://hg.python.org/cpython", :using => :hg17 18  option :universal19  option "with-tcl-tk", "Use Homebrew's Tk instead of OS X Tk (has optional Cocoa and threads support)"20  option "with-quicktest", "Run `make quicktest` after the build"21 22  deprecated_option "quicktest" => "with-quicktest"23  deprecated_option "with-brewed-tk" => "with-tcl-tk"24 25  depends_on "pkg-config" => :build26  depends_on "readline" => :recommended27  depends_on "sqlite" => :recommended28  depends_on "gdbm" => :recommended29  depends_on "openssl"30  depends_on "xz" => :recommended # for the lzma module added in 3.331  depends_on "homebrew/dupes/tcl-tk" => :optional32  depends_on :x11 if build.with?("tcl-tk") && Tab.for_name("homebrew/dupes/tcl-tk").with?("x11")33 34  skip_clean "bin/pip3", "bin/pip-3.4", "bin/pip-3.5"35  skip_clean "bin/easy_install3", "bin/easy_install-3.4", "bin/easy_install-3.5"36 37  resource "setuptools" do38    url "https://pypi.python.org/packages/source/s/setuptools/setuptools-19.4.tar.gz"39    sha256 "214bf29933f47cf25e6faa569f710731728a07a19cae91ea64f826051f68a8cf"40  end41 42  resource "pip" do43    url "https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz"44    sha256 "46f4bd0d8dfd51125a554568d646fe4200a3c2c6c36b9f2d06d2212148439521"45  end46 47  resource "wheel" do48    url "https://pypi.python.org/packages/source/w/wheel/wheel-0.26.0.tar.gz"49    sha256 "eaad353805c180a47545a256e6508835b65a8e830ba1093ed8162f19a50a530c"50  end51 52  fails_with :clang do53    build 42554    cause "https://bugs.python.org/issue24844"55  end56 57  # Homebrew's tcl-tk is built in a standard unix fashion (due to link errors)58  # so we have to stop python from searching for frameworks and linking against59  # X11.60  patch :DATA if build.with? "tcl-tk"61 62  # Fix extension module builds against Xcode 7 SDKs63  # https://github.com/Homebrew/homebrew/issues/4108564  # https://bugs.python.org/issue2513665  #patch do66  #  url "https://bugs.python.org/file40478/xcode-stubs.diff"67  #  sha256 "029cc0dc72b1bcf4ddc5f913cc4a3fd970378073c6355921891f041aca2f8b12"68  #end69 70  def lib_cellar71    prefix/"Frameworks/Python.framework/Versions/#{xy}/lib/python#{xy}"72  end73 74  def site_packages_cellar75    lib_cellar/"site-packages"76  end77 78  # The HOMEBREW_PREFIX location of site-packages.79  def site_packages80    HOMEBREW_PREFIX/"lib/python#{xy}/site-packages"81  end82 83  fails_with :llvm do84    build 233685    cause <<-EOS.undent86      Could not find platform dependent libraries <exec_prefix>87      Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]88      python.exe(14122) malloc: *** mmap(size=7310873954244194304) failed (error code=12)89      *** error: can't allocate region90      *** set a breakpoint in malloc_error_break to debug91      Could not import runpy module92      make: *** [pybuilddir.txt] Segmentation fault: 1193    EOS94  end95 96  # setuptools remembers the build flags python is built with and uses them to97  # build packages later. Xcode-only systems need different flags.98  pour_bottle? do99    reason "The bottle needs the Xcode CLT to be installed."100    satisfy { MacOS::CLT.installed? }101  end102 103  def install104    # Unset these so that installing pip and setuptools puts them where we want105    # and not into some other Python the user has installed.106    ENV["PYTHONHOME"] = nil107    ENV["PYTHONPATH"] = nil108 109    args = %W[110      --prefix=#{prefix}111      --enable-ipv6112      --datarootdir=#{share}113      --datadir=#{share}114      --enable-framework=#{frameworks}115      --without-ensurepip116    ]117 118    args << "--without-gcc" if ENV.compiler == :clang119 120    cflags   = []121    ldflags  = []122    cppflags = []123 124    unless MacOS::CLT.installed?125      # Help Python's build system (setuptools/pip) to build things on Xcode-only systems126      # The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)127      cflags   << "-isysroot #{MacOS.sdk_path}"128      ldflags  << "-isysroot #{MacOS.sdk_path}"129      cppflags << "-I#{MacOS.sdk_path}/usr/include" # find zlib130      # For the Xlib.h, Python needs this header dir with the system Tk131      if build.without? "tcl-tk"132        cflags << "-I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"133      end134    end135    # Avoid linking to libgcc http://code.activestate.com/lists/python-dev/112195/136    args << "MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}"137 138    # We want our readline and openssl! This is just to outsmart the detection code,139    # superenv makes cc always find includes/libs!140    #inreplace "setup.py" do |s|141    #  s.gsub! "do_readline = self.compiler.find_library_file(lib_dirs, 'readline')",142    #          "do_readline = '#{Formula["readline"].opt_lib}/libhistory.dylib'"143    #  s.gsub! "/usr/local/ssl", Formula["openssl"].opt_prefix144    #end145 146    if build.universal?147      ENV.universal_binary148      args << "--enable-universalsdk" << "--with-universal-archs=intel"149    end150 151    # Allow sqlite3 module to load extensions: http://docs.python.org/library/sqlite3.html#f1152    inreplace("setup.py", 'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))', "pass") if build.with? "sqlite"153 154    # Allow python modules to use ctypes.find_library to find homebrew's stuff155    # even if homebrew is not a /usr/local/lib. Try this with:156    # `brew install enchant && pip install pyenchant`157    inreplace "./Lib/ctypes/macholib/dyld.py" do |f|158      f.gsub! "DEFAULT_LIBRARY_FALLBACK = [", "DEFAULT_LIBRARY_FALLBACK = [ '#{HOMEBREW_PREFIX}/lib',"159      f.gsub! "DEFAULT_FRAMEWORK_FALLBACK = [", "DEFAULT_FRAMEWORK_FALLBACK = [ '#{HOMEBREW_PREFIX}/Frameworks',"160    end161 162    if build.with? "tcl-tk"163      tcl_tk = Formula["tcl-tk"].opt_prefix164      cppflags << "-I#{tcl_tk}/include"165      ldflags  << "-L#{tcl_tk}/lib"166    end167 168    args << "CFLAGS=#{cflags.join(" ")}" unless cflags.empty?169    args << "LDFLAGS=#{ldflags.join(" ")}" unless ldflags.empty?170    args << "CPPFLAGS=#{cppflags.join(" ")}" unless cppflags.empty?171 172    system "./configure", *args173 174    system "make"175 176    ENV.deparallelize # Installs must be serialized177    # Tell Python not to install into /Applications (default for framework builds)178    system "make", "install", "PYTHONAPPSDIR=#{prefix}"179    # Demos and Tools180    system "make", "frameworkinstallextras", "PYTHONAPPSDIR=#{share}/python3"181    system "make", "quicktest" if build.with? "quicktest"182 183    # Any .app get a " 3" attached, so it does not conflict with python 2.x.184    Dir.glob("#{prefix}/*.app") { |app| mv app, app.sub(".app", " 3.app") }185 186    # A fix, because python and python3 both want to install Python.framework187    # and therefore we can't link both into HOMEBREW_PREFIX/Frameworks188    # https://github.com/Homebrew/homebrew/issues/15943189    ["Headers", "Python", "Resources"].each { |f| rm(prefix/"Frameworks/Python.framework/#{f}") }190    rm prefix/"Frameworks/Python.framework/Versions/Current"191 192    # Symlink the pkgconfig files into HOMEBREW_PREFIX so they're accessible.193    (lib/"pkgconfig").install_symlink Dir["#{frameworks}/Python.framework/Versions/#{xy}/lib/pkgconfig/*"]194 195    # Remove 2to3 because python2 also installs it196    rm bin/"2to3"197 198    # Remove the site-packages that Python created in its Cellar.199    site_packages_cellar.rmtree200 201    # These makevars are available through distutils.sysconfig at runtime and202    # some third-party software packages depend on them203    inreplace Dir.glob(frameworks/"Python.framework/Versions/#{xy}/lib/python#{xy}/config-#{xy}*/Makefile") do |s|204      s.change_make_var! "LINKFORSHARED",205                         "-u _PyMac_Error #{opt_prefix}/Frameworks/Python.framework/Versions/#{xy}/Python"206    end207 208    %w[setuptools pip wheel].each do |r|209      (libexec/r).install resource(r)210    end211  end212 213  def post_install214    # Fix up the site-packages so that user-installed Python software survives215    # minor updates, such as going from 3.3.2 to 3.3.3:216 217    # Create a site-packages in HOMEBREW_PREFIX/lib/python#{xy}/site-packages218    site_packages.mkpath219 220    # Symlink the prefix site-packages into the cellar.221    site_packages_cellar.unlink if site_packages_cellar.exist?222    site_packages_cellar.parent.install_symlink site_packages223 224    # Write our sitecustomize.py225    rm_rf Dir["#{site_packages}/sitecustomize.py[co]"]226    (site_packages/"sitecustomize.py").atomic_write(sitecustomize)227 228    # Remove old setuptools installations that may still fly around and be229    # listed in the easy_install.pth. This can break setuptools build with230    # zipimport.ZipImportError: bad local file header231    # setuptools-0.9.8-py3.3.egg232    rm_rf Dir["#{site_packages}/setuptools*"]233    rm_rf Dir["#{site_packages}/distribute*"]234    rm_rf Dir["#{site_packages}/pip[-_.][0-9]*", "#{site_packages}/pip"]235 236    %w[setuptools pip wheel].each do |pkg|237      (libexec/pkg).cd do238        system bin/"python3", "-s", "setup.py", "--no-user-cfg", "install",239               "--force", "--verbose", "--install-scripts=#{bin}",240               "--install-lib=#{site_packages}",241               "--single-version-externally-managed",242               "--record=installed.txt"243      end244    end245 246    rm_rf [bin/"pip", bin/"easy_install"]247    mv bin/"wheel", bin/"wheel3"248 249    # post_install happens after link250    %W[pip3 pip#{xy} easy_install-#{xy} wheel3].each do |e|251      (HOMEBREW_PREFIX/"bin").install_symlink bin/e252    end253 254    # Help distutils find brewed stuff when building extensions255    include_dirs = [HOMEBREW_PREFIX/"include", Formula["openssl"].opt_include]256    library_dirs = [HOMEBREW_PREFIX/"lib", Formula["openssl"].opt_lib]257 258    if build.with? "sqlite"259      include_dirs << Formula["sqlite"].opt_include260      library_dirs << Formula["sqlite"].opt_lib261    end262 263    if build.with? "tcl-tk"264      include_dirs << Formula["homebrew/dupes/tcl-tk"].opt_include265      library_dirs << Formula["homebrew/dupes/tcl-tk"].opt_lib266    end267 268    cfg = lib_cellar/"distutils/distutils.cfg"269    cfg.atomic_write <<-EOF.undent270      [install]271      prefix=#{HOMEBREW_PREFIX}272 273      [build_ext]274      include_dirs=#{include_dirs.join ":"}275      library_dirs=#{library_dirs.join ":"}276    EOF277  end278 279  def xy280    version.to_s.slice(/(3.\d)/) || "3.6"281  end282 283  def sitecustomize284    <<-EOF.undent285      # This file is created by Homebrew and is executed on each python startup.286      # Don't print from here, or else python command line scripts may fail!287      # <https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md>288      import re289      import os290      import sys291 292      if sys.version_info[0] != 3:293          # This can only happen if the user has set the PYTHONPATH for 3.x and run Python 2.x or vice versa.294          # Every Python looks at the PYTHONPATH variable and we can't fix it here in sitecustomize.py,295          # because the PYTHONPATH is evaluated after the sitecustomize.py. Many modules (e.g. PyQt4) are296          # built only for a specific version of Python and will fail with cryptic error messages.297          # In the end this means: Don't set the PYTHONPATH permanently if you use different Python versions.298          exit('Your PYTHONPATH points to a site-packages dir for Python 3.x but you are running Python ' +299               str(sys.version_info[0]) + '.x!\\n     PYTHONPATH is currently: "' + str(os.environ['PYTHONPATH']) + '"\\n' +300               '     You should `unset PYTHONPATH` to fix this.')301 302      # Only do this for a brewed python:303      if os.path.realpath(sys.executable).startswith('#{rack}'):304          # Shuffle /Library site-packages to the end of sys.path305          library_site = '/Library/Python/#{xy}/site-packages'306          library_packages = [p for p in sys.path if p.startswith(library_site)]307          sys.path = [p for p in sys.path if not p.startswith(library_site)]308          # .pth files have already been processed so don't use addsitedir309          sys.path.extend(library_packages)310 311          # the Cellar site-packages is a symlink to the HOMEBREW_PREFIX312          # site_packages; prefer the shorter paths313          long_prefix = re.compile(r'#{rack}/[0-9\._abrc]+/Frameworks/Python\.framework/Versions/#{xy}/lib/python#{xy}/site-packages')314          sys.path = [long_prefix.sub('#{site_packages}', p) for p in sys.path]315 316          # Set the sys.executable to use the opt_prefix317          sys.executable = '#{opt_bin}/python#{xy}'318    EOF319  end320 321  def caveats322    text = <<-EOS.undent323      Pip and setuptools have been installed. To update them324        pip3 install --upgrade pip setuptools325 326      You can install Python packages with327        pip3 install <package>328 329      They will install into the site-package directory330        #{site_packages}331 332      See: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md333    EOS334 335    # Tk warning only for 10.6336    tk_caveats = <<-EOS.undent337 338      Apple's Tcl/Tk is not recommended for use with Python on Mac OS X 10.6.339      For more information see: http://www.python.org/download/mac/tcltk/340    EOS341 342    text += tk_caveats unless MacOS.version >= :lion343    text344  end345 346  test do347    # Check if sqlite is ok, because we build with --enable-loadable-sqlite-extensions348    # and it can occur that building sqlite silently fails if OSX's sqlite is used.349    system "#{bin}/python#{xy}", "-c", "import sqlite3"350    # Check if some other modules import. Then the linked libs are working.351    system "#{bin}/python#{xy}", "-c", "import tkinter; root = tkinter.Tk()"352    system bin/"pip3", "list"353  end354end355 356__END__357diff --git a/setup.py b/setup.py358index 2779658..902d0eb 100644359--- a/setup.py360+++ b/setup.py361@@ -1699,9 +1699,6 @@ class PyBuildExt(build_ext):362         # Rather than complicate the code below, detecting and building363         # AquaTk is a separate method. Only one Tkinter will be built on364         # Darwin - either AquaTk, if it is found, or X11 based Tk.365-        if (host_platform == 'darwin' and366-            self.detect_tkinter_darwin(inc_dirs, lib_dirs)):367-            return368 369         # Assume we haven't found any of the libraries or include files370         # The versions with dots are used on Unix, and the versions without371@@ -1747,22 +1744,6 @@ class PyBuildExt(build_ext):372             if dir not in include_dirs:373                 include_dirs.append(dir)374 375-        # Check for various platform-specific directories376-        if host_platform == 'sunos5':377-            include_dirs.append('/usr/openwin/include')378-            added_lib_dirs.append('/usr/openwin/lib')379-        elif os.path.exists('/usr/X11R6/include'):380-            include_dirs.append('/usr/X11R6/include')381-            added_lib_dirs.append('/usr/X11R6/lib64')382-            added_lib_dirs.append('/usr/X11R6/lib')383-        elif os.path.exists('/usr/X11R5/include'):384-            include_dirs.append('/usr/X11R5/include')385-            added_lib_dirs.append('/usr/X11R5/lib')386-        else:387-            # Assume default location for X11388-            include_dirs.append('/usr/X11/include')389-            added_lib_dirs.append('/usr/X11/lib')390-391         # If Cygwin, then verify that X is installed before proceeding392         if host_platform == 'cygwin':393             x11_inc = find_file('X11/Xlib.h', [], include_dirs)394@@ -1786,10 +1767,6 @@ class PyBuildExt(build_ext):395         if host_platform in ['aix3', 'aix4']:396             libs.append('ld')397 398-        # Finally, link with the X11 libraries (not appropriate on cygwin)399-        if host_platform != "cygwin":400-            libs.append('X11')401-402         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],403                         define_macros=[('WITH_APPINIT', 1)] + defs,404                         include_dirs = include_dirs,405