Tweaking Build Options in Git Packaging Tools

Before anything else: what are these “Git packaging tools” you speak of? Well, they’re basically programs that help us automate the process of creating and distributing our code as a package for others to use. Some popular ones include Hatchling (which we’ll be using in this tutorial), Setuptools, Flit, PDM, and more!

Now let’s say you have some awesome Python library that you want to share with the world. You can create a Git repository for it on platforms like Github or Bitbucket, but how do we make sure everyone else can easily install and use our code? That’s where packaging tools come in!

First, let’s add a new file called `pyproject.toml` to the root of your project directory (if you don’t have one already). This is like adding some secret sauce to your recipe it tells Git what ingredients we need and how to mix them together. Here’s an example:

# This section specifies the build system for the project
[build-system]
# This line specifies the required packaging tool for the build system
requires = ["hatchling"]
# This line specifies the specific build backend to be used
build-backend = "hatchling.build"

Now let’s say you want to add some extra features to your package that aren’t available by default (like building extension modules). You can do this by adding a `setup.cfg` file in the root directory with these lines:

[build_ext]  # This section specifies the build options for extension modules
include_dirs = my/custom/path  # This option specifies the custom paths to be included for building extensions
# add any custom paths here for your extensions to be built

And that’s it! Now when you run `git build` or `hatch build`, Git will automatically use Hatchling (or whatever backend you chose) to create a distribution package from your code. You can also customize other options like metadata, input files, and more by adding additional configuration in the `pyproject.toml` file.

It’s not as complicated as it sounds (or tastes), but it can make a big difference when sharing your code with others.

SICORPS