home > developer

Tuesday, May 11th, 2010

Installing PyQt 4.7.3

Abbreviated notes for installing PyQt 4.7.3 on Mac OS 10.6 (Snow Leopard). This assumes you have already downloaded and installed the Qt SDK.

cd tmp

wget http://www.riverbankcomputing.co.uk/static/Downloads/sip4/sip-4.10.2.tar.gz
untar sip-4.10.2.tar.gz 
open doc/html/index.html 
cd sip-4.10.2
python configure.py --arch i386 --sdk MacOSX10.4u.sdk
make
sudo make install
cd ..
rm -rf sip-4.10.2/

wget http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-mac-gpl-4.7.3.tar.gz
untar PyQt-mac-gpl-4.7.3.tar.gz 
cd PyQt-mac-gpl-4.7.3
python configure.py --use-arch i386
make
sudo make install
cd ..
rm -rf PyQt-mac-gpl-4.7.3/

Then, do a quick test.

python
>>> from PyQt4 import QtGui
>>> a = QtGui.QApplication([])
>>> w = QtGui.QWidget()
>>> w.show()    
>>> w.hide()

Smile.

/developer   〆   permalink

Wednesday, February 24th, 2010

Hg Init

Hg Init: a Mercurial tutorial by Joel Spolsky is awesome. Consise, funny, clear, and true. Plus the domain name is perfect.

/developer   〆   permalink

Tuesday, February 23rd, 2010

Software Carpentry

Software Carpentry’s tag line is “Basic software development practices for scientists and engineers.” Definitely worthwhile — although I’d recommend hg or git over subversion.

/developer   〆   permalink

Tuesday, February 23rd, 2010

Best Explanation of Git and Mercurial’s Similarities

Mercurial for Git users answered many of my questions on the nuances of Mercurial. The branch model, bare repositories, and command equivalence table were especially helpful for someone like myself who has used both systems but never fully understood the distinctions.

/developer   〆   permalink

Saturday, January 23rd, 2010

Link Roundup

Trying to clear out my inbox today … so here’s a variety of interesting links I’ve seen in the last few months.

Top 10 User Interaction Myths

Python Debugging Techniques (code.interact(), logging, pdb)

Logging Module

Guide to Branching in Mercurial

Python Bytecode Disassembler

Python Module of the Week

Windows Sysinternals

UI Complexity

Arduino Small Prototyping Board

fabricate Build Tool

mlabwrap Python to Matlab Bridge

eCircuit Center (former Varian guy’s EE circuit learning site)

/developer   〆   permalink

Saturday, January 23rd, 2010

A Style Guide and pychecker

I came across Google’s Python Style Guide and enjoyed it. It mentioned pychecker which is a nice static analysis tool for helping to find bugs in Python code.

/developer   〆   permalink

Saturday, January 23rd, 2010

grin: Easy Search of Directorys Full of Source Code

I am loving the grin tool. It’s like a find/grep mashup with good defaults. In human-speak, that means you can easily search source code on the command line with a short command.

Just go pip install grin it already (or easy_install grin if you’re old school).

/developer   〆   permalink

Saturday, January 23rd, 2010

View Python Profiles

Profiling tools are essential to understanding where to focus your attention when improving software performance. RunSnakeRun is a nice way to visualize, sort, and better understand Python profiling data.

/developer   〆   permalink

Saturday, January 23rd, 2010

Instant Ubuntu GUIs with Quickly

I like the idea of Quickly: make easy one-line commands for creating, editing, designing, running, packaging, and releasing Ubuntu GUI projects. Ars’s overview captures the gist of it well.

/developer   〆   permalink

Saturday, January 9th, 2010

Why I Like Mercurial

Mercurial is a great version control tool. I like it for the following reasons:

  • distributed (you can checkin changes with no network connection)
  • free, open-source
  • written in Python (easy to customize with workflows)
  • works well on Mac, Linux, and Windows
  • TortoiseHG on Windows means non-developers at work can use it
  • simple to get started with, but powerful features available
  • hg is the shortest and easiest name to type on the command line compared to the only credible competitors: git, svn, bzr … it doesn’t get any better than 2 adjacent letters on the home row!

/developer   〆   permalink

Saturday, January 9th, 2010

TortoiseHg Usage Introduction (Mercurial on Windows)

I wanted to share a quick introduction to using a Mercurial repository on Windows with TortoiseHg. This assumes someone has already setup the repository on a shared network drive (we’ll call \\Shared\Repo\Project44) and you want to keep up do date with the changes directly in Windows Explorer.

Initial Checkout

  1. Download and install the latest TortoiseHg at http://bitbucket.org/tortoisehg/stable/downloads/.
  2. After rebooting, Right-click -> TortoiseHG -> Settings -> Global -> Commit, and set your Username to something. I’m using “Alan Brooks”.
  3. Right-click -> TortoiseHG -> Clone a Repository.
  4. Put your \\Shared\Repo\Project44 in “Source Path”.
  5. Click “clone” in the upper left.
  6. The folder “Project44” on your hard drive is a working copy of all the latest files and also a complete copy of the entire history of the project (a.k.a. the repository in the “.hg” folder). I’ll call this folder your “local repo” for short.

