Sunday, 20 December 2009

MacPorts

Today I 'av mainly been wondering how I will remember the stuff I need to know in order to use MacPorts. This blog will be a memory jogger.

It is a prerequisite to install X11 (from your Snow Leopard disk) and download XCode from Apple (You will need to register).

$ port help
$ port search py26 # find all packages for python 2.6
$ sudo port install py26-django # install a package with all dependencies
$ port installed # list what you have installed
$ port deps openssl # show package dependencies
$ port outdated # show what needs updating

$ sudo port selfupdate # check for macports update
$ sudo port upgrade outdated # check for updated packaes

MacPorts are here.

For me (today) I think its easier to use than fink. The only thing I miss is a native aqua version of Tk.

Just in case I have to do this again:

$ history | grep 'sudo port'
  sudo port install python26
  sudo port install python_select
  sudo port install py26-pil
  sudo port install py26-django
  sudo port install py26-pyqt4
  sudo port install py26-docutils
  sudo port install qscintilla
  sudo port install py26-matplotlib
  sudo port install py26-matpltlib-basemap

$ history | grep select
  192  sudo python_select python26

Thursday, 17 December 2009

PIL on Snow Leopard

Today I 'ave mainly been thinking how to install Python Imaging Library on OS X 10.6.

It was all going so well...

But when I came to do some mods to some old python  stuff I found that Python Image Library was not installed with Apple Python 2.6. No problem just download and install PIL. Well no... It did not just work like it usually would, then I started reading various posts about the problems and possible solutions.

In the past I have used fink but have always felt was a bit awkward. My preferred solution would be to install PIL on top of Apple Python and carry on!

Today I am attempting to install python2.6.4 using MacPorts. Its a long process so no idea if it will finish before I fall asleep. However I will tell the story here if I find out how to do it.

Download mac ports from here.
Install in the usual way.

$ sudo port install python26 # this takes a long time
$ sudo port install python_select
$ sudo python_select python26
$ sudo port install py26-pil
$ sudo port install py26-django
$ sudo port install py26-pyqt4 # this takes a long time
$ suso port install py26-docutils

MacPorts .. seems simple enough to me.

Tkinter apps look a bit too much X11 like for me but Qt looks like it always does. Seems a bit of a shame because Apple python seems difficult to upgrade. I assume its a 32/64 bit compatibility problem that will go away in time.

Saturday, 12 December 2009

Google Chrome for Mac OS X

Today I 'ave mainly been trying the new Google browser on my MacBook.  First impressions are good.

You should try it. Look here for more information.

Sunday, 1 November 2009

OS X 10.6 Snow Leopard

Today I 'ave mainly been doing an upgrade to my trusty laptop from Leopard to Snow Leopard.

I checked out the advice on the net which varied between: do an upgrade and: do a complete re-install. In the end I did a clean install and then got back my old user files and most of my applications from a Time Machine backup. Nice one Apple!

The only things I have had to do anything with are...

emacs (was part of fink) is now available as native os x here.
mercurial for python2.6 here.

For the present I have no need for fink.

Snow Leopard  ... Grrr...

Monday, 28 September 2009

Carradale


Today I 'ave mainly been thinking about a recent trip to Scotland. The location was Carradale near Cambletown.



Here is my holiday snap....









Sunday, 6 September 2009

North East England .. Almost in Scotland















Today I 'ave mainly been thinking about the North East of England. My recent holiday snap was taken on the beach walk to Bambergh Castle.

Tuesday, 25 August 2009

Python indentation TABS and Spaces

Today I 'av mainly been thinking about how to clean up source files that contain a mixture of tabs and spaces. This is illegal in Python 3.x.


It has never been a problem for me as I learned that tabs are evil several years before I started programming with Python. However Pmw has several files that contain tabs. This led me to search for help... I was pleased to find that tools already exist in the Python directories.


The first: tabnanny.py checks files for mixtures of tabs and spaces.

The second reindent.py fixes problems.



$ python /sw/lib/python2.5/tabnanny.py -v .
# remove -v for less output

