Skip to content

Commit e6f94c9

Browse files
authored
Merge pull request #536 from tiran/prebuilt-wheel-hook
Implement prebuilt-wheel hook
2 parents d7f5395 + 3634fa2 commit e6f94c9

File tree

13 files changed

+163
-12
lines changed

13 files changed

+163
-12
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ jobs:
100100
- optimize_build
101101
- extra_metadata
102102
- elfdeps
103+
- prebuilt_wheel_hook
103104
os:
104105
- ubuntu-latest
105106
- macos-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ __pycache__/
1919
/package.json
2020
/e2e-output/
2121
/dist/
22+
/e2e/fromager_hooks/build
23+
/e2e/fromager_hooks/dist
2224
/e2e/pyo3_test/.cargo
2325
/e2e/pyo3_test/build
2426
/e2e/pyo3_test/dist

.mergify.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ pull_request_rules:
2727
conditions:
2828
- and:
2929
- check-success=e2e (3.11, 1.75, bootstrap, ubuntu-latest)
30-
- check-success=e2e (3.11, 1.75, bootstrap_extras, ubuntu-latest)
3130
- check-success=e2e (3.11, 1.75, bootstrap_build_tags, ubuntu-latest)
32-
- check-success=e2e (3.11, 1.75, bootstrap_prerelease, ubuntu-latest)
33-
- check-success=e2e (3.11, 1.75, bootstrap_constraints, ubuntu-latest)
3431
- check-success=e2e (3.11, 1.75, bootstrap_cache, ubuntu-latest)
32+
- check-success=e2e (3.11, 1.75, bootstrap_constraints, ubuntu-latest)
33+
- check-success=e2e (3.11, 1.75, bootstrap_extras, ubuntu-latest)
34+
- check-success=e2e (3.11, 1.75, bootstrap_prerelease, ubuntu-latest)
3535
- check-success=e2e (3.11, 1.75, build, ubuntu-latest)
3636
- check-success=e2e (3.11, 1.75, build_order, ubuntu-latest)
3737
- check-success=e2e (3.11, 1.75, build_settings, ubuntu-latest)
@@ -44,21 +44,22 @@ pull_request_rules:
4444
- check-success=e2e (3.11, 1.75, optimize_build, ubuntu-latest)
4545
- check-success=e2e (3.11, 1.75, override, ubuntu-latest)
4646
- check-success=e2e (3.11, 1.75, pep517_build_sdist, ubuntu-latest)
47+
- check-success=e2e (3.11, 1.75, prebuilt_wheel_hook, ubuntu-latest)
4748
- check-success=e2e (3.11, 1.75, prebuilt_wheels_alt_server, ubuntu-latest)
4849
- check-success=e2e (3.11, 1.75, report_missing_dependency, ubuntu-latest)
4950
- check-success=e2e (3.11, 1.75, rust_vendor, ubuntu-latest)
5051
- check-success=e2e (3.12, 1.75, bootstrap, macos-latest)
5152
- check-success=e2e (3.12, 1.75, bootstrap, ubuntu-latest)
52-
- check-success=e2e (3.12, 1.75, bootstrap_extras, macos-latest)
53-
- check-success=e2e (3.12, 1.75, bootstrap_extras, ubuntu-latest)
5453
- check-success=e2e (3.12, 1.75, bootstrap_build_tags, macos-latest)
5554
- check-success=e2e (3.12, 1.75, bootstrap_build_tags, ubuntu-latest)
56-
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, macos-latest)
57-
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, ubuntu-latest)
55+
- check-success=e2e (3.12, 1.75, bootstrap_cache, macos-latest)
56+
- check-success=e2e (3.12, 1.75, bootstrap_cache, ubuntu-latest)
5857
- check-success=e2e (3.12, 1.75, bootstrap_constraints, macos-latest)
5958
- check-success=e2e (3.12, 1.75, bootstrap_constraints, ubuntu-latest)
60-
- check-success=e2e (3.12, 1.75, bootstrap_cache, ubuntu-latest)
61-
- check-success=e2e (3.12, 1.75, bootstrap_cache, macos-latest)
59+
- check-success=e2e (3.12, 1.75, bootstrap_extras, macos-latest)
60+
- check-success=e2e (3.12, 1.75, bootstrap_extras, ubuntu-latest)
61+
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, macos-latest)
62+
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, ubuntu-latest)
6263
- check-success=e2e (3.12, 1.75, build, macos-latest)
6364
- check-success=e2e (3.12, 1.75, build, ubuntu-latest)
6465
- check-success=e2e (3.12, 1.75, build_order, macos-latest)
@@ -83,6 +84,8 @@ pull_request_rules:
8384
- check-success=e2e (3.12, 1.75, override, ubuntu-latest)
8485
- check-success=e2e (3.12, 1.75, pep517_build_sdist, macos-latest)
8586
- check-success=e2e (3.12, 1.75, pep517_build_sdist, ubuntu-latest)
87+
- check-success=e2e (3.12, 1.75, prebuilt_wheel_hook, macos-latest)
88+
- check-success=e2e (3.12, 1.75, prebuilt_wheel_hook, ubuntu-latest)
8689
- check-success=e2e (3.12, 1.75, prebuilt_wheels_alt_server, macos-latest)
8790
- check-success=e2e (3.12, 1.75, prebuilt_wheels_alt_server, ubuntu-latest)
8891
- check-success=e2e (3.12, 1.75, report_missing_dependency, macos-latest)

