Skip to main content

Posts about python (old posts, page 39)

The Future of PyQt by Example

Three years ago, I started a series of long posts called "PyQt by Example". It reached five posts before I abandoned for a series of reasons that don't matter anymore. That series is coming back starting next week, rewritten, improved and extended.

It will do so in a new site, and the "old" posts will be retired to an archive page. Why? Well, the technologies used in some of them are obsolete or don't quite work nowadays. So, the new versions will be the preferred ones.

And while I am not promising anything, I have enough written to make this something quite longer, more nicely layouted, more interesting and make it cover more ground. BUT, while doing some checks on the traffic statistics for the old posts, some things popped out.

This was very popular

About 60% of my site's traffic goes to those five posts. Out of about 1200 posts over 12 years, 60% of the viewers go to the 0.4% of the pages. That is a lot.

It's a long tail

The traffic has not decreased in three years. If anything, it has increased

A long and tall tail.

So, all this means there is a desire for PyQt documentation that is not satisfied. I am not surprised: PyQt is great, and the recommended book is not free, so there is bound to be a lot of demand.

And, here's the not-so-rosy bit: I had unobtrusive, relevant, out-of-the-way-but-visible ads in those pages for more than two years. Of the 70000 unique visitors, not even one clicked on an ad. Don't worry, I was not expecting to get money out of them (although I would love to some day collect a $100 check instead of having google hold my money for me ad eternum).

But really? Not even one ad click? In more than two years, thousands of people? I have to wonder if I just attract cheap people ;-)

PyCamp Starts This Week

This friday marks the beginning of the 2012 PyCamp. What's PyCamp? It's a lot of python programmers (this year, about 50) gathering in an isolated place for a long weekend, with nothing to do except code. We will have our meals catered, there are no TVs, there is hardly anything within walking distance, and it's going to be very cold.

So, it's going to be awesome. It's a rare chance for me to spend a few days hacking at my own personal projects, uninterrupted by more important things like family, work, cooking, or socializing except between nerds.

Sure, there is the occasional monocycle riding, or juggling lesson, or shooting practice, but really, three or four solid days of hacking.

I intend to work on projects related to Nikola my static site generator, so if you are interested in that and going to pycamp, I want to talk with you.

And if you are interested but not going to pycamp, there is no reason not to join in a virtual sprint. We'll have internet. There is IRC. I will have time. It's a weekend! Please share any interesting ideas you have about static site generators in the nikola-discuss group and we'll see how much can get implemented or at least started.

A Simple Nikola Link Checker

One of the most important things when you are building a static site generator like Nikola is that your site should not be broken. So, I really should have done this earlier ;-)

This is a very simple link checker that ensures the pages Nikola generates have no broken links. I will make it part of Nikola proper once it's more polished and doit supports getting a list of targets

To try it, get it and run it from the same place where you have your, right after you run doit.

import os
import urllib
from urlparse import urlparse

import lxml.html

def analyze(filename):
        # Use LXML to parse the HTML
        d = lxml.html.fromstring(open(filename).read())
        for l in d.iterlinks():
            # Get the target link
            target = l[0].attrib[l[1]]
            if target == "#":  # These are always valid
            parsed = urlparse(target)
            # We only handle relative links.
            # TODO: check if the URL points to inside the generated
            # site and check it anyway
            if parsed.scheme:
            # Ignore the fragment, since the link will still work
            # TODO: check that the fragment is valid
            if parsed.fragment:
                target = target.split('#')[0]
            # Calculate what file or folder this points to
            target_filename = os.path.abspath(
                os.path.join(os.path.dirname(filename), urllib.unquote(target)))
            # Check if it exists, or report it
            if not os.path.exists(target_filename):
                print "In %s broken link: " % filename, target
    except Exception as exc:
        # Something bad happened, report
        print "Error with:", filename, exc

# This is hackish: we use doit to get a list of all
# generated files. Minor modifications would let you check
# the non-generated files as well.

for task in os.popen('doit list --all', 'r').readlines():
    task = task.strip()
    if task.split(':')[0] in (
        'render_site') and '.html' in task:
            # It looks like a generated HTML file

On Politeness, Street Signs, and Codes of Conduct

When I grow up, I want a pink car. Girls like pink.

—Tato (my son, age 4 at the time)