Example Workflow

  1. Edit some code or files until you get to a point where you’d like to record a small incremental change in your local repo.
  2. Notice that the files/folders you’ve changed all have little red marks in Windows Explorer.
  3. Commit to your local repo. Right-click -> HG Commit …, select files to commit, write a checkin comment, then click Commit. This commit will be an atomic action for all the files as a group.
  4. Sync with the remote repo. Right-click -> TortoiseHG -> Synchronize…, click Pull to get anyone else’s changes. If there are changes, they may need merged before you push. If no changes, click Push to publish your changes to the repo.
  5. Look at the history. Right-click -> TortoiseHG -> View Changelog.

References

A couple of good things to read to get started with Mercurial are:

/developer   〆   permalink

Saturday, January 9th, 2010

Mercurial Command Line Quick Reference

There are two main ways I’ve been using Mercurial over the last couple years: on the command line and via tortoisehg (right-click) on Windows. This is a quick reference to the command-line interface. Mercurial on the command line is called “hg” (a reference to the element Mercury).

Help

>> hg            % lists basic commands
>> hg help       % lists all commands
>> hg help pull  % gives detailed help on command "hg pull"

Where am I?

>> hg status    % tell which files have been modified
>> hg st        % same as hg status (you can abbrevitate
                %    non-ambiguous commands)
>> hg log -l 5  % log of last 5 commits
>> hg diff      % current changes to your working directory
>> hg diff -c 9 % changes made by revision 9

Committing as you work

>> hg commit -m "change 1"  % regular commit
>> hg add new.c             % tell hg to start tracking a file
>> hg ci -m "change 2"      % "ci" is short for commit (legacy)
>> hg rename new.c blue.c   % rename a file (like copy + remove)
>> hg revert ---all          % oops, I didn't want to rename
>> !del blue.c              % del manually (stop tracking blue.c)
>> hg mv new.c red.c        % "mv" is short for rename
>> hg ci -A -m "change 3"   % "-A" adds/del's files, avoids 
                            %    the "hg add, hg remove" dance

Syncing with another repository

>> hg pull      % grab any new changes from default repo
>> hg update    % update your working directory with the changes
>> hg merge     % merge new code with your code
>> hg ci -m "merge" % commit merge result
>> hg fetch     % short for "hg pull, hg update, hg merge, hg ci"
>> hg push      % send your changes to the default repo

Merging

>> hg heads     % list the potential heads that could be merged
>> hg merge     % auto-merge (specify rev with -r if >2 heads)
>> hg resolve   % if auto-merge failed, retry after manual edits

Repository management

>> hg init          % make a new repo in the current dir
>> hg clone C:\Repo % clone the repo to work on a branch/idea

Advanced, but nice (many require enabling extentions)

>> hg view      % launches a graphical history viewer
>> hg paths     % where this repo pushes and pulls from
>> hg rollback  % undo the last commit (only OK if not pushed)
>> hg shelve    % stash work-in-progress to fix something else
>> hg unshelve  % resume your work-in-progress
>> hg rebase    % move a set of commits to a new baseline
>> hg tip -p    % show latest committed changes

Hope this helps. Please send me ideas for other commands that you like to use often.

/developer   〆   permalink

Saturday, January 9th, 2010

lxml.objectify == Best Python XML API

I’ve used a couple different XML parsing libraries in the past, but have always had a desire for XML to behave just like an object where accessing attributes maps directly to accessing XML children. Who would have known it — the lxml library, one of the fastest XML processors offers exactly this API, calling it lxml.objectify. I can’t wait to try it …

/developer   〆   permalink

Saturday, January 9th, 2010

Generate Microsoft Word 2007/2008 docx Files from Python Code

In some situations, it would be nice to be able to spit out an automated report as a Word document. Mike Maccana has come up with a new tool for doing just that and shared the code on github as project python-docx. I like it.

/developer   〆   permalink

Sunday, September 27th, 2009

Updating NumPy, SciPy, and Matplotlib

I recently upgraded to NumPy to 1.4.0.dev7419, SciPy to 0.8.0.dev5953, and matplotlib version 0.99.1.1.

svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
python setup.py build
python setup.py install
cd ..

svn co http://svn.scipy.org/svn/scipy/trunk scipy
cd scipy
python setup.py build
python setup.py install
cd ..

python
>>> import numpy
>>> numpy.__version__    # '1.4.0.dev7419'
>>> numpy.test('1','10') # 26 errors in 2231 tests, but usable
>>> import scipy
>>> scipy.__version__    # '0.8.0.dev5953'
>>> scipy.test('1','10') # 165 errors in 4515 tests, but usable

