PEP 441 resulted in the creation of the zipapp module. The PEP says "Python has had the ability to execute directories or ZIP-format archives as scripts since version 2.6 [...] This feature is not as popular as it should be mainly because it was not promoted as part of Python 2.6." So far, so true -- the first time I saw the feature used in production, in Facebook, I was so shocked I had to take a Sweet Stop break.
However, more than a year before the PEP was created, and even longer than the PEP was implemented, the PEX format was contributed to the Python community by Twitter. It was, indeed, not well promoted. Indeed the lightning talk by Brian Wickman (creator of PEX) wouldn't be given for two more years.
However, at this point in time, PEX is a superior solution to zipapp in every single way:
- It supports both Python 2 and Python 3.
- It supports C extensions and non-zip-safe archives.
- It has been used in production, by many people.
The only advantage zipapp has? It is in the standard library. This used to be a big advantage. However, Python packaging is good now and the biggest difference is that a module in the standard library can change in backwards-compatible ways extremely slowly, and in ways that evolve bad interfaces even slower. A module on PyPI can get regular updates, regular releases and, most importantly, if it is bad -- it can be supplanted by a new module, and see users naturally move to the new solution.
ZipApp is a non-solution for a non-problem. The solution for the problem of this feature not being well known is to talk about it more. I, and other people, have given multiple talks that involved the awesomeness of PEX (in SF Python, SF SRE, PyBay) and have written multiple posts and proofs of concept on my GitHub.
I have used PEX in production in three different companies, teaching my colleagues about it as a side-effect.
I wish more people would be giving talks, and writing posts. Using the standard library to reimplement a popular tool, that can iterate faster, not being bound to the Python release cycle, does not help anyone.
Nitpicks are for Robots
My Little Subclass: Inheritance is Magic
Learning about Python Method Resolution Order with Twilight Sparkle and her friends.
(Thanks to Ashwini Oruganti for her helpful suggestions.)
The show "My Little Pony: Friendship is Magic" is the latest reimagination of the "My Little Pony" brand as a TV show. The show takes place, mostly, in Ponyville and …read more
PYTHONPATH Considered Harmful
(Thanks to Tim D. Smith and Augie Fackler for reviewing a draft. Any mistakes that remain are mine.)
The environment variable
PYTHONPATH seems harmless enough.
The official documentation refers to its function as
"Augment the default search path for module files."
However, in practice, setting this variable in a shell …
Shipping Python Applications in Docker
When looking in open source examples, or tutorials, one will often see Dockerfiles that look like this:
FROM python:3.6 COPY setup.py /mypackage COPY src /mypackage/src COPY requirements.txt / RUN pip install -r /requirements.txt RUN pip install /mypackage ENTRYPOINT ["/usr/bin/mypackage-console-script", "some", "arguments"]