There has been a lot of talk lately about codes of conduct in conferences. I don't have answers to much, but I do have a lot of questions in my head, and some things seem to come to my mind because of that, so I will do a little head dumping, and let's see if clarity appears.

So. The main thing seems to be that the proposed codes of conduct aim at making events inclusive, and more diverse, and welcoming to people who may have felt unwelcome in the past. That these groups involve women should be a call of attention. Women? Women are half the world, and apparently we have been excluding them, whether intentionally or not.

So, in principle, if adopting a code of conduct helps that, I am all for it. Same about gays, lesbians, transexuals, etc. They are not 50% of the world, but they are about 10% of it, so it's a very large amount of people, and adding them to our groups is another easy optimization.

However, it concerns me a bit that these codes of conduct contain language like this:

Harassment includes offensive verbal comments related to gender, sexual orientation, disability, physical appearance, body size, race, religion, sexual images in public spaces, deliberate intimidation, stalking, following, unauthorized or inappropriate photography or recording, sustained disruption of talks or other events, inappropriate physical contact, and unwelcome sexual attention.

Some are completely obvious, people who disrupt the speakers at conferences are to be thrown out, intimidation is abominable, stalking is creepy, etc. But "offensive verbal comments related to [everything]"?

And here, I have to make a small detour and talk about street signs. When I visited London, one thing that called my attention was the language in street signs. Here's an example:

In other countries it would say "No dogs", wouldn't it?

So, why do they have signs like this? It's probably because they are very polite people. Also, it may be because offensive signs are punishable by jail.

I have a completely unfounded suspicion that the politeness came first, and then came the right not to be offended, which ended encoded into law, and now you just have to be polite, or else.

I am quite loudly atheist, yet I only mention it outside this blog if someone mentions his religion. So, for example, if someone says "god asks less and yet he forgives", I may say "that's because he doesn't exist", as a joke. I am now assuming that saying that in a conference with that kind of code of conduct is going to be considered offensive behaviour. And let's say I am ok with that, I can still go for a few hours without offending people. Have not tried it lately, but I am sure I can do it.

And I know that at a private event, like a conference, there is no inherent freedom of speech, because there is the right of admission, and I can just be kicked out without any explanation, and I am also fine with that, because I reserve the right to kick people out of my own home, too.

So, sure, let's keep religion out of it. It has no place in a technical conference one way or another, and in any case, I will wear my invisible pink unicorn shirt as an outward sign of my atheism (it looks just like a gray v-neck t-shirt).

And I am totally fine about not mocking or harassing people because of their gender or sexual preferences. I am old and provincial enough that when two men start kissing next to me, I feel awkward. Luckily, I am enough of an adult that I just think to myself, "dude, you are a provincial prude" and look the other way. After all, I have seen people take exception to me kissing my wife in public, so, live and let live, whatever. I like women, my wife likes men, so I can understand you liking either.

On the other hand, I understand that the mere existence and presence of some people can be offensive to others. I know people who would rather stand for 2 hours than sit next to a transexual. Or would rather get off the bus instead of being there. And I am enough of an old, provincial prude that I understand them. So, offending is not the thing here, because if offending is the thing, then the mere presence of someone can offend others, and that's the exact opposite of what we want. We want them to either not be offended, or be offended and get over it, or be offended and not care.

So, handing out invitations to threesomes to people in hallways is a bit too much (I never invite people to threesomes before the fourth date, it is gauche). Hitting on people in bars at night is probably not too bad, unless it's a constant thing that ruins the night for someone (what do I know, I have never hit on someone or been hit on in a bar. Except by other men. Just my luck!) in which case I expect a group of nice people to form a protective ring around the poor person who is just too attractive? (again, what do I know, I have never been atractive).

The thing we want is politeness. We want to be nice to each other. We want everyone to be as nice as they possibly can to as many people as they can. Specially, we want everyone to be extremely nice to the people they like the least. Because with people you get along with, you can do crazy stuff you can't do with others.

On the other hand, I suspect there is something else here I am missing. Because tolerance and respect is just not my thing. I am all for proselitizing and disrespect, for creative annoyance and pushing people outside their comfort zones. But I try not to do it personally, I try to throw things to the crowd and see what they do with them.