$ python /sw/lib/python2.5/Tools/scripts/reindent.py -d -r -v .
# remove -d to change files

Monday, 24 August 2009

Porting Python programs to 3.x

Today I 'av mainly been thinking about how to upgrade existing Python programs so that they can be easily ported to Python 3.x. The advice on the Python website is:

  1. Write tests (we all know that anyway).
  2. Run tests and make sure they pass. Lets hope that you are using the unit test package and perhaps even a coverage tool so that you know something about the quality of the tests.
  3. Run python2.6 with the -3 option to find out what changes you can make to your source to ease the transition. The idea is to stick with 2.6/7 until you are ready to jump to 3.x (assuming that all 3rd party packages are available).
  4. Make the recommended changes either manually or perhaps by using the 2to3 translation tool. (2to3 can be run with specific options e.g 2to3 -f has_key will just change has_key to in.)
  5. Re-run tests.
  6. Do a full conversion to 3.x and see if tests still work. (Again keeping main source configured for 2.6/7)
Well thats the theory. For my part I have taken this advice and am helping with the porting of the Pmw package here.

I have also been wondering why the same has not been done for the whole of the Python standard library. Tkinter in particular is full of has_key and callable. This is a pity as it obscures problems in local code.

I also realised that the output format of 2to3 is quite verbose. I have produced a summary tool here to get a shorter easier to read output as shown below:





$ python2.6 -3 All.py 2>&1 | python2.6 -m ppande.py3stats
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py
DeprecationWarning: callable() not supported in 3.x; use hasattr(o, '__call__')
[1050, 3237]
DeprecationWarning: dict.has_key() not supported in 3.x; use the in operator
[1903, 1914, 1939, 1967, 2438, 2441]
/Users/steve/pmw_fixes/Pmw/Pmw_0_0_0/lib/PmwEntryField.py
DeprecationWarning: builtin_function_or_method inequality comparisons not supported in 3.x
[114, 147]
Total errors: 10
Summary:
DeprecationWarning: builtin_function_or_method inequality comparisons not supported in 3.x
DeprecationWarning: callable() not supported in 3.x; use hasattr(o, '__call__')
DeprecationWarning: dict.has_key() not supported in 3.x; use the in operator



Thursday, 23 July 2009

The TED Conference

Today I 'ave mainly been thinking about another conference... Quite by accident I have stumbled upon an amazing gathering of interesting people at TED Global 2009. I believe all talks are to be posted on the internet over the coming weeks and most look like they would be worth seeing.

TED is a small nonprofit devoted to Ideas Worth Spreading. It started out (in 1984) as a conference bringing together people from three worlds: Technology, Entertainment, Design. Since then its scope has become ever broader. Along with the annual TED Conference in Long Beach, California, and the TEDGlobal conference in Oxford UK, TED includes the award-winning TEDTalks video site, the Open Translation Program, the new TEDx community program, this year's TEDIndia Conference and the annual TED Prize.


Saturday, 4 July 2009

Life after EuroPython 2009?

Today I 'ave mainly been thinking about the best bits from EuroPython. Well done to the organisers for a great conference. These were the best bits for me (sadly I missed some talks that may have been as good as several talks were at the same time.)
  • PyPy has gone from an experiment to reality in the last 3 years and is now on JIT v4 here.
  • The 4 main Python platforms are all going strong: CPython , Jython, PyPy and IronPython in discussion here. The guys at this talk really know their stuff!
  • Crowd sourcing at the Guardian here. Simon Willison one of the best presenters ever.
  • Bruce Eckel Keynote here (I was alerted to Python several years ago, while reading Thinking in C++ by Bruce Eckel, thanks Bruce).
  • Python is great but what is the best way to get this over to the folks who have not tried it. Harald has a good plan here.
  • Turbo Grears 2. In particular the glowing references to SQLAlchemy here.
  • Lightening Talks. There is a lot of stuff going on with Python. Also included a very entertaining Harald doing the fill in between talks.
  • After the talk on the PSF by Steve Holden there was a suggestion that we could all become associate members of the PSF for 10 quid a year. Sounds good to me.