rm -rf /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib*
wget http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99.1/matplotlib-0.99.1.1.tar.gz/download
open matplotlib-0.99.1.1.tar.gz
cd matplotlib-0.99.1.1
python setup.py build
python setup.py install
cd ..

ipython -pylab
>>> plot([1,2,3])

/developer   〆   permalink

Monday, July 13th, 2009

Python Link Roundup

Intra-package References

I just found out that Python 2.5 or newer allows relative imports, something I had been writing custom code to work around. Python documentation gives examples in 3 forms:

from . import echo
from .. import formats
from ..filters import equalizer

Packaging Tools

Alex Clemesha explains modern python hacker tools virtualenv, Fabric, and pip. I find all three of them intersting.

pip is an alternative to easy_install where you can install and upgrade python packages easily with commands like:

pip install -U ipython

Fabric facilitates deploying code to a remote location.

virtualenv lets you setup and manage working environments that aren’t littered with everything you ever installed into your global site-packages directory.

I also recommend virtualenvwrapper, which puts a nice interface on top of virtualenv.

/developer   〆   permalink

Saturday, January 31st, 2009

Agreed. Git is Awesome.

I agree with every word in Fine. Git is Awesome.

/developer   〆   permalink

Saturday, January 17th, 2009

Mercurial and Git Links

Useful Mercurial Setup suggestions from Ted Naleid.

Daily Git tips at git ready.

/developer   〆   permalink

Saturday, January 3rd, 2009

Introducing numpyIO.py

I implemented numpyIO.py because I often use scipy.io.numpyio.fread() and scipy.io.numpyio.fwrite(), but I don’t want to depend on scipy. It uses numpy’s tofile/fromfile functions instead.

Why might you want this instead of SciPy’s numpyio? Well, I can think of a few reasons:

  • it imports faster because it only depends on numpy, not scipy
  • easier to package with py2exe or py2app
  • it is slightly faster
  • it lets you avoid rewriting legacy code that makes extensive use of scipy’s deprecated fread/fwrite

Grab the numpyIO project from bitbucket or clone the repo with:

hg clone http://bitbucket.org/lannybroo/numpyio

/developer   〆   permalink

Monday, December 29th, 2008

Updating to Python 2.6 on Mac OS X Leopard 10.5.6

Install Python from source.

cd ~/tmp
wget http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz
untar Python-2.6.1.tgz
cd Python-2.6.1
mate Mac/README
./configure --enable-framework
make
make install
cd ..

Update setuptools so that easy_install works.

wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg
sh setuptools-0.6c9-py2.6.egg

Add the following to my .profile so that the binaries installed by easy_install take precedence over my old Python 2.5 stuff.

export PATH=/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH

Easy install various packages I use frequently.

easy_install IPython
easy_install nose
easy_install pexpect
easy_install cheetah
easy_install clonedigger
easy_install pyserial
easy_install markdown2
easy_install euclid
easy_install psyco

Do the slightly tougher installs: NumPy (svn rev 6271), SciPy (svn rev 5300), matplotlib, and euclid. See http://www.scipy.org/Installing_SciPy/Mac_OS_X for details. Before starting, I also updated to the latest apple developer tools, although this isn’t strictly necessary.

wget http://r.research.att.com/gfortran-4.2.3.dmg
open gfortran-4.2.3.dmg # install using GUI

wget http://www.fftw.org/fftw-3.2.tar.gz
untar fftw-3.2.tar.gz
cd fftw-3.2
./configure
make
sudo make install
cd ..

svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
python setup.py build
python setup.py install
cd ..

svn co http://svn.scipy.org/svn/scipy/trunk scipy
cd scipy
python setup.py build
python setup.py install
cd ..

python
>>> import numpy
>>> numpy.test('1','10') # 6 problems in 1897 tests, but usable
>>> import scipy
>>> scipy.test('1','10') # 168 errors of 3990 tests, but usable

sudo port install libpng
sudo port install freetype
easy_install matplotlib

ipython -pylab
>>> plot([1,2,3])

svn checkout http://pyeuclid.googlecode.com/svn/trunk/ pyeuclid
cd pyeuclid
python setup.py install
cd ..

Install wxPython and PythonCard for GUI development.

wget http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-unicode-2.8.9.1-universal-py2.6.dmg
wget http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-docs-demos-2.8.9.1-universal-py2.6.dmg
open wxPython2.8-osx-unicode-2.8.9.1-universal-py2.6.dmg
open wxPython2.8-osx-docs-demos-2.8.9.1-universal-py2.6.dmg

wget http://prdownloads.sourceforge.net/pythoncard/PythonCard-0.8.2.tar.gz
untar PythonCard-0.8.2.tar.gz
cd PythonCard-0.8.2
python setup.py install
open /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PythonCard/samples/minimal/

Then, Ctrl-click and open minimal.py with Python Launcher to test.

/developer   〆   permalink

Sunday, November 30th, 2008

Speedy Python

A great reference: Tools for Accelerating Python. I learned about quite a few new ways of getting Python code to run faster …

/developer   〆   permalink