Skip to content

Hatch v1.10.0

Hatch v1.10.0 brings a test command, support for UV, and a Python script runner.

Test command

The new test command allows you to easily run tests for your project on multiple versions of Python. The default behavior follows best practices, using pytest with select plugins for test execution and coverage.py for code coverage measurement.

The command is designed to be both simple to use while also satisfying the needs of most projects. For example, the following shows Hatch running tests for Jinja in all environments in the default matrix:

Testing Jinja example

Here is us testing Rich, with a bit of configuration:

Testing Rich example

See the tutorial for a detailed walk-through and the config reference for options.

UV

The package installer UV, brought to you by the same folks behind Ruff, is now supported. In any environment, you can set the installer option to uv to use UV in place of virtualenv & pip for virtual environment creation and dependency management, respectively. This often results in a significant performance benefit.

For example, if you wanted to enable this functionality for the default environment, you could set the following:

[tool.hatch.envs.default]
installer = "uv"
[envs.default]
installer = "uv"

Semi-internal environments like those used for testing and static analysis have this enabled by default.

See the how-to guide for more information about switching the installer.

Python script runner

The run command now supports executing Python scripts with inline metadata as standardized by PEP 723.

As an example, consider the following script:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "httpx",
#   "rich",
# ]
# ///

import httpx
from rich.pretty import pprint

resp = httpx.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

If you run the script for the first time as follows:

hatch run script.py

Hatch will create a dedicated environment for that script using a version of Python greater than or equal to 3.11 with dependencies httpx and rich.

Script running example

See the how-to guide for more information.

Static analysis

The environment used for static analysis is now completely configurable such that you can fully alter the underlying behavior of the fmt command (see the how-to).

Additionally, Ruff has been updated to version 1.4.0 and the rules selected by default have been updated accordingly. Check out their blog post about how the new hand-written parser has made it twice as fast!

Community highlights

Visual Studio Code

Visual Studio Code announced support for Hatch environments in their latest release. This means that you can now easily discover and select Hatch environments for your projects directly from the editor.

See the how-to guide for detailed instructions.

CMake build plugin

A new release of the extension module builder scikit-build-core has introduced a build plugin for Hatchling. This means that you can use Hatchling as your build backend while also shipping extension modules built with CMake.

To get started, add the dependency to your build requirements:

[build-system]
requires = ["hatchling>=1.24.2", "scikit-build-core~=0.9.3"]
build-backend = "hatchling.build"

Then explicitly enable the experimental option (acknowledging that the plugin will move to a dedicated package in the future):

[tool.hatch.build.targets.wheel.hooks.scikit-build]
experimental = true
[build.targets.wheel.hooks.scikit-build]
experimental = true

At this point, you can create your CMakeLists.txt file as usual and start building your extension modules with CMake! Check out the dedicated example project for a complete demonstration.

Meta

Docs

The efforts toward documentation improvements have increased substantially and the priorities have shifted. From now on expect to see far more tutorials and how-to guides rather than just reference material.

Future

Upcoming features include:

  • workspaces functionality similar to Cargo
  • commands to manage dependencies
  • Windows release artifacts signed by the PSF (just like macOS)
  • performance improvements for both the CLI and the Hatchling build system

Support

If you or your organization finds value in what Hatch provides, consider a sponsorship to assist with maintenance and more rapid development!