venthur,
@venthur@mastodon.social avatar

Inspired by @fcodvpt post about current popularity of build backends, I investigated how the popularity of build backends used in pyproject.toml evolved over time since PEP-0517 introduced them in 2015:

https://venthur.de/2024-01-26-build-backends.html

#python, #pypi

image/png

fohrloop,
@fohrloop@fosstodon.org avatar

@venthur @fcodvpt nice stats! I would have expected flit to have higher percentage. The python packaging is still in the middle of changes and it's interesting to see where this is going and what kind of tools we will be using in five years from now.

#python #pythonpackaging #flit

brettcannon,
@brettcannon@fosstodon.org avatar

@fohrloop @venthur @fcodvpt Flit is a bit of a special build back-end as it has no dependencies and very simple, so it's typically used to help bootstrap packaging projects themselves. Compare that to Hatchling and pdm-backend which has some nice-to-haves.

fohrloop,
@fohrloop@fosstodon.org avatar

@brettcannon @venthur @fcodvpt

well that's interesting. I've been a happy flit user without realizing it :D To be honest, I've just used

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

in my pyproject.toml and that's it. I wonder what is the first sign I will have to migrate from flit if I write pure python code (No cython / C). 🤔

brettcannon,
@brettcannon@fosstodon.org avatar

@fohrloop @venthur @fcodvpt How do you generate your sdists? And then after that is when folks want something slightly fancier like dynamic version numbers that require a plug-in.

fohrloop,
@fohrloop@fosstodon.org avatar

@brettcannon @venthur @fcodvpt

So far I've been only creating wheels with

python -m pip wheel --no-deps .

Are there some benefits with the sdist format?

The dynamic versioning thing seems pretty fancy!

#python #pythonpackaging

diazona,
@diazona@techhub.social avatar

@fohrloop @brettcannon @venthur @fcodvpt One thing I've heard is that packagers for downstream repositories (e.g. Linux distribution package managers) prefer or even insist on sdists because they need the test code and/or documentation. There can be other tools that are trying to do things other than installing your package that can't work with a wheel, they need an sdist.

BTW you can use python -m build to build a project and get both the sdist and wheel "for free".

And yeah, dynamic versioning is great. I've had so many problems with hard-coding the version number in a file; IMO it's so much easier to just determine it from the tag. So this is the "killer feature" that makes me choose hatch (or setuptools back in the day before hatch supported it) over other backends.

#Python #PythonPackaging

fohrloop,
@fohrloop@fosstodon.org avatar

@diazona @brettcannon @venthur @fcodvpt

Thank you for the insight! I didn't know sdists have such use case, and it didn't come to my mind that the sdist has also the tests+docs included. Perhaps something that could be added to https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist

Thanks for the build module tip! Haven't stumbled onto that before.

diazona,
@diazona@techhub.social avatar

@fohrloop @brettcannon @venthur @fcodvpt FWIW it's not actually guaranteed that sdists have tests and docs included. I mean, ultimately an sdist is just a .tar.gz archive that follows a few standards, but I don't think those standards govern what goes in the repo, except for the PKG-INFO file which needs to contain some metadata. (Technically I don't think an sdist even needs to contain the package's own source code! You could make a valid sdist with almost nothing in it - useless, but valid.)

However, the way most build tools are configured, they'll put everything in the sdist by default, so it's common to have tests+docs in there, and a certain subset of consumers have come to rely on that.

#Python #PythonPackaging

fohrloop,
@fohrloop@fosstodon.org avatar

@diazona @brettcannon @venthur @fcodvpt

Just tested the "python -m build" on a project, and the difference of wheel and sdist was

  1. wheel has .dist-info folder with entry_points.txt, LICENSE.txt, METADATA, RECORD and WHEEL files.

  2. sdist had LICENSE.txt, PKG_INFO, pyproject.toml and README.md files at the root level

In other words, the tests (or docs other than README) were not included. I'm using flit. Maybe it's something about my configuration.

diazona,
@diazona@techhub.social avatar

@fohrloop @brettcannon @venthur @fcodvpt Oh interesting. That could be, but I do seem to remember that flit will omit any Python files other than a single top-level directory or Python file whose name matches the package name. Or something like that. Maybe that causes it to exclude tests and docs.

Every build backend has its own rules about what files it includes in an sdist, and it wouldn't surprise me if flit is one of the most conservative in that sense. Of course, that probably does mean that if you ever want to get your package included in a Linux distro or some other context where tests and/or documentation are important, you need to use something other than flit.

#Python #PythonPackaging

brettcannon,
@brettcannon@fosstodon.org avatar

@diazona @fohrloop @venthur @fcodvpt It's flit and why I said sdist support is a differentiation between the tools. Flit doesn't include much, Hatch is everything included by your git repo, and PDM tried to be smart about it

kushal,
@kushal@toots.dgplug.org avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • ngwrru68w68
  • tester
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • cubers
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • Leos
  • provamag3
  • anitta
  • modclub
  • megavids
  • lostlight
  • All magazines