hatch-prebuilt 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hatch_prebuilt-0.1.0/.github/dependabot.yml +33 -0
- hatch_prebuilt-0.1.0/.github/workflows/labeler.yml +15 -0
- hatch_prebuilt-0.1.0/.github/workflows/pre-commit.yml +16 -0
- hatch_prebuilt-0.1.0/.github/workflows/publish.yml +86 -0
- hatch_prebuilt-0.1.0/.github/workflows/release-drafter.yml +17 -0
- hatch_prebuilt-0.1.0/.github/workflows/stale.yml +13 -0
- hatch_prebuilt-0.1.0/.github/workflows/test.yml +35 -0
- hatch_prebuilt-0.1.0/.github/zizmor.yml +8 -0
- hatch_prebuilt-0.1.0/.gitignore +6 -0
- hatch_prebuilt-0.1.0/.pre-commit-config.yaml +26 -0
- hatch_prebuilt-0.1.0/LICENSE +21 -0
- hatch_prebuilt-0.1.0/PKG-INFO +137 -0
- hatch_prebuilt-0.1.0/README.md +115 -0
- hatch_prebuilt-0.1.0/pyproject.toml +49 -0
- hatch_prebuilt-0.1.0/src/hatch_prebuilt/__init__.py +299 -0
- hatch_prebuilt-0.1.0/src/hatch_prebuilt/binary.py +139 -0
- hatch_prebuilt-0.1.0/src/hatch_prebuilt/download.py +93 -0
- hatch_prebuilt-0.1.0/src/hatch_prebuilt/static_binaries.py +217 -0
- hatch_prebuilt-0.1.0/tests/fakes.py +45 -0
- hatch_prebuilt-0.1.0/tests/test_binary.py +83 -0
- hatch_prebuilt-0.1.0/tests/test_download.py +47 -0
- hatch_prebuilt-0.1.0/tests/test_minisign.py +79 -0
- hatch_prebuilt-0.1.0/tests/test_recipe.py +146 -0
- hatch_prebuilt-0.1.0/tests/test_static_binaries.py +176 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: github-actions
|
|
9
|
+
directory: /
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
12
|
+
cooldown:
|
|
13
|
+
default-days: 7
|
|
14
|
+
groups:
|
|
15
|
+
actions:
|
|
16
|
+
patterns:
|
|
17
|
+
- "*"
|
|
18
|
+
commit-message:
|
|
19
|
+
# Prefix commit message with "chore: "
|
|
20
|
+
prefix: "chore"
|
|
21
|
+
- package-ecosystem: pip
|
|
22
|
+
directory: /
|
|
23
|
+
schedule:
|
|
24
|
+
interval: "weekly"
|
|
25
|
+
cooldown:
|
|
26
|
+
default-days: 7
|
|
27
|
+
groups:
|
|
28
|
+
pip:
|
|
29
|
+
patterns:
|
|
30
|
+
- "*"
|
|
31
|
+
commit-message:
|
|
32
|
+
# Prefix commit message with "chore: "
|
|
33
|
+
prefix: "chore"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: PR Auto-labeler
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
# pull_request event is required for auto-labeler
|
|
5
|
+
pull_request:
|
|
6
|
+
types: [opened, reopened, synchronize, edited]
|
|
7
|
+
|
|
8
|
+
permissions: {}
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
draft-release:
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
pull-requests: write
|
|
15
|
+
uses: cpp-linter/.github/.github/workflows/pr-labeler.yml@main
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: pre-commit
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
types: [opened, synchronize, reopened, edited]
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
permissions: {}
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
pre-commit:
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
uses: cpp-linter/.github/.github/workflows/pre-commit.yml@main
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
name: Upload Python Package
|
|
2
|
+
|
|
3
|
+
# Publishing a GitHub release uploads the package to PyPI. Running this
|
|
4
|
+
# workflow by hand on main uploads it to TestPyPI. Both use PyPI trusted
|
|
5
|
+
# publishing (OIDC), so no API token is stored in this repository; the
|
|
6
|
+
# publish jobs run in the "pypi" / "testpypi" environments.
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
permissions: {}
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
permissions:
|
|
19
|
+
contents: read
|
|
20
|
+
# for the build provenance attestation
|
|
21
|
+
id-token: write
|
|
22
|
+
attestations: write
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
25
|
+
with:
|
|
26
|
+
# hatch-vcs takes the version from the tags
|
|
27
|
+
fetch-depth: 0
|
|
28
|
+
persist-credentials: false
|
|
29
|
+
- uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
|
|
30
|
+
with:
|
|
31
|
+
enable-cache: false
|
|
32
|
+
- name: Build the sdist and the wheel
|
|
33
|
+
run: uv build
|
|
34
|
+
- name: Check the distributions
|
|
35
|
+
run: uvx twine check --strict dist/*
|
|
36
|
+
- name: Attest build provenance
|
|
37
|
+
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
|
|
38
|
+
with:
|
|
39
|
+
subject-path: dist/*
|
|
40
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
41
|
+
with:
|
|
42
|
+
name: dist
|
|
43
|
+
path: dist
|
|
44
|
+
|
|
45
|
+
publish-testpypi:
|
|
46
|
+
name: Publish to TestPyPI
|
|
47
|
+
needs: build
|
|
48
|
+
if: >-
|
|
49
|
+
github.event_name == 'workflow_dispatch' &&
|
|
50
|
+
github.ref == 'refs/heads/main' &&
|
|
51
|
+
github.repository_owner == 'cpp-linter'
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
|
+
environment:
|
|
54
|
+
name: testpypi
|
|
55
|
+
url: https://test.pypi.org/project/hatch-prebuilt/
|
|
56
|
+
permissions:
|
|
57
|
+
id-token: write # trusted publishing
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
60
|
+
with:
|
|
61
|
+
name: dist
|
|
62
|
+
path: dist
|
|
63
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
64
|
+
with:
|
|
65
|
+
repository-url: https://test.pypi.org/legacy/
|
|
66
|
+
skip-existing: true
|
|
67
|
+
|
|
68
|
+
publish-pypi:
|
|
69
|
+
name: Publish to PyPI
|
|
70
|
+
needs: build
|
|
71
|
+
if: >-
|
|
72
|
+
github.event_name == 'release' &&
|
|
73
|
+
startsWith(github.ref, 'refs/tags/') &&
|
|
74
|
+
github.repository_owner == 'cpp-linter'
|
|
75
|
+
runs-on: ubuntu-latest
|
|
76
|
+
environment:
|
|
77
|
+
name: pypi
|
|
78
|
+
url: https://pypi.org/project/hatch-prebuilt/
|
|
79
|
+
permissions:
|
|
80
|
+
id-token: write # trusted publishing
|
|
81
|
+
steps:
|
|
82
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
83
|
+
with:
|
|
84
|
+
name: dist
|
|
85
|
+
path: dist
|
|
86
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Release Drafter
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "main"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions: {}
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
draft-release:
|
|
13
|
+
permissions:
|
|
14
|
+
# write permission is required to create a github release
|
|
15
|
+
contents: write
|
|
16
|
+
pull-requests: read
|
|
17
|
+
uses: cpp-linter/.github/.github/workflows/release-drafter.yml@main
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions: {}
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
18
|
+
python: ['3.9', '3.14']
|
|
19
|
+
runs-on: ${{ matrix.os }}
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
24
|
+
with:
|
|
25
|
+
# hatch-vcs takes the version from the tags
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
persist-credentials: false
|
|
28
|
+
- uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
|
|
29
|
+
with:
|
|
30
|
+
enable-cache: false
|
|
31
|
+
- name: Run the tests
|
|
32
|
+
shell: bash # PowerShell would not expand $PYTHON
|
|
33
|
+
env:
|
|
34
|
+
PYTHON: ${{ matrix.python }}
|
|
35
|
+
run: uv run --python "$PYTHON" --group test pytest -v
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
autofix_prs: true
|
|
3
|
+
autofix_commit_msg: 'chore: auto fixes from pre-commit.com hooks'
|
|
4
|
+
autoupdate_commit_msg: 'chore: pre-commit autoupdate'
|
|
5
|
+
autoupdate_schedule: quarterly
|
|
6
|
+
|
|
7
|
+
repos:
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: v6.0.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: trailing-whitespace
|
|
12
|
+
- id: end-of-file-fixer
|
|
13
|
+
- id: check-docstring-first
|
|
14
|
+
- id: check-added-large-files
|
|
15
|
+
- id: check-yaml
|
|
16
|
+
- id: check-merge-conflict
|
|
17
|
+
- id: debug-statements
|
|
18
|
+
- repo: https://github.com/asottile/pyupgrade
|
|
19
|
+
rev: v3.22.0
|
|
20
|
+
hooks:
|
|
21
|
+
- id: pyupgrade
|
|
22
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
23
|
+
rev: v0.17.1
|
|
24
|
+
hooks:
|
|
25
|
+
- id: ruff-check
|
|
26
|
+
- id: ruff-format
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cpp-linter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: hatch-prebuilt
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Build Python wheels that install prebuilt executables unchanged, with hatchling
|
|
5
|
+
Project-URL: Source, https://github.com/cpp-linter/hatch-prebuilt
|
|
6
|
+
Project-URL: Issues, https://github.com/cpp-linter/hatch-prebuilt/issues
|
|
7
|
+
Author-email: Xianpeng Shen <xianpeng.shen@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: binary,hatch,hatchling,packaging,wheel
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Framework :: Hatch
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
16
|
+
Classifier: Topic :: System :: Archiving :: Packaging
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: hatchling>=1.27
|
|
19
|
+
Provides-Extra: minisign
|
|
20
|
+
Requires-Dist: cryptography>=42; extra == 'minisign'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# hatch-prebuilt
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/hatch-prebuilt/)
|
|
26
|
+
[](https://github.com/cpp-linter/hatch-prebuilt/actions/workflows/test.yml)
|
|
27
|
+
[](https://cpp-linter.github.io/)
|
|
28
|
+
|
|
29
|
+
Build Python wheels that install prebuilt executables unchanged, with
|
|
30
|
+
[hatchling](https://hatch.pypa.io/latest/). `pip install` or `uv pip install` puts the executable
|
|
31
|
+
straight into the environment's `bin/` (`Scripts\` on Windows), with no Python wrapper in
|
|
32
|
+
between, so starting it costs nothing extra.
|
|
33
|
+
|
|
34
|
+
The [cpp-linter](https://github.com/cpp-linter) wheel repositories use it:
|
|
35
|
+
[ccache-wheel](https://github.com/cpp-linter/ccache-wheel) (`ccache-bin`),
|
|
36
|
+
[llvm-cov-wheel](https://github.com/cpp-linter/llvm-cov-wheel) (`llvm-cov`) and
|
|
37
|
+
[clangd-wheel](https://github.com/cpp-linter/clangd-wheel) (`clangd-bin`).
|
|
38
|
+
|
|
39
|
+
## What it does
|
|
40
|
+
|
|
41
|
+
A wheel repository describes its tool in `hatch_build.py`: which platforms it has, and how to
|
|
42
|
+
download and verify the files of one version for one platform. hatch-prebuilt does the rest:
|
|
43
|
+
|
|
44
|
+
- picks the version (from a version file, or an environment variable so CI can build older
|
|
45
|
+
versions) and the platform (from an environment variable, or the build machine);
|
|
46
|
+
- checks that every executable is a binary for that platform: ELF machine and static linking,
|
|
47
|
+
Mach-O architecture or universal slices, PE machine;
|
|
48
|
+
- works out the wheel tag, including the minimum macOS version the binaries declare;
|
|
49
|
+
- stages the license files where `license-files` finds them, and gives hatchling the executables
|
|
50
|
+
as shared scripts and any other files (man pages, headers) as shared data.
|
|
51
|
+
|
|
52
|
+
It also has the download helpers the recipes share: retrying downloads, a download cache, SHA-512
|
|
53
|
+
pins, minisign signatures (`hatch-prebuilt[minisign]`) and archive extraction.
|
|
54
|
+
|
|
55
|
+
## A recipe
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
# hatch_build.py
|
|
59
|
+
from pathlib import Path
|
|
60
|
+
|
|
61
|
+
from hatch_prebuilt import Platform, Recipe, Staged, cached_download, check_sha512
|
|
62
|
+
|
|
63
|
+
URL = "https://example.com/mytool-{version}-{platform}{exe}"
|
|
64
|
+
SHA512 = {...}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MyTool(Recipe):
|
|
68
|
+
name = "mytool"
|
|
69
|
+
version_file = "mytool_version.txt"
|
|
70
|
+
platform_variable = "MYTOOL_PLATFORM"
|
|
71
|
+
platforms = (
|
|
72
|
+
Platform(
|
|
73
|
+
"linux-x86_64",
|
|
74
|
+
"manylinux_2_17_x86_64.musllinux_1_1_x86_64",
|
|
75
|
+
"elf-x86_64",
|
|
76
|
+
"linux",
|
|
77
|
+
"x86_64",
|
|
78
|
+
),
|
|
79
|
+
Platform("macos-arm64", "macosx_{macos}_arm64", "macho-arm64", "macos", "arm64"),
|
|
80
|
+
Platform("windows-x86_64", "win_amd64", "pe-x86_64", "windows", "x86_64"),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def stage(self, platform, version):
|
|
84
|
+
url = URL.format(version=version, platform=platform.name, exe=platform.exe)
|
|
85
|
+
binary = cached_download(url, self.cache / Path(url).name)
|
|
86
|
+
check_sha512(binary, SHA512[platform.name], url)
|
|
87
|
+
return Staged(scripts={f"mytool{platform.exe}": binary}, licenses={"LICENSE": ...})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
RECIPE = MyTool(Path(__file__).parent)
|
|
91
|
+
get_metadata_hook, get_build_hook = RECIPE.hooks()
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
raise SystemExit(RECIPE.main())
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```toml
|
|
98
|
+
# pyproject.toml
|
|
99
|
+
[build-system]
|
|
100
|
+
requires = ["hatchling>=1.27", "hatch-prebuilt>=0.1,<1"]
|
|
101
|
+
build-backend = "hatchling.build"
|
|
102
|
+
|
|
103
|
+
[project]
|
|
104
|
+
name = "mytool-bin"
|
|
105
|
+
dynamic = ["version"]
|
|
106
|
+
license-files = ["upstream/LICENSE"]
|
|
107
|
+
|
|
108
|
+
[tool.hatch.metadata.hooks.custom]
|
|
109
|
+
|
|
110
|
+
[tool.hatch.build.targets.wheel]
|
|
111
|
+
bypass-selection = true
|
|
112
|
+
|
|
113
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then `python hatch_build.py platforms` lists the platforms, and
|
|
117
|
+
`MYTOOL_PLATFORM=<platform> python -m build --wheel` builds one wheel, for any platform, on
|
|
118
|
+
Linux or macOS (Windows cannot give the executables their executable bit). The shared
|
|
119
|
+
[`binary-wheels.yml`](https://github.com/cpp-linter/.github/blob/main/.github/workflows/binary-wheels.yml)
|
|
120
|
+
workflow builds and tests all of them, and
|
|
121
|
+
[`templates/binary-wheel/`](https://github.com/cpp-linter/.github/tree/main/templates/binary-wheel)
|
|
122
|
+
is a complete wheel repository to start from.
|
|
123
|
+
|
|
124
|
+
Tools from the
|
|
125
|
+
[clang-tools-static-binaries](https://github.com/cpp-linter/clang-tools-static-binaries)
|
|
126
|
+
releases need even less: `hatch_prebuilt.static_binaries.StaticBinariesRecipe` knows the
|
|
127
|
+
platforms, the file names and the SHA-512 pins in `sources.json`, so the recipe only names the
|
|
128
|
+
tools.
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
See the [contributing guide](https://github.com/cpp-linter/.github/blob/main/CONTRIBUTING.md).
|
|
133
|
+
`uv run --group test pytest` runs the tests.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# hatch-prebuilt
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/hatch-prebuilt/)
|
|
4
|
+
[](https://github.com/cpp-linter/hatch-prebuilt/actions/workflows/test.yml)
|
|
5
|
+
[](https://cpp-linter.github.io/)
|
|
6
|
+
|
|
7
|
+
Build Python wheels that install prebuilt executables unchanged, with
|
|
8
|
+
[hatchling](https://hatch.pypa.io/latest/). `pip install` or `uv pip install` puts the executable
|
|
9
|
+
straight into the environment's `bin/` (`Scripts\` on Windows), with no Python wrapper in
|
|
10
|
+
between, so starting it costs nothing extra.
|
|
11
|
+
|
|
12
|
+
The [cpp-linter](https://github.com/cpp-linter) wheel repositories use it:
|
|
13
|
+
[ccache-wheel](https://github.com/cpp-linter/ccache-wheel) (`ccache-bin`),
|
|
14
|
+
[llvm-cov-wheel](https://github.com/cpp-linter/llvm-cov-wheel) (`llvm-cov`) and
|
|
15
|
+
[clangd-wheel](https://github.com/cpp-linter/clangd-wheel) (`clangd-bin`).
|
|
16
|
+
|
|
17
|
+
## What it does
|
|
18
|
+
|
|
19
|
+
A wheel repository describes its tool in `hatch_build.py`: which platforms it has, and how to
|
|
20
|
+
download and verify the files of one version for one platform. hatch-prebuilt does the rest:
|
|
21
|
+
|
|
22
|
+
- picks the version (from a version file, or an environment variable so CI can build older
|
|
23
|
+
versions) and the platform (from an environment variable, or the build machine);
|
|
24
|
+
- checks that every executable is a binary for that platform: ELF machine and static linking,
|
|
25
|
+
Mach-O architecture or universal slices, PE machine;
|
|
26
|
+
- works out the wheel tag, including the minimum macOS version the binaries declare;
|
|
27
|
+
- stages the license files where `license-files` finds them, and gives hatchling the executables
|
|
28
|
+
as shared scripts and any other files (man pages, headers) as shared data.
|
|
29
|
+
|
|
30
|
+
It also has the download helpers the recipes share: retrying downloads, a download cache, SHA-512
|
|
31
|
+
pins, minisign signatures (`hatch-prebuilt[minisign]`) and archive extraction.
|
|
32
|
+
|
|
33
|
+
## A recipe
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
# hatch_build.py
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
|
|
39
|
+
from hatch_prebuilt import Platform, Recipe, Staged, cached_download, check_sha512
|
|
40
|
+
|
|
41
|
+
URL = "https://example.com/mytool-{version}-{platform}{exe}"
|
|
42
|
+
SHA512 = {...}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class MyTool(Recipe):
|
|
46
|
+
name = "mytool"
|
|
47
|
+
version_file = "mytool_version.txt"
|
|
48
|
+
platform_variable = "MYTOOL_PLATFORM"
|
|
49
|
+
platforms = (
|
|
50
|
+
Platform(
|
|
51
|
+
"linux-x86_64",
|
|
52
|
+
"manylinux_2_17_x86_64.musllinux_1_1_x86_64",
|
|
53
|
+
"elf-x86_64",
|
|
54
|
+
"linux",
|
|
55
|
+
"x86_64",
|
|
56
|
+
),
|
|
57
|
+
Platform("macos-arm64", "macosx_{macos}_arm64", "macho-arm64", "macos", "arm64"),
|
|
58
|
+
Platform("windows-x86_64", "win_amd64", "pe-x86_64", "windows", "x86_64"),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def stage(self, platform, version):
|
|
62
|
+
url = URL.format(version=version, platform=platform.name, exe=platform.exe)
|
|
63
|
+
binary = cached_download(url, self.cache / Path(url).name)
|
|
64
|
+
check_sha512(binary, SHA512[platform.name], url)
|
|
65
|
+
return Staged(scripts={f"mytool{platform.exe}": binary}, licenses={"LICENSE": ...})
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
RECIPE = MyTool(Path(__file__).parent)
|
|
69
|
+
get_metadata_hook, get_build_hook = RECIPE.hooks()
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
raise SystemExit(RECIPE.main())
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```toml
|
|
76
|
+
# pyproject.toml
|
|
77
|
+
[build-system]
|
|
78
|
+
requires = ["hatchling>=1.27", "hatch-prebuilt>=0.1,<1"]
|
|
79
|
+
build-backend = "hatchling.build"
|
|
80
|
+
|
|
81
|
+
[project]
|
|
82
|
+
name = "mytool-bin"
|
|
83
|
+
dynamic = ["version"]
|
|
84
|
+
license-files = ["upstream/LICENSE"]
|
|
85
|
+
|
|
86
|
+
[tool.hatch.metadata.hooks.custom]
|
|
87
|
+
|
|
88
|
+
[tool.hatch.build.targets.wheel]
|
|
89
|
+
bypass-selection = true
|
|
90
|
+
|
|
91
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then `python hatch_build.py platforms` lists the platforms, and
|
|
95
|
+
`MYTOOL_PLATFORM=<platform> python -m build --wheel` builds one wheel, for any platform, on
|
|
96
|
+
Linux or macOS (Windows cannot give the executables their executable bit). The shared
|
|
97
|
+
[`binary-wheels.yml`](https://github.com/cpp-linter/.github/blob/main/.github/workflows/binary-wheels.yml)
|
|
98
|
+
workflow builds and tests all of them, and
|
|
99
|
+
[`templates/binary-wheel/`](https://github.com/cpp-linter/.github/tree/main/templates/binary-wheel)
|
|
100
|
+
is a complete wheel repository to start from.
|
|
101
|
+
|
|
102
|
+
Tools from the
|
|
103
|
+
[clang-tools-static-binaries](https://github.com/cpp-linter/clang-tools-static-binaries)
|
|
104
|
+
releases need even less: `hatch_prebuilt.static_binaries.StaticBinariesRecipe` knows the
|
|
105
|
+
platforms, the file names and the SHA-512 pins in `sources.json`, so the recipe only names the
|
|
106
|
+
tools.
|
|
107
|
+
|
|
108
|
+
## Contributing
|
|
109
|
+
|
|
110
|
+
See the [contributing guide](https://github.com/cpp-linter/.github/blob/main/CONTRIBUTING.md).
|
|
111
|
+
`uv run --group test pytest` runs the tests.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-prebuilt"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Build Python wheels that install prebuilt executables unchanged, with hatchling"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Xianpeng Shen", email = "xianpeng.shen@gmail.com" }]
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
keywords = ["hatch", "hatchling", "wheel", "binary", "packaging"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Framework :: Hatch",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Software Development :: Build Tools",
|
|
21
|
+
"Topic :: System :: Archiving :: Packaging",
|
|
22
|
+
]
|
|
23
|
+
dependencies = ["hatchling>=1.27"]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
# For recipes whose upstream signs its releases with minisign.
|
|
27
|
+
minisign = ["cryptography>=42"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Source = "https://github.com/cpp-linter/hatch-prebuilt"
|
|
31
|
+
Issues = "https://github.com/cpp-linter/hatch-prebuilt/issues"
|
|
32
|
+
|
|
33
|
+
[tool.hatch.version]
|
|
34
|
+
# The version comes from the release tag (v0.1.0 -> 0.1.0).
|
|
35
|
+
source = "vcs"
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
test = ["pytest", "cryptography>=42"]
|
|
39
|
+
dev = [{ include-group = "test" }, "pre-commit"]
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
line-length = 100
|
|
46
|
+
|
|
47
|
+
[tool.ruff.lint.per-file-ignores]
|
|
48
|
+
# Recipes set their tools and platforms as class attributes.
|
|
49
|
+
"tests/*" = ["RUF012"]
|