Tag Archive for 'OS X'

Winning at the shell game: iPython on Google App Engine

iPython is an awesome extended Python shell that gives you goodies like tab completion for instances, history tracing (so you can easily copy interactive sessions as doctests), etc. And, if you install it, your Django project on Google App Engine will automatically start using it instead of the regular python shell when you use ./manage.py shell.

To install iPython on OS X Tiger (yes, my Leopard discs are still safely in their box since I downgraded and I don't see any reason to bring them back out yet), I followed the following steps:

  1. Download the latest iPython from the iPython distributions page (ipython-0.8.4.tar.gz)
  2. Untar it, cd into the folder
  3. As per the instructions on the iPython download page:
    python setup.py build
    sudo python setup.py install
  4. To test it out on my Google App Engine/Django project, from my project folder: ./manage.py shell

(Note: The docs mention that you need to have readline installed on Mac OS X in order to use some of the features like tab completion and syntax highlighting. It just worked out of the box for me on OS X Tiger 10.4.11 -- I'm not sure if I had installed readline at some point or whether it was just there. Check out these instructions if you're having trouble.)

Once you have it installed, try out the cool code completion:

from my_app import models
models.

Press ⇥, and you'll see a list of all your models. models.my_model. ⇥ will show you the properties for that model and so on.

To create doctests, simply enter your test instructions in the shell and then type hist -n to get a dump of your history without line numbers that you can copy and paste into your doctest.

You can press ⌃ P and ⌃ ⇧ P to interactively bring up the previous and next commands in the history. If you've typed a bit of the command before doing this, it will filter to show you only those commands from your history that match the text you've entered.

You can also access the system shell without leaving iPython by preceding system calls with an exclamation mark. !ls, for example, will show you a listing of the current working directory.

And there's much more you can do that you can read about on the iPython documentation (or just type ? in the iPython shell itself and browse the docs interactively).

Check out iPython, it's yummy!

I found out about iPython from an excellent blog post by AkH on useful tips and good practices for Django projects. Thanks, dude!

Testing Google App Engine apps in Internet Explorer on Windows with Parallels on OS X

I've had a hard time trying to get Internet Explorer on Windows (under Parallels) to connect to the Google App Engine local development server running on OS X.

The interesting thing was that IE would connect to the built-in web server on the Mac without problem (using the Shared Network setting, I could also connect to any other web site.) But I couldn't connect to the development server either via IP or via the computer name using Bonjour for Windows.

I was puzzled until I looked at the options for dev_appserver.py and saw that it binds to a specific address (by default to localhost). Ah, eureka!

I got it working by starting the development server and binding it to the local IP address of my Mac (which you can find at the bottom of the System Preferences panel once you have Personal File Sharing enabled).

cd myapp
dev_appserver.py -a 10.113.127.29 .

I wasn't able to get it to work with the computer name from Windows by binding the server to it although it worked on the Mac and Bonjour for Windows was enabled in Internet Explorer -- it just did not see the server.

I hope this helps someone else save a little hair.

Now if only there was a quick fix for things looking crappy on Internet Explorer 6 :)

Getting started with Django on OS X

I've started setting aside a few hours every night to try new things. Two nights ago, I felted. Last night, I played with my Arduino board and light sensors. Tonight, I wanted to play with Django.

I use the term "play" loosely.

The problem is that there's no easy way to get started with Django. You have to jump through a few hoops to prove that you're truly worthy. I can't help but compare that to how easy it is to play with PHP (install MAMP, WAMP, or XAMMP and Bob's your uncle; you're up and running with Apache, PHP and MySQL in a single-click.) Similarly, Rails had Locomotive in Tiger and apparently comes pre-installed in Leopard (that's not enough to make me go back to Tiger after downgrading.)

Django looks lovely, but for it to really go mainstream it has to be easy for developers to set it up and play with it. To kick the tires, as it were, without jumping through too many hoops. Django needs its Locomotive.

