George V. Reilly

Python Egg Cache

Every so often, one of our Bamboo builds would break thus:

pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 17] File exists: '/home/bamboo/.python-eggs'

The Python egg cache directory is currently set to:

  /home/bamboo/.python-eggs

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

This occurred while trying to make use of PyCrypto.

After a little research, I decided that instead of installing PyCrypto as a zipped egg (as it does by default) into the continue.

Running PyCharm on Yosemite

I did a clean install of OS X 10.10 on my home laptop a week ago. I tried to launch PyCharm 4.0.4 on it today. It im­me­di­ate­ly failed. Every time.

When I looked in the System Console, I saw:

1/25/15 7:46:00.557 PM pycharm[1160]: No matching VM found.
1/25/15 7:46:00.711 PM com.apple.xpc.launchd[1]: (com.jetbrains.pycharm.58252[1160]) Service exited with abnormal code: 1

The JetBrains website wasn't very helpful when I looked there. In time, I found a Stack­Over­flow answer that put me on the right track (and reminded me that I had previously solved this problem about a year ago, at work). PyCharm and some of the other JetBrains IDEs require JDK 1.6, as continue.

Blog 2014

My DasBlog-based blog at http://www.georgevreil­ly.com/blog/ has been out of commission for months. I've been meaning to replace it for a long time, but I only just got around to making a serious effort, as I realized that otherwise I would have no posts at all for 2014. I received only a handful of complaints about its absence; if there had been more, I would have fixed it sooner.

DasBlog is a fairly light­weight blogging engine that runs on ASP.NET. It doesn't require a database, but it does require the ability to write XML blogpost entries to the local filesystem. That's a non-standard con­fig­u­ra­tion for ASP.NET and IIS websites, which inevitably causes continue.

Turn off Windows Defender on your builds

I've spent some time this evening profiling a Python ap­pli­ca­tion on Windows, trying to find out why it was so much slower than on Mac or Linux. The ap­pli­ca­tion is an in-house build tool which reads a number of config files, then writes some output files.

Using the Run­SnakeRun Python profile viewer on Windows, two things im­me­di­ate­ly leapt out at me: we were running os.stat a lot and file.close was really expensive.

A quick test convinced me that we were stat-ing the same files over and over. It was a com­bi­na­tion of explicit checks and implicit code, like os.walk calling os.path.isdir. I wrote a little cache that memoizes the results, which brought continue.

SQLAlchemy Sharding

I wrote up some lessons that I learned about SQLAlchemy Sharding at the Cozi Tech Blog.

Python String Formatting

Python has long had a string in­ter­po­la­tion operator, %.

Python 2.6 and 3.0 introduced a new, richer set of string formatting operations. See PEP 3101 for the rationale.

One trick that I liked with the old way of formatting was to put the locals() dictionary or self.__dict__ on the right-hand side

>>> def stuff(a, b):
...  c = a+b; d = a-b
...  return "%(a)s, %(b)s, %(c)s, %(d)s" % locals()
...
>>> stuff(3, 17)
'3, 17, 20, -14'

It took me a few minutes to figure out how to do the equivalent with string.format: use the ** syntax to unpack the dict into kwargs.

>>> class Person(object):
...  def __init__(self, name, age):
... 
continue.

Augmenting Python's strftime

The Cozi Tech Blog needed some love, so I wrote a post on augmenting Python's strftime.

Flattening List Comprehensions in Python

Python has list com­pre­hen­sions, syntactic sugar for building lists from an expression.

>>> [2 * i for i in (2, 3, 5, 7, 11)]
[4, 6, 10, 14, 22]

This doesn't work so well when the com­pre­hen­sion expression is itself a list: you end up with a list of lists.

>>> def gen():
...     for l in [['a', 'b'], ['c'], ['d', 'e', 'f']]:
...         yield l
...
>>> [l for l in gen()]
[['a', 'b'], ['c'], ['d', 'e', 'f']]

This is ugly. Here's one way to build a flattened list, but it's less elegant than the com­pre­hen­sion.

>>> x = []
>>> for 
continue.

Northwest Python Day 2009

[Eric holding forth on BuildBot]

Eric and I attended Northwest Python Day 2009 today at the University of Washington. There were about 50 people present, with a few out-of-town visitors from Portland and Vancouver BC.

It was a mixed bag. I found the afternoon sessions more in­ter­est­ing than the morning ones.

The morning talks started with a set of five-minute lightning talks, including:

Browser Interface, Local continue.

Cheetah Tips

At Cozi, we're writing our new web services in Python (a story for another day). I wrote up a few hard-won tips on using the Cheetah Template library at the Cozi Tech Blog.

Previous » « Next