Premailer is probably my most successful open source project in recent years. I base that on the fact that 25 different people have committed to it.

Today I merged a monster PR by Michael Jason Smith of OnlineGroups.net.

What it does is basically that it makes premailer work in Python 3, PyPy and Python 2.6. Check out the tox.ini file. Test coverage is still 100%.

If you look at the patch the core of the change is actually surprisingly little. The majority of the "secret sauce" is basically a bunch of import statements which are split by if sys.version_info >= (3, ): and some various minor changes around encoding UTF-8. The rest of the changes are basically test sit-ups.

A really interesting thing that hit us was that the code had assumptions about the order of things. Basically the tests assumed the the order of certain things in the resulting output was predictable even though it was done using a dict. dicts are famously unreliable in terms of the order you get things out and it's meant to be like that and it's a design choice. The reason it worked till now is not only luck but quite amazing.

Anyway, check it out. Now that we have a tox.ini file it should become much easier to run tests which I hope means patches will be better checked as they come in.

Comments

Dan Stromberg

First, congratulations on premailer working on 3.x.

Second, if you decide you want a dictionary with an order guarantee, you could try the standard library's OrderedDict or one of these:
http://stromberg.dnsalias.org/~strombrg/datastructures/
http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/

HTH

Your email will never ever be published.

Previous:
Do you curl a lot to check headers? September 5, 2014 Linux
Next:
django-html-validator October 20, 2014 Python, Web development, Django
Related by category:
How I run standalone Python in 2025 January 14, 2025 Python
get in JavaScript is the same as property in Python February 13, 2025 Python
How to resolve a git conflict in poetry.lock February 7, 2020 Python
Best practice with retries with requests April 19, 2017 Python
Related by keyword:
Cope with JSONDecodeError in requests.get().json() in Python 2 and 3 November 16, 2016 Python
Premailer.io July 8, 2015 Python, Web development, AngularJS, JavaScript
Sorting mixed type lists in Python 3 January 18, 2014 Python
premailer.py - Transform CSS into line style attributes with lxml.html July 11, 2009 Python