Recently, I’ve had to deal with some Python packaging issues, pushing me to familiarize myself with the (PyPA) tools and ecosystem.
There is one thing that still confuses me. Suppose I have a pure-Python project. No C, no build complexity, no compilation, plain and simple Python code. When I run python -m build
, I get
- a
.tar.gz
sdist, - a
-py3-none-any.whl
wheel.
My question is: why do I need both? Since the wheel is universal (not platform-specific), wouldn’t the wheel suffice? Is it only to include tests/docs in the sdist but not in the wheel? But then, who will consume my sdist and might need those tests, given that I very likely host my source code on GitLab/GitHub/whatever?
On An Overview of Packaging for Python — Python Packaging User Guide, I read (emphasis mine)
“In fact, Python’s package installer, pip
, always prefers wheels because installation is always faster, so even pure-Python packages work better with wheels.
Binary distributions are best when they come with source distributions to match. Even if you don’t upload wheels of your code for every operating system, by uploading the sdist, you’re enabling users of other platforms to still build it for themselves. Default to publishing both sdist and wheel archives together, unless you’re creating artifacts for a very specific use case where you know the recipient only needs one or the other.”
Which makes me think that the sdist is only needed if my package contains C/C++/Rust/<insert compiled language> code.
Consider this both as a question and feedback about how the UX could be improved, whether through changes in the tools or in the packaging documentation