aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2011-03-19 16:44:46 -0700
committerAdam Vandenberg2011-03-29 13:54:53 -0700
commit9028352dfe47015a87f33c32091b3d748b769cf3 (patch)
treed40d11342dc7654d1eb9c54d5dc2a8bad3e530cf /Library
parent804d7af0fc2d4818c70ecb2890bcee855b3f3ab2 (diff)
downloadhomebrew-9028352dfe47015a87f33c32091b3d748b769cf3.tar.bz2
python: better site-packages and install-scripts
Previous versions of the Python 2.x formula did not set up the site-packages and install-scripts folders in a way friendly to updates of Python itself.
Diffstat (limited to 'Library')
-rw-r--r--Library/Formula/distribute.rb45
-rw-r--r--Library/Formula/pip.rb108
-rw-r--r--Library/Formula/python.rb167
3 files changed, 75 insertions, 245 deletions
diff --git a/Library/Formula/distribute.rb b/Library/Formula/distribute.rb
deleted file mode 100644
index 181cb894a..000000000
--- a/Library/Formula/distribute.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'formula'
-
-class Distribute < Formula
- url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz'
- homepage 'http://pypi.python.org/pypi/distribute/0.6.14'
- md5 'ac607e05682116c06383b27a15e2db90'
-
- def caveats
- <<-EOS.undent
- This formula is only meant to be used against a Homebrew-built Python.
- It will install itself directly into Python's location in the Cellar.
- EOS
- end
-
- def install
- python = Formula.factory("python")
- unless python.installed?
- onoe "The Distribute brew is only meant to be used against a Homebrew-built Python."
- puts <<-EOS
- Homebrew's "distribute" formula is only meant to be installed against a Homebrew-
- built version of Python, but we couldn't find such a version.
-
- The system-provided Python comes with "easy_install" already installed, with the
- caveat that some Python packages don't install cleanly against Apple's customized
- versions of Python.
-
- To install distribute against a custom Python, download distribute from:
- http://pypi.python.org/pypi/distribute
- unzip, and run:
- /path/to/custom/python setup.py install
- EOS
- exit 99
- end
-
- system "#{python.bin}/python", "setup.py", "install",
- "--install-scripts", bin,
- "--install-purelib", python.site_packages,
- "--install-platlib", python.site_packages
-
- (prefix+"README.homebrew").write <<-EOF
-distribute's libraries were installed directly into:
- #{python.site_packages}
-EOF
- end
-end
diff --git a/Library/Formula/pip.rb b/Library/Formula/pip.rb
deleted file mode 100644
index 3295ea8a9..000000000
--- a/Library/Formula/pip.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-require 'formula'
-
-class Pip < Formula
- url 'http://pypi.python.org/packages/source/p/pip/pip-0.8.2.tar.gz'
- homepage 'http://pip.openplans.org/'
- md5 'df1eca0abe7643d92b5222240bed15f6'
-
- depends_on 'distribute'
-
- def patches
- # Create a locations branch for darwin with placeholders
- DATA
- end
-
- def install
- python = Formula.factory("python")
- unless python.installed?
- onoe "The \"pip\" brew is only meant to be used against a Homebrew-built Python."
- puts <<-EOS
- Homebrew's "pip" formula is only meant to be installed against a Homebrew-
- built version of Python, but we couldn't find such a version.
-
- The system-provided Python comes with "easy_install" already installed, with the
- caveat that some Python packages don't install cleanly against Apple's customized
- versions of Python.
-
- To install pip against a custom Python:
- First download distribute from:
- http://pypi.python.org/pypi/distribute
- unzip, and run:
- /path/to/custom/python setup.py install
-
- Then download pip from:
- http://pypi.python.org/pypi/pip
- unzip, and run:
- /path/to/custom/python setup.py install
- EOS
- exit 99
- end
-
- inreplace 'pip/locations.py' do |s|
- # Replace placeholders with HOMEBREW paths
- s.gsub! '#BUILD_PREFIX#', "'#{var}/pip/build'"
- s.gsub! '#SRC_PREFIX#', "'#{var}/pip/src'"
- s.gsub! '#STORAGE_DIR#', "'#{var}/pip'"
- s.gsub! '#CONFIG_FILE#', "'#{etc}/pip.conf'"
- s.gsub! '#LOG_FILE#', "'#{var}/pip/pip.log'"
- end
-
- system "#{python.bin}/python", "setup.py", "install",
- "--install-scripts", bin,
- "--install-purelib", python.site_packages,
- "--install-platlib", python.site_packages
-
- (prefix+"README.homebrew").write <<-EOF
-pip's libraries were installed directly into:
- #{python.site_packages}
-EOF
- end
-
- def caveats
- <<-EOS.undent
- This formula is only meant to be used against a Homebrew-built Python.
- It will install itself directly into Python's location in the Cellar.
-
- Pip's configuration file lives at:
- #{etc}/pip.conf
- EOS
- end
-end
-
-
-__END__
-diff --git a/pip/locations.py b/pip/locations.py
-index 4254ef2..0a31cc2 100644
---- a/pip/locations.py
-+++ b/pip/locations.py
-@@ -19,8 +19,8 @@ if running_under_virtualenv():
- src_prefix = os.path.join(sys.prefix, 'src')
- else:
- ## FIXME: this isn't a very good default
-- build_prefix = os.path.join(os.getcwd(), 'build')
-- src_prefix = os.path.join(os.getcwd(), 'src')
-+ build_prefix = #BUILD_PREFIX#
-+ src_prefix = #SRC_PREFIX#
-
- # FIXME doesn't account for venv linked to global site-packages
-
-@@ -35,11 +35,16 @@ if sys.platform == 'win32':
- default_storage_dir = os.path.join(user_dir, 'pip')
- default_config_file = os.path.join(default_storage_dir, 'pip.ini')
- default_log_file = os.path.join(default_storage_dir, 'pip.log')
-+elif sys.platform[:6] == 'darwin':
-+ bin_py = os.path.join(sys.prefix, 'bin')
-+ default_storage_dir = #STORAGE_DIR#
-+ default_config_file = #CONFIG_FILE#
-+ default_log_file = #LOG_FILE#
-+ # Forcing to use /usr/local/bin for standard Mac OS X framework installs
-+ if sys.prefix[:16] == '/System/Library/':
-+ bin_py = '/usr/local/bin'
- else:
- bin_py = os.path.join(sys.prefix, 'bin')
- default_storage_dir = os.path.join(user_dir, '.pip')
- default_config_file = os.path.join(default_storage_dir, 'pip.conf')
- default_log_file = os.path.join(default_storage_dir, 'pip.log')
-- # Forcing to use /usr/local/bin for standard Mac OS X framework installs
-- if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
-- bin_py = '/usr/local/bin'
diff --git a/Library/Formula/python.rb b/Library/Formula/python.rb
index d7d22790c..d5c6264e9 100644
--- a/Library/Formula/python.rb
+++ b/Library/Formula/python.rb
@@ -1,43 +1,13 @@
require 'formula'
-<<-COMMENTS
-Versions
---------
-This formula is currently tracking version 2.7.x.
+# This formula for Python 2.7.1
+# Python 3.x is available as a separate formula:
+# $ brew install python3
-Python 3.x is available as a separate formula:
- brew install python3
-
-Options
--------
-There are a few options for customzing the build.
- --universal: Builds combined 32-/64-bit Intel binaries.
- --framework: Builds a "Framework" version of Python.
- --static: Builds static instead of shared libraries.
- --no-poll: Don't include Apple's broken poll implementation.
-
-site-packages
--------------
-The "site-packages" folder lives in the Cellar, under the "lib" folder
-for normal builds, and under the "Frameworks" folder for Framework builds.
-
-A .pth file is added to the Cellar site-packages that adds the corresponding
-HOMEBREW_PREFIX folder (/usr/local/lib/python2.7/site-packages by default)
-to sys.path. Note that this alternate folder doesn't itself support .pth files.
-
-pip / distribute
-----------------
-The pip (and distribute) formulae in Homebrew are designed only to work
-against a Homebrew-installed Python, though they provide links for
-manually installing against a custom Python.
-
-pip and distribute are installed directly into the Cellar site-packages,
-since they need to install to a place that supports .pth files.
-
-The pip & distribute formuale use the "site_packages" method defined here
-to get the appropriate site-packages path.
-
-COMMENTS
+class Distribute < Formula
+ url 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.15.tar.gz'
+ md5 'ea52e1412e7ff560c290266ed400e216'
+end
# Was a Framework build requested?
@@ -53,8 +23,8 @@ class Python < Formula
homepage 'http://www.python.org/'
md5 'aa27bc25725137ba155910bd8e5ddc4f'
- depends_on 'readline' => :optional # Prefer over OS X's libedit
- depends_on 'sqlite' => :optional # Prefer over OS X's older version
+ depends_on 'readline' => :optional # Prefer over OS X's libedit
+ depends_on 'sqlite' => :optional # Prefer over OS X's older version
depends_on 'gdbm' => :optional
def options
@@ -69,41 +39,11 @@ class Python < Formula
# Skip binaries so modules will load; skip lib because it is mostly Python files
skip_clean ['bin', 'lib']
- def site_packages
- # The Cellar location of site-packages
- if as_framework?
- # If we're installed or installing as a Framework, then use that location.
- return prefix+"Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages"
- else
- # Otherwise use just 'lib'
- return lib+"python2.7/site-packages"
- end
- end
-
- def exec_prefix
- if as_framework?
- # If we're installed or installing as a Framework, then use that location.
- return prefix+"Frameworks/Python.framework/Versions/2.7/bin"
- else
- # Otherwise just use 'bin'
- return bin
- end
- end
-
- def prefix_site_packages
- # The HOMEBREW_PREFIX location of site-packages
- HOMEBREW_PREFIX+"lib/python2.7/site-packages"
- end
-
- def validate_options
+ def install
if build_framework? and ARGV.include? "--static"
onoe "Cannot specify both framework and static."
exit 99
end
- end
-
- def install
- validate_options
args = ["--prefix=#{prefix}"]
@@ -119,8 +59,7 @@ class Python < Formula
# allow sqlite3 module to load extensions
inreplace "setup.py",
- 'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))',
- '#sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))'
+ 'sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))', ''
system "./configure", *args
@@ -132,13 +71,36 @@ class Python < Formula
ENV.j1 # Installs must be serialized
system "make install"
- # Add the Homebrew prefix path to site-packages via a .pth
+ # Post-install, fix up the site-packages and install-scripts folders
+ # so that user-installed Python software survives minor updates, such
+ # as going from 2.7.0 to 2.7.1.
+
+ # Remove the site-packages that Python created in its Cellar.
+ site_packages.rmtree
+
+ # Create a site-packages in the prefix.
prefix_site_packages.mkpath
- (site_packages+"homebrew.pth").write prefix_site_packages
+
+ # Symlink the prefix site-packages into the cellar.
+ ln_s prefix_site_packages, site_packages
+
+ # Tell distutils-based installers where to put scripts
+ scripts_folder.mkpath
+ (effective_lib+"python2.7/distutils/distutils.cfg").write <<-EOF.undent
+ [install]
+ install-scripts=#{scripts_folder}
+ EOF
+
+ # Install distribute. The user can then do:
+ # $ easy_install pip
+ # $ pip install --upgrade distribute
+ # to get newer versions of distribute outside of Homebrew.
+ Distribute.new.brew { system "#{bin}/python", "setup.py", "install" }
end
def caveats
framework_caveats = <<-EOS.undent
+
Framework Python was installed to:
#{prefix}/Frameworks/Python.framework
@@ -146,31 +108,52 @@ class Python < Formula
such as:
mkdir ~/Frameworks
ln -s "#{prefix}/Frameworks/Python.framework" ~/Frameworks
-
EOS
- site_caveats = <<-EOS.undent
- The site-packages folder for this Python is:
- #{site_packages}
+ general_caveats = <<-EOS.undent
+ A "distutils.cfg" has been written, specifing the install-scripts folder as:
+ #{scripts_folder}
- We've added a "homebrew.pth" file to also include:
- #{prefix_site_packages}
+ If you install Python packages via "python setup.py install", easy_install, pip,
+ any provided scripts will go into the install-scripts folder above, so you may
+ want to add it to your PATH.
- EOS
+ Distribute has been installed, so easy_install is available.
+ To update distribute itself outside of Homebrew:
+ $ easy_install pip
+ $ pip install --upgrade distribute
- general_caveats = <<-EOS.undent
- You may want to create a "virtual environment" using this Python as a base
- so you can manage multiple independent site-packages. See:
- http://pypi.python.org/pypi/virtualenv
-
- If you install Python packages via pip, binaries will be installed under
- Python's cellar but not automatically linked into the Homebrew prefix.
- You may want to add Python's bin folder to your PATH as well:
- #{exec_prefix}
+ See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
EOS
- s = site_caveats+general_caveats
- s = framework_caveats + s if as_framework?
+ s = general_caveats
+ s += framework_caveats if as_framework?
return s
end
+
+private
+
+ # Path helpers
+
+ def effective_lib
+ # If we're installed or installing as a Framework, then use that location.
+ return prefix+"Frameworks/Python.framework/Versions/2.7/lib" if as_framework?
+ # Otherwise use just 'lib'
+ return lib
+ end
+
+ # The Cellar location of site-packages
+ def site_packages
+ effective_lib + "python2.7/site-packages"
+ end
+
+ # The HOMEBREW_PREFIX location of site-packages
+ def prefix_site_packages
+ HOMEBREW_PREFIX+"lib/python2.7/site-packages"
+ end
+
+ def scripts_folder
+ HOMEBREW_PREFIX+"share/python"
+ end
+
end