Friday, 26 June 2009

EuroPython 2009



Today I 'ave mainly been thinking about my upcoming trip to Birmingham to attend EuroPython. click
here for more information.

Saturday, 13 June 2009

Google Picks Mercurial

Today I 'ave mainly been noticing that the Google folks have provided Mercurial as an alternative to Subversion. See here for more information.I may even update my online code.

Updating from subversion to mercurial turned out to be easy enough, just go to administer page select source and change repository to mercurial. Also follow the instructions here

On OS X with mercurial 1.2 it was as easy as hg convert, hg update, hg push for source and wiki.

Friday, 12 June 2009

Hide Tkinter Cursor on Linux

Today I 'av mainly been thinking how to enable or disable a cursor in a Tkinter application. I looked at several threads on the internet but none exactly answered my question. This is what I did...

Use gimp to create a 1x1 pixel image.

Save as 1x1.xbm. You will have to export the file. Make sure the X10 box in unchecked and the hot spot box is checked.

The xbm file is readable and looks like:


$ cat 1x1.xbm
#define 1x1_width 1
#define 1x1_height 1
#define 1x1_x_hot 0
#define 1x1_y_hot 0
static unsigned char 1x1_bits[] = {
0x00 };


The code looks like...


from Tkinter import *

root = Tk()
root.configure(cursor='@1x1.xbm white') # turn cursor off
....
root.configure(cursor='arrow_left') # turn it back on


More elaborate options are possible that include a cursor a mask and 2 colors.

Sadly I was unable to make this work on OS X although I am sure it is possible.

On windows the cursor 'no' does the same thing.

Monday, 4 May 2009

Scotland

For the last few days I 'ave mainly been thinking about a Scottish Island hopping holiday on Arran and Mull. This blog entry has been created to capture the experience.

This is my favorite holiday snap..




Sunday, 19 April 2009

How not to crash my phone

Today I 'ave mainly been thinking about how to develop an application for my phone without crashing it.  I have no idea what happens when I write an application that locks up. I assume that at the worst I will lose all my contacts :-(. 

My first idea was to use the emulator but sadly I cannot get the python runtime to load into the emulator. The emulator is 5th edition S60, I have looked on the wiki and the Nokia forums but no one else seems to have this problem. It complains about certificates?

I have no second idea.


Saturday, 18 April 2009

Python on my phone

Today I 'ave mainly been thinking how I can develop a Python application for my phone. The messages from the www are a bit confusing so I shall put my memory joggers here for anyone else who attempts this.

On a XP PC... not sure if it works from  a Mac.

here is my phone on the Nokia web site.

here is the SDK for my phone. I had to sign up to forum Nokia to get this.

Before install this needed Perl 5.9+  and Java JRE 1.5+.

I downloaded python 2.5.4 from here.

I downloaded the Python S60 addon for the SDK from here. This was the difficult bit as it does not come up in google searches. (It has moved from Nokia to SourceForge to Garage)

I used bluetooth to send the python runtime to my phone.

On receiving the .sis file as a message the phone asks if it is ok to install.

I then used bluetooth to install the sample scribble application on my phone.

Yippee it works. Now can I write something?

The S60 wiki looks like a good place to keep up to date.

Monday, 6 April 2009

Mercurial wins

Today I 'ave mainly been thinking that the folks here have come to the conclusion that Mercurial is the one.




Tuesday, 17 March 2009

Bazaar seems to do the job

Today I 'ave mainly been thinking about ... keeping my code under version control (again).

I have been using Bazaar for the last week or so and it just works. I started a new project and moved files around as I created and refactored. So for now its Bazaar for me. Its pity I would have to move away from google code (here) to here. But for now I will just continue to use it locally. These are my most used commands:




bzr whoami "Bob Smith bob@smith.com"
bzr whoami

