Tuesday, October 23, 2012

Adding to the XCode "Open Developer Tool" Menu

UPDATE: This tweak actually disappears (along with the apps you copy inside XCode) whenever XCode is updated!

In spite of the agony that comes every time Apple changes where XCode and its friends live, I like the direction they're going. Now everything's bundled neatly inside the XCode app itself... almost.

Today I wanted to use the handy OpenGL Shader Builder app that I remembered from a long time ago, but to my dismay I realized it wasn't installed. As of this writing, XCode had cleverly bundled its extra apps inside the XCode app as well - you can access them by going to XCode -> Open Developer Tool. As the Shader Builder wasn't there, the "More Developer Tools..." option took me to the somewhat sluggish developer download site, where I was able to log in and download the tools I wanted.

Now the tricky part, and where my OCD kicks in. I like the direction Apple took in bundling these inside XCode, so I'd like these new ones in the same place. After a wee bit of hacking, I figured out how to do this and add them to XCode's menu. As no one after a quick google search seems to document this, I thought I should:
  • Quit XCode
  • In the Finder, navigate to the XCode app and "Show Package Contents"
  • Copy aliases of the new apps into Contents/Applications/ (you'll be prompted for your password)
  • Add lines to Contents/Resources/IDEHelperApps.plist for each new app you add
    • This can be a little tricky with permissions - an easy way to do it is copy the file to the desktop, and copy back, overwriting the original
  • Open XCode again, and presto! Your new apps are in the menu:

Tuesday, May 15, 2012

PySide in Eclipse

Here's a quick note about getting rid of PySide errors in Eclipse if you're getting them - I installed PySide and all the examples work just fine, but Eclipse is flagging everything PySide-related as an error. You have to do a couple things:
  • PySide might have been installed in a non-standard location:
    • In Spotlight, search for "PySide", probably limiting to the /Library directory
    • If you find the PySide folder, click it to see where it got installed - in my case, it was installed at /Library/Python/2.7/site-packages/PySide, even though the /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 could import PySide without any trouble
    • If this is the case with you, go to Eclipse -> Preferences -> PyDev -> Interpreter - Python -> Libraries
    •  Click "New Folder"
    • Navigate to the site-packages directory that contains PySide (not the PySide directory itself!)
  • Like PyQt4, PySide wraps .so ("shared object") files, not actual python, so you'll also need to:
    • In the same screen (Eclipse -> Preferences -> PyDev -> Interpreter - Python), click the "Forced Builtins" tab, click "New...", type "PySide", and click "OK"

Thursday, May 10, 2012

Installing pycairo or py2cairo on OS X Lion

This is for folks that don't like using macports, fink, or homebrew, but want to install cairo and possibly use it with Python.

First of all, if you're comfortable with the version of python that ships with OS X, I'd recommend these binaries - they're much more mac-user friendly. You have to install a couple of them in the right order, though, but the page explains it pretty well.
(disclaimer: I didn't actually go all the way of getting py2cairo installed with these frameworks, but py2cairo's install scripts should just work with these binaries... feel free to comment if you try it and it doesn't!)

For those of us that are using a "real" version of python from python.org, things aren't as pretty... there are some guides for building on Leopard (note, not Snow Leopard, just Leopard!), but a lot has changed since then, especially if you're talking about 64-bit architectures. In case it's helpful to anyone, here's a script I hacked together over a couple of days (with help from this stackoverflow thread) to get py2cairo up and running on OS X Lion with a 64-bit python.org installation:

Download

#!/bin/bash

rm -rf ~/Downloads/temp
mkdir ~/Downloads/temp
cd ~/Downloads/temp

curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.26.tar.gz -o pkgconfig.tar.gz
curl ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.10.tar.gz -o libpng.tar.gz
curl http://www.cairographics.org/releases/pixman-0.24.4.tar.gz -o pixman.tar.gz
curl http://www.cairographics.org/releases/cairo-1.12.0.tar.gz -o cairo.tar.gz
curl http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2 -o py2cairo.tar.bz2

tar -xzvf pkgconfig.tar.gz
tar -xzvf libpng.tar.gz
tar -xzvf pixman.tar.gz
tar -xzvf cairo.tar.gz
tar -xzvf py2cairo.tar.bz2

mv pkg-config-* pkgconfig
mv libpng-* libpng
mv pixman-* pixman
mv cairo-* cairo
mv py2cairo-* py2cairo

cd pkgconfig
./configure
make
sudo make install

export PKG_CONFIG=/usr/local/bin/pkg-config
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/lib:$LD_LIBRARY_PATH
export LINKFLAGS='-search_dylibs_first -L /Library/Frameworks/Python.framework/Versions/2.7/lib/'
export ARCHFLAGS='-arch x86_64'

export MACOSX_DEPLOYMENT_TARGET=10.7
export CC="gcc"
export LDFLAGS="-arch x86_64"
export CFLAGS="-arch x86_64"

cd ../libpng
./configure
make
sudo make install

cd ../pixman
./configure
make
sudo make install

cd ../cairo
./configure
make
sudo make install

cd ../py2cairo
python waf clean

python waf configure --prefix=$PYTHONPATH
python waf build
python waf install

cd ../..
rm -rf ~/Downloads/temp



Make sure to try "import cairo" in the interpreter to test if everything worked.

Monday, March 26, 2012

web.py and Sessions

I have fallen in love with web.py over the last few weeks - if you want a site up and running using Python as a backend just as fast (or faster) than you could with PHP, check it out.

But I did have a devil of a time with sessions, so in case you're using web.py and having problems, here's what I discovered:

Syntax:
You'd expect a normal, pythonic dictionary, but, alas, we don't have this in web.py. To set a value (assuming my session object is named boringly "session," and I want to set "myvalue" to 1):
session.myvalue = 1
However, to access data, you have to use .get():
print session.get("myvalue")
will give you that same value back.

Debug Mode:
I spent a good three-ish hours trying to figure out why my session data kept getting nuked. There is actually a bug in web.py (feel free to comment if/when this gets fixed) that reloads your module twice if you're in debug mode. To fix it, add this after the imports in your code:
web.config.debug = False

Of course, you end up with a tradeoff while you're working on your site (do I care to see the sometimes-helpful error messages enough to have session stuff broken?), but at least it should work fine when you're ready for the world to use it.

Thursday, January 19, 2012

Macfusion, MacFUSE and OS X Lion

UPDATE (4 Nov 2013): I found the problem with Mavericks - the latest workaround is here.
UPDATE (29 Oct 2013): I just upgraded to Mavericks, and Macfusion is now broken. I've tried every combination of installations, command-line sshfs programs, etc. that I can find and nothing is working yet.  I'll post again if I figure it out, but for now, I guess I'm stuck with Cyberduck. Macfusion should still work if you're running Lion (and maybe Mountain Lion), though.

And another by-product of the Lion upgrade... and a lesson in hasty installations.

Back in Snow Leopard, I had used Macfusion to mount many of the systems that I have ssh access to as devices on my mac - life is so much handier when you can edit and copy files directly without remembering all the proper terminal stuff. You set up the ssh connection once, and forever after you can access your servers with a pull-down menu in the Finder.

After my fresh installation of Lion (see last post), I decided I still wanted this tool, so I downloaded and installed Macfusion, forgetting that back in the day I had to install MacFUSE first. I went to connect to my favorite server, and, what do you know? I get an error:

Mount process has terminated unexpectedly

It took me a few minutes for the "aha! I forgot to install MacFUSE!" So, in my rushed habit, I downloaded the original MacFUSE installer I had used in Snow Leopard, installed, and in its preference pane...

Macfuse does not appear to be installed

Crap. Maybe I need to restart.

Nope.

Okay, maybe Macfusion messed with something by being installed first... After much googling, I figured out how to remove both MacFUSE and Macfusion via a bunch of sudo rm -rf statements (yikes!), and installed in the proper order.

Still the same error.

Okay, maybe this is a Lion issue. Googling that... and yes, it turns out MacFUSE doesn't like the uber-64-bit-ness of Lion. Someone suggested a patched version of MacFUSE that should work, no guarantees...

And, of course, it doesn't fly on my machine.

NOW what? In the same forum, someone whispered something about a proper solution that was in the works: OSXFUSE. A quick peek at the post date, and, yup, that was six months ago. I wonder if it's farther along now...

Yup. And the installer has a nice backward compatibility mode to MacFUSE - and for OCD freaks like me, it also will do the uninstallation of MacFUSE for you as it installs itself so you don't have to do all the unix deleting.

Kudos to Benjamin Fleischer and Erik Larsson. You know software is great when it fixes your problem so fast you hardly remember using it.

Wednesday, January 18, 2012

Getting PHP to run in OS X Lion

So I upgraded to OS X Lion over the weekend. Because I'm OCD, I burned it to a DVD, and did a fresh install on a hard drive I swapped in from a neighbor's dead laptop. Luckily I have a USB - PATA adapter, and just plugged in my old hard drive to copy my files straight over after the installation (check out thinkgeek.com if this sounds like it might help you; they're really handy. You can also probably find a cheaper one than thinkgeek's on ebay if you want to do the leg work).

Anyway, I had a lame little php website in my sites folder - nothing serious for public consumption, but as I work on lots of computers at once, it's handy to just throw a file into my Sites folder so I can access it on another computer without breaking out a flash drive. With the upgrade to OS X Lion, I went through my System Preferences, and turned on Web Sharing, hoping things would work like they did before. Back in Snow Leopard, I had edited /Library/WebServer/Documents/index.html to redirect to /~home/index.php ("home" is my username - yet another OCD quirk), but when I added this tweak in OS X Lion, I just got the php code itself dumped to the browser.

Obviously, this won't do.

Per much advice on the internets, I tried un-commenting this line in /etc/apache2/httpd.conf:

LoadModule php5_module libexec/apache2/libphp5.so
(Note: you'll need to change permissions of the file in order to do this... if you don't like the hassle of doing this on the command line, TextWrangler streamlines this a bit if you try to edit the file directly).

Still just gettting php code. Again, this won't do.

After much playing around with options, I tried dropping the "index.php" from my redirect in /Library/WebServer/Documents/index.html

... and suddenly we're in business.

I'm still a little vague on why - if I find the time to investigate, I'll update.