aappleby / hancho

A simple pleasant build system in Python.
MIT License
350 stars 9 forks source link

Enable building sdist, wheel via `python -m build` #6

Closed claui closed 3 months ago

claui commented 3 months ago

This PR allows anyone to python -m build an sdist or wheel for Hancho.

@aappleby In particular, if you ever decide to put hancho on PyPI, you should be able to use this config as-is.

Rationale

Making Hancho available on PyPI allows anyone to install and update Hancho via pip install or whatever dependency management system they like. This is mainly for people who prefer to keep hancho.py in a separate location on their PATH separately from their own development tree, and have it updatable via pip.

Having a PEP-517-conformant pyproject.toml also allows system package maintainers to package Hancho for their distribution with little modification.

Design

To keep aligned to Hancho’s project mission, this particular pyproject.toml is specifically designed to let hancho.py remain an independent standalone script in the project root.

In other words, users will still be able to pick just the hancho.py file and copy it into their project development tree as-is, without caring about pyproject.toml or anything else if they prefer so.

How to use

To build an sdist and wheel, install PyPA’s build package first.

Then run:

python -m build

To upload the resulting sdist and wheel to PyPI or TestPyPI, use their web front-end or Twine.

Or have a GitHub workflow publish Hancho on PyPI automatically every time you push a Git tag.

Implementation note

In case you wonder why I choose poetry-core as a build backend:

In contrast to other build backends like setuptools, which would have required hancho.py to go in a subdirectory that matches the package name, poetry-core supports building a package from a single-file *.py module even if it lives in a project root directly, i.e. next to pyproject.toml.

This is to make sure that hancho.py remains a portable, self-contained script that doesn’t require PyPI, pip, or anything else, and can be copied as-is anywhere you like.

Example in the wild

One real-life example of a working system package using the Poetry backend is the hancho AUR package (PKGBUILD, pyproject.toml).

Related issue

This PR addresses #1 if you choose so.

aappleby commented 3 months ago

Nice! I was wondering how much work that would be - I'll merge it shortly.

aappleby commented 3 months ago

Merged.