bzr init # create a new repo in current folder
bzr add
bzr log
bzr status
bzr diff
bzr ignored
bzr rm file.py
bzr revert file.py
bzr rm -keep file.py
bzr commit -m 'story'
bzr mv folder newfolder
bzr mv file.py newfolder/


Monday, 16 March 2009

Spotify

Today I 'ave mainly been thinking about .. spotify. .... Following the advice of Mac User, I created an account, here, downloaded the spotify application and have been listening to all kinds of music.... Free.

To be honest the choice of music is immense and it is an odd experience being able to listen to almost any music you choose. The package is meant to include adverts but I did not notice any.

So my next plan is to make a few eclectic playlists and get my laptop hooked up to my Hi-Fi. The ultimate iPod collection.. Did I say it was Free?

Thursday, 12 March 2009

More ways to code in blogs

Today I 'ave mainly been tinking about different ways to publish code in blogs. This is an example produced using Pygments.



class Thingy(object):
pass



Now this is perhaps a better way to do it. I like this because it does not require me to edit my blog html. On the downside I have to have all my snippets on my laptop. Perhaps not a bad thing?

First get pygments:


easy_install Pygments


Then generate the html with all the style inline


pygmentize -f html -O noclasses=true code_example1.py


Then paste into the Edit Html view

Wednesday, 11 March 2009

Adding code to my blog


Today I 'ave mainly been thinking about... how I can include code in my blog. For example I would like to include some code here:




class Thing(object):
pass




And then add more words here...



To get this to work I edited my blogger site html to add 2 lines after head to include prettify.css and prettify.js from google code. I also had to call onload in the body tag. This is described here and I looked here at the source to see how it worked in practice. You can just look at the source of this page. I hope one day blogger will have a nice code button in the Compose window. 




def func(param):
pass




Looks like I will have to alter my colour scheme!

Tuesday, 10 March 2009

Now I am confused its Bazzar

Today I 'ave mainly been thinking about DVCS again. I was getting ready to continue the story of Bob and Alice with Mercurial when I found several articles claiming that Bazzar was the new svn. So instead of helping Bob and Alice get their work done... I read enough about Bazaar to get my subversion library into bazaar.

My main problem was finding the right bit of documentation. In the end it was very simple:

bzr branch http://mysite/svn/trunk

It only took a few seconds and I seem to have all my files and history. (Much faster than Mercurial)

So maybe Bob and Alice will try out bzr later.

Monday, 9 March 2009

Mercurial for a small project

Today I 'ave been mainly thinking about ... how to use Mercurial for a small team.

Start from repository main (created from existing svn).

Create 2 clones one for each person on the team.

 hg clone main bob
 hg clone main alice

(good old Bob and Alice)

Bob does a few changes 

 vi
 hg status
 hg diff
 hg commit

Alice does a few more changes including an odd one in a file changed by Bob
 
 emacs
 hg diff
 hg status
 hg commit

What will Bob do next? ...anyway I am off to the pub.



Sunday, 8 March 2009

Mercurial?

My first attempt at blogging... here goes.

In case anyone is interested, the title is a catch phrase from a character Jesse in the Fast Show (UK TV Comedy).

Today I 'ave mainly been thinking about ... the options available for sharing source files.

Over the years I have used DEC CMS, *nix RCS, CVS and most recently SVN.

I am aware that there are several alternatives available, and today I have invested some time looking at Mercurial as an alternative to svn

 On the whole I like svn but I have had problems when I have attempted to move files around (re-factoring often causes this), especially renaming folders seems to cause me a bit of trouble when I come to commit. 

I have also noticed that the Python community are considering the options to move away from subversion. See python PEP 374.

Here are my early thoughts.

Getting a svn repository and converting it to Mercurial went very smoothly. I had 2 attempts: First I let it get all revisions. Even for a smallish library it took quite a time to construct the new repository. On my second attempt I only asked for the last 3 revisions and this was much quicker.

Now I have just got to get into the Mercurial mindset and find an appropriate work flow.

One barrier to use may be finding a place to host my Mercurial repository.

More later.