All that said, I was resolved to play with it so I decided to try and find the simplest way to get a Django development environment running under OS X. During my rants on Twitter last night, Gareth Rushgrove had kindly suggested XCode + Macports but I didn't want to go through the hassle of installing the monolithic XCode.

Here's what I did do to get Django running on my OS X box running Tiger:

  1. Simon Willison had mentioned on Twitter that SQLite is a good development database (and MySQL is notoriously difficult to set up with Python). Seeing that Python 2.5 came with everything you need to work with SQLite3, I started by installing the Python 2.5.2 Universal Binary. (Using Django's Object-Relational Mapping engine, you can apparently just switch it out for MySQL, etc., on deployment.)
  2. Next, I checked out the Django trunk from SVN using Terminal: svn co http://code.djangoproject.com/svn/django/trunk/ and followed the official installation instructions.

If you've been following along, at this point, you should actually have a working Django install that you can develop on using SQLite3. (That wasn't too difficult at all actually; but neither have I seen it spelled out like this anywhere else.)

To test your installation, bring up Terminal and type:

django-admin.py startproject mysite

You should see Django create the mysite folder for you.

Navigate to that folder (cd mysite) and look at the files that Django created for you (ls). You'll be using these to build your Django application.

singularity:~/django/myfirst/mysite aral$ ls
__init__.py     manage.py       settings.pyc    urls.pyc
__init__.pyc    settings.py     urls.py

Next, run the development server:

python manage.py runserver

You should see something along the lines of:

Django version 0.97-pre-SVN-7254, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Finally, to make sure that SQLite is working, edit the settings.py file in your mysite folder to populate the following two lines

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/Users/aral/projects/mysite/mydb'

Replace the path with the path to your project folder. The mydb file doesn't exist yet. Create it by bringing up Terminal and entering:

python manage.py syncdb

You should see a stream of output starting with:

Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site

Create a superuser account when prompted.

Finally, to see the schema of the database that Django has created for you, fire up sqlite3:

singularity:~/django/mysite aral$ sqlite3 mydb
SQLite version 3.1.3
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE "auth_group" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(80) NOT NULL UNIQUE
);
// etc.

I hope this helps you get started with Django on OS X. I'm looking forward to playing with it in the coming days.

Resources:

Apple releases a fix for Leopard keyboard freezes

John Grden just forwarded me an email form John Olsen (thanks guys) alerting me that Apple has reportedly released a fix for the keyboard freezing issue in Leopard.

That's good news but, to tell you the truth, I'm going to wait a couple of months at least before even considering giving Leopard another shot. See, the thing is, I'm really happy on Tiger and downgrading to it made me realize just how many little issues I had with Leopard (responsiveness, general quirkiness, etc.) I absolutely love how stable Tiger is. I love how Tiger looks (yes, I love my non-transparent menu bar, rounded corners and blue apple logo) and I love how everything (all applications, etc.) work. I love the level of polish Tiger has.

Tiger doesn't remind me of Windows at all and Leopard did.

Part of Apple's corporate culture is its arrogance. The problem with arrogance is that, combined with incompetence it makes you appear a fool. Apple can be as arrogant as they want with Tiger. It's a shining beacon of stability and aesthetics, a perfect marriage of form and function. It just works. Not so with Leopard, at least not yet.

In Leopard, form trumps function and eye-candy exists for its own sake while fundamental characteristics of the operating system like stability are compromised.

I'm personally going to wait until Apple or third parties at least give me the option to make Leopard more like Tiger before I upgrade again. I'm guessing this will be in the 10.5.2 - 10.5.4 timeframe.

And really, I don't miss anything that Leopard had. I definitely do not miss the IMHO butt ugly interface. The Finder enhancements were really nice (I loved the breadcrumbs, for one), spotlight was far more useful and I did enjoy the integration between Mail and iCal but I value a stable system far more than any of these. And I didn't really get to use Time Machine as I'm on a laptop and don't have a USB drive plugged in all the time (here's hoping for that dual hard-drive laptop in '08, Apple... and I'll have that second one removable/hot swappable if you don't mind!) :)

