Skip to content

Commit

Permalink
Merge pull request #3 from gregglind/robust
Browse files Browse the repository at this point in the history
More detailed docs, e.g. using brew; make both python and pythonw point to generated stub.
  • Loading branch information
matthewryanscott committed Feb 15, 2012
2 parents 170938b + 6221a8e commit 372b82c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 10 deletions.
27 changes: 27 additions & 0 deletions README.rst
@@ -0,0 +1,27 @@
virtualenv-pythonw-osx
===========================

Some GUIs Pythona apps don't work right, unless ``pythonw`` is in an app bundle.

This script only fixes virtualenvs based on Framework style installs (bundles)

Framework Installs:
---------------------

* the default OSX install
* ``brew install python --framework``

But **not**:

* ``brew install python``, which we can't fix using this method



CF:

https://github.com/pypa/virtualenv/issues/54
http://stackoverflow.com/questions/3692928/why-doesnt-the-save-button-work-on-a-matplotlib-plot
http://code.google.com/p/iterm2/issues/detail?id=1680

This code attempts to fix this issue, by making sure both ``python`` and ``pythonw`` get
compiled like app bundles.
64 changes: 54 additions & 10 deletions install_pythonw.py
@@ -1,5 +1,22 @@
#!/usr/bin/env python

"""
Some GUIs don't work right, unless the python is in an app bundle.
This script only fixes virtualenvs based on Framework style installs (bundles)
CF:
https://github.com/pypa/virtualenv/issues/54
http://stackoverflow.com/questions/3692928/why-doesnt-the-save-button-work-on-a-matplotlib-plot
http://code.google.com/p/iterm2/issues/detail?id=1680
This code attempts to fix this issue, by making sure both ``python`` and ``pythonw`` get
compiled like app bundles.
"""


import os
from os import path
import shutil
Expand All @@ -8,9 +25,32 @@


USAGE = """
Usage: install_pythonw.py ENVPATH
Usage: install_pythonw.py ROOT_OF_PARTICULAR_VIRTUALENV
(if you are in the virtualenv right now, try:
$ which python
for me: /Users/me/venvs/py27/bin/python
$ python install_pythonw.py /Users/me/venvs/py27/
or
$ python install_pythonw.py `which python`/../..
"""

BREW_NOTE = """
if this virtualenv is based on the Python installation from Homebrew,
you might want to install "Framework style". This script only fixes
virtualenvs based on OSX Framework-style installs.
$ brew install python --framework
"""

def main(env_path, script_path):
# If Python.app already exists, exit.
Expand All @@ -32,6 +72,7 @@ def main(env_path, script_path):
dot_python_src = os.readlink(dot_python)
if not path.exists(dot_python_src):
print dot_python_src, 'does not exist; exiting.'
print BREW_NOTE
return 1
# Find Python.app in PARDIR/Resources/
python_app_src = path.join(
Expand All @@ -52,15 +93,18 @@ def main(env_path, script_path):
pythonw_executable,
])
# Compile pythonw to bin directory.
pythonw_dest = path.join(env_path, 'bin', 'pythonw')
call([
'cc',
'-arch', 'i386', '-arch', 'x86_64',
'-DPYTHONWEXECUTABLE="' + pythonw_executable + '"',
'-o',
pythonw_dest,
pythonw_c,
])
for name in ['python','pythonw']:
pythonw_dest = path.join(env_path, 'bin', name)
call([
'cc',
'-arch', 'i386', '-arch', 'x86_64',
'-DPYTHONWEXECUTABLE="' + pythonw_executable + '"',
'-o',
pythonw_dest,
pythonw_c,
])

print "finished! App bundle created at: " + python_app_dest


if __name__ == '__main__':
Expand Down

0 comments on commit 372b82c

Please sign in to comment.