Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
ansible: 1.2.2 some fixes
Browse files Browse the repository at this point in the history
-   Install the Python module `ansible` into the usual prefix, but use
    `python.private_site_packages` (in `libexec`) for the deps.
-   In oder for the `ansible` module to be useful, the deps are needed
    and we insert the `python.private_site_packages` in the
    `ansible/__init__.py` as a `sitedir`, to the `egg`s are working.
-   Rewrote the `bin_wrapper` to be ready to be moved into
    `python_helper` or something.
-   With the brand new changes in the PythonInstalled dependency,
    it is not necessary to set the `PYTHONPATH` if you want to use
    the `python.private_site_packages` inside of the `libexec`.
    However, you have to put the calls to `system python` inside of
    a `python do … end` block (technical limitation of supporting
    Python 2.x and 3.x in general).
  • Loading branch information
samueljohn committed Sep 3, 2013
1 parent 0c847bb commit 2058d5c
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions Library/Formula/ansible.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require 'formula'

class PyCrypto < Formula
url 'https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz'
sha1 'c17e41a80b3fbf2ee4e8f2d8bb9e28c5d08bbb84'
end

class PyYAML < Formula
url 'https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.10.tar.gz'
sha1 '476dcfbcc6f4ebf3c06186229e8e2bd7d7b20e73'
Expand All @@ -15,11 +10,21 @@ class Paramiko < Formula
sha1 'fd925569b9f0b1bd32ce6575235d152616e64e46'
end

class MarkupSafe < Formula
url 'https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.18.tar.gz'
sha1 '9fe11891773f922a8b92e83c8f48edeb2f68631e'
end

class Jinja2 < Formula
url 'https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz'
sha1 'a9b24d887f2be772921b3ee30a0b9d435cffadda'
end

class PyCrypto < Formula
url 'https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz'
sha1 'c17e41a80b3fbf2ee4e8f2d8bb9e28c5d08bbb84'
end

class Ansible < Formula
homepage 'http://ansible.github.com/'
url 'https://github.com/ansible/ansible/archive/v1.2.2.tar.gz'
Expand All @@ -30,37 +35,48 @@ class Ansible < Formula
depends_on :python
depends_on 'libyaml'

def bin_wrapper bin_file; <<-EOS.undent
#!/bin/sh
PYTHONPATH="#{libexec}/lib/#{python.xy}/site-packages:$PYTHONPATH" "#{libexec}/bin/#{bin_file}" "$@"
def wrap script, pythonpath, place_original="#{libexec}/bin"
script = Pathname.new(script)
place_original = Pathname.new(place_original)
place_original.mkpath
mv script, "#{place_original}/"
script.write <<-EOS.undent
#!/bin/sh
PYTHONPATH="#{pythonpath}:$PYTHONPATH" "#{place_original}/#{script.basename}" "$@"
EOS
end

def install
ENV['PYTHONPATH'] = "#{libexec}/lib/#{python.xy}/site-packages"
# installing into private sitepackages inside of the Cellar (in libexec)
install_args = [ "setup.py", "install", "--prefix=#{libexec}" ]

PyCrypto.new.brew { system python, *install_args }
PyYAML.new.brew { system python, *install_args }
Paramiko.new.brew { system python, *install_args }
Jinja2.new.brew { system python, *install_args }
python do
PyCrypto.new.brew { system python, *install_args }
PyYAML.new.brew { system python, *install_args }
Paramiko.new.brew { system python, *install_args }
MarkupSafe.new.brew { system python, *install_args }
Jinja2.new.brew { system python, *install_args }

inreplace 'lib/ansible/constants.py' do |s|
s.gsub! '/usr/share/ansible', share+'ansible'
s.gsub! '/etc/ansible', etc+'ansible'
end
inreplace 'lib/ansible/constants.py' do |s|
s.gsub! '/usr/share/ansible', share+'ansible'
s.gsub! '/etc/ansible', etc+'ansible'
end

system python, "setup.py", "install", "--prefix=#{prefix}"
# The "main" ansible module is installed in the default location and
# in order for it to be usable, we add the private_site_packages
# to the __init__.py of ansible so the deps (PyYAML etc) are found.
# Because of egg files,
inreplace 'lib/ansible/__init__.py',
"__author__ = 'Michael DeHaan'",
"__author__ = 'Michael DeHaan'; import site; site.addsitedir('#{python.private_site_packages}')"

man1.install Dir['docs/man/man1/*.1']
system python, "setup.py", "install", "--prefix=#{prefix}"
end

(libexec/'bin').mkpath
man1.install Dir['docs/man/man1/*.1']

Dir["#{bin}/*"].each do |bin_path|
bin_path = Pathname.new(bin_path)
bin_file = bin_path.basename
mv bin_path, libexec/"bin/#{bin_file}"
bin_path.write(bin_wrapper(bin_file))
Dir["#{bin}/*"].each do |script|
wrap script, pythonpath=python.private_site_packages
end
end
end

0 comments on commit 2058d5c

Please sign in to comment.