Skip to main content


TIL: importlib.metadata.version #

Apparently __version__ can be dynamic now.

While I was updating my standard pyproject.toml to use dependency groups, I switched to using uv as my build backend (from setuptools). Like all the other design choices, it has very sensible defaults with good overrides when you need them.

One thing that it doesn't support is dynamic versions (i.e. reading __version__ from __init__.py). Charlie Marsh explains:

Using dynamic metadata for things that are actually just static lookups feels like the wrong tradeoff.

Like version = ["dynamic"] to read the version from __init__.py.

As soon as you have dynamic metadata, you need to install dependencies and run Python just to get that info.


Static metadata rules. Just write the version out twice!

This makes sense, but I really didn't want to write out the version twice. Luckily, uv has a nice uv version command to change/bump the version number in the pyproject.toml, so I started thinking about how I'd also change the version in the __init__.py at the same time.

I asked ChatGPT what the best approach was and it suggested something quite different: don't write the value in __init__.py at all.

from importlib.metadata import version, PackageNotFoundError
try:
    __version__ = version("package-name") # from pyproject.toml: project.name
except PackageNotFoundError:
    __version__ = "0.0.0" # aka unknown version

I have since noticed that this was also the suggestion Adam Johnson had in the same thread.

One minor concern I have is whether this works in a cosmofy build, but that will be a separate exploration.


Dependency Groups to the Rescue #

Finally a standard place to put dev dependencies.

Previously: Stop Hiding Python Dev Dependencies

I'm a bit late to the party, but even when I saw that PEP 735 – Dependency Groups in pyproject.toml had been accepted and standardized by PyPA, it still didn't register how this should impact my pyproject.toml configurations.

In my previous post, I argued that absent a standard place to put dev dependencies in pyproject.toml, we should opt to use optional-dependencies. However, dependency groups seem to offer a nice standard place for such dependencies: these are bundles of dependencies that don't get built into the final distribution (i.e. they are not required to run the package).

Feels like the best of both worlds and uv already started using dependency-groups.dev as the place that uv add --dev writes to and this group is sync'd by default when using uv sync and uv run.

I only really got this when I read Simon Willison's post about how he's using dependency groups to make it easier for people to hack on his code.


πŸ“– Remix: Making Art and Commerce Thrive in the Hybrid Economy by Lawrence Lessig (2002; via Tribe of Mentors & Joseph Gordon Levitt). I knew most of these ideas from having read TechDirt for so many years and listening to Lessig talk about these ideas for several decades. Still, I was surprised how much of the fights we have today still stem from a basic disagreement about copyright and how art gets made.







castfit 0.1.3 #

Now with a non-exhaustive is_subtype function

castfit 0.1.3 is available. The biggest thing I did was implement is_subtype which is a forced me to learn about invariant, covariant, and contravariant types.

To install castfit:

# modern (recommended)
uv add castfit

# classic
python -m pip install castfit

Read more


Release Notes 0.1.3 - 2025-11-27T03:12:11Z #

Changed

  • #33 PyPI publishing to support newer uv build metadata
  • #40 PyPI publishing to use uv publish instead of pypa/gh-action-pypi-publish

Added

  • #23 ability to type check Callable via is_subtype
  • #34 support for property fields on classes
  • #35 __name__ to TypeInfo if present
  • #36 support for default values in dataclasses.Field
  • #37 support for function definitions in classes

Removed

  • #40 support for python 3.9

Security

  • #40 We are trying out uv publish instead of pypa/gh-action-pypi-publish.


πŸ“– Remote: Office Not Required by Jason Fried & David Heinemeier Hansson (2013; via Iridescent Learning). It's interesting to see how work from home policies have ebbed and flowed since 2013.








πŸ“ Claude Agent Skills: A First Principles Deep Dive (Han Lee). Very long, but informative break down of how Claude's Agent Skills works and how its different from function calling. I was particularly impressed by how the UI has to adapt between information being fed back to the LLM and information for the user.


πŸ“ SQLite concurrency and why you should care about it (Jean-Pierre Bachmann / Jellyfin). In all the times I've gotten a SQLite locking issue, the solution has always been to retry a few times (until some other process releases the lock). But this article suggests a few other ways to solve the problem.


πŸ“– The Wise Man's Fear by Patrick Rothfuss (2011; via Shalev NessAiver). Sequel to The Name of the Wind. Patrick Rothfuss joins the ranks of several other fantasy authors in having an unfinished series. I ended up reading the rants of his fans and editors as well as counter points that authors don't owe readers books. This book was a fine sequel; not as great and a bit graphic at times.


πŸ“– The Name of the Wind by Patrick Rothfuss (2007; via Shalev NessAiver). It's got stories-within-stories, sympathetic magic-as-physics, and a prodigy for a main character. What more could you want?








View all posts