I mean, I have been photographed without my consent. I have even had my shirt scanned without asking permission (ok, I admit having a QR code in a shirt is sort of an implicit agreement), I have been called names, but I know that, in the words of a scifi writer, I live life in the low difficulty setting, because I am a rather healthy white heterosexual male born in middle class with a job, so again, I don't quite know what it's like to be insanely attractive, or gay, or insanely attractive to gays, or anything. I am not harassable. My face protects me. I know others don't have such powerful defenses.

So, while that kind of language does fill me with trepidation, and makes me wonder what kind of community I have been living in, oblivious to all these things I read about lately, I will accept those codes and try to follow them. I have never intentionally broken them, even before they existed (I did once take an inappropriate picture, it was a joke, I only showed it to one person, and I deleted it, and I really am sorry and would not do it again, ok?)

So, I hope to see a lot of people I don't know in the next free software events I attend. Hopefully I will not offend any of them in a bad way. I will not be too brash. I will try to be inclusive. I will try to be nice. But remember. If I am very, very nice to you, it may be because I can't stand you. You're welcome.

Nikola 3.0.1 Available for Testing

Version 3.0.1 of Nikola my static site generator is ready for initial user testing.

I have merged a bunch of patches from Kay Hayen and Kadefor:

  • disqus_developer is gone

  • addthis buttons are optional (controlled by a new option)

  • You can have more than one static files folder to be merged into output.

  • Image galleries support uppercase extensions.

  • Templates can not link to CSS that is empty/missing

  • Better Google Sitemaps

  • Preserve (some) metadata when copying files, like timestamps

  • Don't overwrite existing posts with doit new_post

  • Generate valid URLs from unicode titles

So, if you want to try it out:

I will make it a real release if nothing bad shows up before sunday or monday.

Now that's a nice theme.

I have been flooded by awesome patches for Nikola by different contributors, so there will be a new release very soon. In the meantime, see what happens if someone with design skills does a theme for it:


The author says he's polishing it and will be done in a few days.

Nikola is FAST.

A fast-loading site is a good thing. Your site's speed matters. Which is why creating fast sites is one of Nikola's design goals.

Sure, it's not meant to create e-commerce sites, but if you are doing just a simple corporate site, or a personal blog, why would you not make it as fast as possible anyway?

So, here's one data point, from Kay Hayen

Guess when Kay switched to Nikola.

But you don't have to just believe that graph. Here's Yahoo's YSlow report on this blog, which is hosted in a $5 VPS (as are other sites, BTW. The same VPS. As is a bunch of services. And my Quassel core)

It scores 94 on that test. That's 94 out of 100 possible points in the "Small Site or Blog" ruleset.

How much server tuning was needed? I added one line to the Apache config:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

That makes it compress those files before sending it to the user and improved the third item from F to A.

So, when I say Nikola makes your site fast, don't take my word for it, just check it out.

Nikola 3 is out and it is good.

I just released version 3 of my static site generator, Nikola

It's a major release, there is hardly any code from the previous version that was not moved, prodded, broken or fixed!

The main features of Nikola:

  • Blogs, with tags, feeds, archives, comments, etc.

  • Themable

  • Fast builds, thanks to doit

  • Flexible

  • Small codebase (programmers can understand all of Nikola in a few hours)

  • reStructuredText and Markdown as input languages

  • Easy image galleries (just drop files in a folder!)

  • Syntax highlighting for almost any programming language or markup

  • Multilingual sites

  • Doesn't reinvent wheels, leverages existing tools.

Changes for this release (not exhaustive!):

  • New optional template argument for "nikola init"

  • New "install_theme" task

  • Optional address option for the "serve" task

  • Better looking codeblocks

  • Russian translation

  • Use markdown/reSt compiler based on post extension

  • Don't fail when there are no posts/stories/galleries/tags

  • Use configuration options as dependencies

  • Use more relative links for easier site rellocation

  • Syntax highlight for markdown

  • Better multicore builds (make the -n 2 or -n 4 options work)

  • Configurable output folder

  • Don't fail on posts with periods in the name

  • Different page names for different languages

  • Recognize (some) Mako template dependencies

  • Is now a more "normal" python package.

Rst2pdf 0.92 released, now has a website.

Just released rst2pdf version 0.92. Rst2pdf is a tool to convert restructured text to PDF without requiring multi-hundred-megabytes of software. It supports styling, multiple page layouts, font embedding, vector images, and much more.

Also, now it has a real website:

Try it out and let me know of the obvious, horrible bug I forgot to fix (happens in most rst2pdf releases ;-)