initial support for distribution via pypi wheels

This commit is contained in:
Mick Grove 2026-02-04 12:42:01 -08:00
commit 1c3ea6cb22
4 changed files with 51 additions and 7 deletions

5
.gitignore vendored
View file

@ -212,4 +212,7 @@ fabric.properties
rust-project.json
.dockerignore
# End of https://www.toptal.com/developers/gitignore/api/intellij,rust-analyzer
# End of https://www.toptal.com/developers/gitignore/api/intellij,rust-analyzer
# build artifacts
/dist-pypi/
*.whl

View file

@ -1 +1 @@
__version__ = "0.0.0"
__version__ = "1.2.3"

View file

@ -29,6 +29,7 @@ kingfisher = "kingfisher:main"
path = "kingfisher/_version.py"
[tool.hatch.build]
ignore-vcs = true
include = [
"kingfisher/**/*.py",
"kingfisher/bin/*",
@ -38,6 +39,5 @@ include = [
[tool.hatch.build.targets.wheel]
only-include = [
"kingfisher",
"kingfisher/bin",
"README.md",
]

View file

@ -51,17 +51,53 @@ while [[ $# -gt 0 ]]; do
esac
done
if [[ -z "$binary_path" || -z "$version" || -z "$plat_name" ]]; then
usage
PYTHON="${PYTHON:-}"
if [[ -z "${PYTHON}" ]]; then
if command -v python >/dev/null 2>&1; then
PYTHON="python"
elif command -v python3 >/dev/null 2>&1; then
PYTHON="python3"
else
echo "Python not found. Install Python 3 (or set PYTHON=/path/to/python3)." >&2
exit 1
fi
fi
# Ensure build module exists
"$PYTHON" -m build --version >/dev/null 2>&1 || {
echo "Installing Python build backend (build)..." >&2
"$PYTHON" -m pip install -U build >/dev/null
}
# Resolve binary_path to an absolute, normalized path (works without realpath)
if [[ -z "$binary_path" ]]; then
echo "Missing --binary" >&2
exit 1
fi
if [[ "$binary_path" != /* ]]; then
# interpret relative to the directory where the user invoked the script
binary_path="$PWD/$binary_path"
fi
# Normalize path and verify it exists
if ! binary_path="$(cd "$(dirname "$binary_path")" && pwd)/$(basename "$binary_path")"; then
echo "Failed to resolve binary path: $binary_path" >&2
exit 1
fi
if [[ ! -f "$binary_path" ]]; then
echo "Binary not found: $binary_path" >&2
echo "Tip: check for typos (e.g. 'kiingfisher' vs 'kingfisher')." >&2
exit 1
fi
root_dir="$(git rev-parse --show-toplevel)"
cd "$root_dir"
pkg_dir="$root_dir/pypi"
bin_dir="$pkg_dir/kingfisher/bin"
@ -74,15 +110,20 @@ fi
cp "$binary_path" "$bin_dir/$binary_name"
chmod +x "$bin_dir/$binary_name" || true
test -x "$bin_dir/$binary_name" || {
echo "Binary copy failed: $bin_dir/$binary_name" >&2
exit 1
}
ls -la "$bin_dir/$binary_name"
cat > "$pkg_dir/kingfisher/_version.py" <<EOF
__version__ = "$version"
EOF
python -m build \
"$PYTHON" -m build \
--wheel \
--outdir "$out_dir" \
--config-setting "--plat-name=$plat_name" \
"$pkg_dir"
echo "Built wheel(s) in $out_dir"