docs/customization.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ Fromager supports plugging in Python hooks to be run after build events.
276276
The `post_build` hook runs after a wheel is successfully built and can be used
277277
to publish that wheel to a package index or take other post-build actions.
278278

279+
NOTE: The hook is not run for prebuilt wheels.
280+
279281
Configure a `post_build` hook in your `pyproject.toml` like this:
280282

281283
```toml
@@ -302,3 +304,35 @@ def post_build(
302304
f"{req.name}: running post build hook for {sdist_filename} and {wheel_filename}"
303305
)
304306
```
307+
308+
### prebuilt_wheel
309+
310+
The `prebuilt_wheel` hook runs after a prebuilt wheel has been downloaded and
311+
can be used to publish that wheel to a package index or take other post-build
312+
actions.
313+
314+
Configure a `prebuilt_wheel` hook in your `pyproject.toml` like this:
315+
316+
```toml
317+
[project.entry-points."fromager.hooks"]
318+
prebuilt_wheel = "package_plugins.module:function"
319+
```
320+
321+
The input arguments to the `prebuilt_build` hook are the `WorkContext`,
322+
`Requirement` being built, the distribution name and version, and the wheel
323+
filename.
324+
325+
NOTE: The files should not be renamed or moved.
326+
327+
```python
328+
def prebuilt_wheel(
329+
ctx: context.WorkContext,
330+
req: Requirement,
331+
dist_name: str,
332+
dist_version: str,
333+
wheel_filename: pathlib.Path,
334+
):
335+
logger.info(
336+
f"{req.name}: running prebuilt wheel hook for {wheel_filename}"
337+
)
338+
```

e2e/post_build_hook/build/lib/package_plugins/post_build.py renamed to e2e/fromager_hooks/build/lib/package_plugins/post_build.py

File renamed without changes.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ requires-python = ">=3.11"
2929
dependencies = []
3030

3131
[project.entry-points."fromager.hooks"]
32-
post_build = "package_plugins.post_build:after_build_wheel"
32+
post_build = "package_plugins.hooks:after_build_wheel"
33+
prebuilt_wheel = "package_plugins.hooks:after_prebuilt_wheel"

e2e/post_build_hook/src/package_plugins/post_build.py renamed to e2e/fromager_hooks/src/package_plugins/hooks.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,18 @@ def after_build_wheel(
2222
test_file = sdist_filename.parent / "test-output-file.txt"
2323
logger.info(f"{req.name}: post-build hook writing to {test_file}")
2424
test_file.write_text(f"{dist_name}=={dist_version}")
25+
26+
27+
def after_prebuilt_wheel(
28+
ctx: context.WorkContext,
29+
req: Requirement,
30+
dist_name: str,
31+
dist_version: str,
32+
wheel_filename: pathlib.Path,
33+
):
34+
logger.info(
35+
f"{req.name}: running post build hook in {__name__} for {wheel_filename}"
36+
)
37+
test_file = ctx.work_dir / "test-prebuilt.txt"
38+
logger.info(f"{req.name}: prebuilt-wheel hook writing to {test_file}")
39+
test_file.write_text(f"{dist_name}=={dist_version}")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variants:
2+
cpu:
3+
pre_built: True

e2e/test_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DIST="stevedore"
1212
VERSION="5.2.0"
1313

1414
# Install hook for test
15-
pip install e2e/post_build_hook
15+
pip install e2e/fromager_hooks
1616

1717
OS=$(uname)
1818
if [ "$OS" = "Darwin" ]; then

e2e/test_build_settings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DIST="stevedore"
1212
VERSION="5.2.0"
1313

1414
# Install hook for test
15-
pip install e2e/post_build_hook
15+
pip install e2e/fromager_hooks
1616

1717
# Bootstrap the test project
1818
fromager \

0 commit comments

Comments
 (0)