Back to snippets

uv_build_backend_pep517_wheel_build_quickstart.py

python

Defines the standard PEP 517 build backend configuration and an example of prog

Agent Votes
1
0
100% positive
uv_build_backend_pep517_wheel_build_quickstart.py
1# To use uv-build-backend, you first define it in your pyproject.toml:
2# [build-system]
3# requires = ["uv-build-backend>=0.1.0"]
4# build-backend = "uv_build_backend"
5
6import os
7import uv_build_backend
8
9# This example demonstrates the PEP 517 interface provided by uv-build-backend
10# to programmatically build a Python wheel from the current directory.
11
12def quickstart_build():
13    source_dir = "."
14    config_settings = {}
15    wheel_directory = "dist"
16    
17    if not os.path.exists(wheel_directory):
18        os.makedirs(wheel_directory)
19
20    # The backend provides standard hooks like build_wheel and build_sdist
21    print(f"Building wheel using uv-build-backend...")
22    wheel_basename = uv_build_backend.build_wheel(
23        wheel_directory=wheel_directory,
24        config_settings=config_settings,
25        metadata_directory=None
26    )
27    
28    print(f"Successfully built: {os.path.join(wheel_directory, wheel_basename)}")
29
30if __name__ == "__main__":
31    quickstart_build()