I know that Leopard is working well for some of you and that some of you are very happy with it and that's great! But I see Leopard as more of an alternative to Tiger than an upgrade.

At the end of the day, the kitty that still has this early adopter's heart is Tiger.

Leopard: Great eye candy, pity the keyboard doesn’t always work.

<rant>

Dear Apple,

I have a Macbook Pro. It's your hardware. Unmodified. As shipped from your factory. I also recently bought your operating system upgrade for OS X Leopard. The only problem is that since I upgraded to Leopard, I can't use my keyboard without it freezing every few minutes.

Yeah, that does suck. In fact, it sucks huge hairy elephant balls.

See, this other company, Microsoft, they got the whole keyboard thing working without a hitch in, oh, what was it? Version 1?

You see, Apple, keyboards are important things. They're usually the primary means by which we provide input to our computers. In fact, I'm trying to use one right now -- quite unsuccessfully, I might add -- to write this blog post.

You remember those arrogant "I'm a Mac" ads that tout how reliable Macs are when compared to PCs? (And they truly were with Tiger.) I used to chuckle at them as I remembered what hell my life was under Windows before I switched last year. The only problem is that since I upgraded to Leopard, the ads seem further and further removed from reality. I kind of miss how I never had to worry about my keyboard freezing up in the 23 years that I used Windows. I'm beginning to eye those shiny new Vaios with envy again.

What the fuck is wrong with you Apple? You haven't even publicly acknowledged this issue and it has been reported to you over a hundred times on your own support forums for the past month.

Here's the Apple ad that Microsoft should make ASAP:

Mac: Hi, I'm a ................
PC (grinning): Mac?.. Mac?.. I think his keyboard's frozen again. But have you seen his shiny new 3D dock? Ooh-la-la!

Apple, do you have any idea how incompetent this makes you look?

Most importantly, the first thing you need to do is to officially acknowledge that the problem exists.

Yes, bugs are a fact of life in our industry but it is also common practice to _acknowledge and fix them_.

Next, state that you are working 24/7 on isolating it and finding a fix for it. Tell us you're aware of the problem and working on it. Heck, say you understand. While you're at it, you might even apologize to the hundreds (thousands?) of people who are losing their productivity due to this unbelievable bug.

And scrap your arrogant ads, you don't deserve them anymore. Maybe snack on humble pie for the next year or so until you get Leopard as stable as Tiger was.

Leopard just works? My ass! Tiger just worked. Not Leopard.

(Do I seem _really_ annoyed? Maybe it's because my keyboard has frozen about a dozen times so far in writing this blog post.)

I'm just one previously enthusiastic Apple user who is getting ever more annoyed and disenchanted with Apple. Something tells me that I'm not the only one. Here's a quote from one of the frustrated MacBook Pro owners on Apple's support forums:

Sadly, I am writing this from my Dell. I can't stand using the MBP at this point. How could they let a bug like this get out? At my company, a team would be working 24/7 to fix a problem like this. Do you want to begin to quantify how much this could cost Apple in the long run? Every day without a fix is another level reached in my anger and I assume there are thousands of others like me. I have two friends who are also having the problem now. One MPB from Fall '06 and one MPB from last week! Mine is from early October. I will not be buying Leopard for my fiancee's (fall 06) MacBook Pro this Christmas!

Oh and if any you should come by the cafe I'm in the next few minutes, I'll be the one with the shiny Macbook Pro frantically tapping his Num Lock key to see if his keyboard is back so he can continue working.

Un-fuckin'-believable.

Thanks a whole bunch, Apple! I'm off to restart my computer and (hopefully) get my keyboard back so I can do some work instead of bitching about my computer not working.

</rant off>

Links:






Bad Behavior has blocked 0 access attempts in the last 7 days.