|
6 | 6 | """Build the coreai-opt package. |
7 | 7 |
|
8 | 8 | Usage: |
9 | | - build.py Build a standard wheel from the current version |
10 | | - build.py --dev Build a dev wheel with a PEP 440 .dev version |
| 9 | + build.py --no-sources Build a release: the `.dev` suffix stripped, via |
| 10 | + `uv build --no-sources` (ignores [tool.uv.sources]; |
| 11 | + the recommended way to build the publishable |
| 12 | + artifact). Called by `make build`. |
| 13 | + build.py --dev Build a dev wheel with a timestamped PEP 440 .dev |
| 14 | + version. Called by `make build-dev`. |
| 15 | +
|
| 16 | +``main`` carries the next planned release with a ``.dev0`` suffix in ``_about.py`` |
| 17 | +(e.g. ``0.2.2.dev0``); that suffix is only ever an on-tree marker and must never |
| 18 | +end up in a built wheel. This script computes the version to build, writes it |
| 19 | +into ``_about.py``, builds, then restores the file. A repo that vendors this one |
| 20 | +(building a single combined wheel from both trees) can insert one extra release |
| 21 | +segment via ``COREAI_OPT_VERSION_EXTENSION``; see |
| 22 | +``scripts/release/release_utils.apply_version_extension``. |
11 | 23 | """ |
12 | 24 |
|
13 | 25 | from __future__ import annotations |
|
24 | 36 | # internal-only scripts use the explicit `external.scripts.*` form instead. |
25 | 37 | from scripts._utils import find_repo_root as _find_repo_root |
26 | 38 | from scripts.release.release_utils import ( |
27 | | - get_dev_release_version, |
28 | | - get_package_version, |
| 39 | + ENV_VERSION_EXTENSION, |
| 40 | + apply_version_extension, |
| 41 | + read_version, |
| 42 | + resolve_about_path, |
| 43 | + resolve_build_version, |
| 44 | + strip_dev_suffix, |
29 | 45 | write_version, |
30 | 46 | ) |
31 | 47 |
|
32 | 48 |
|
33 | | -def run_build() -> None: |
34 | | - """Run ``uv build`` to produce the wheel and sdist.""" |
| 49 | +def run_build(*, no_sources: bool) -> None: |
| 50 | + """Run ``uv build`` to produce the wheel and sdist. |
| 51 | +
|
| 52 | + Args: |
| 53 | + no_sources: Pass ``--no-sources`` to ``uv build``, ignoring |
| 54 | + ``[tool.uv.sources]`` so the artifact doesn't depend on uv-specific |
| 55 | + index overrides — used for the publishable release build. |
| 56 | + """ |
35 | 57 | print(f"Building package with python (version: {sys.version})...") |
36 | | - subprocess.run(["uv", "build"], check=True) |
| 58 | + command = ["uv", "build", *(["--no-sources"] if no_sources else [])] |
| 59 | + subprocess.run(command, check=True) |
37 | 60 | print("Build complete! Check dist/ directory") |
38 | 61 |
|
39 | 62 |
|
40 | 63 | def _build_parser() -> argparse.ArgumentParser: |
41 | 64 | parser = argparse.ArgumentParser(description="Build the coreai-opt package.") |
42 | | - parser.add_argument( |
| 65 | + mode = parser.add_mutually_exclusive_group(required=True) |
| 66 | + mode.add_argument( |
43 | 67 | "--dev", |
44 | 68 | action="store_true", |
45 | | - help="Build a dev wheel with a PEP 440 .dev version", |
| 69 | + help="Build a dev wheel with a timestamped PEP 440 .dev version", |
| 70 | + ) |
| 71 | + mode.add_argument( |
| 72 | + "--no-sources", |
| 73 | + action="store_true", |
| 74 | + help="Build a release via `uv build --no-sources`", |
46 | 75 | ) |
47 | 76 | return parser |
48 | 77 |
|
49 | 78 |
|
50 | 79 | def main() -> None: |
51 | 80 | args = _build_parser().parse_args() |
52 | | - if not args.dev: |
53 | | - run_build() |
54 | | - return |
55 | 81 | repo_root = _find_repo_root(Path(__file__)) |
56 | | - original_version = get_package_version(repo_root) |
57 | | - dev_version = os.environ.get("DEV_VERSION") or get_dev_release_version(original_version) |
| 82 | + |
| 83 | + about = resolve_about_path(repo_root) |
| 84 | + original = about.read_text(encoding="utf-8") # exact bytes to restore afterwards |
| 85 | + on_tree_version = read_version(original) # e.g. "0.2.2.dev0" |
| 86 | + extended = apply_version_extension(on_tree_version, os.environ.get(ENV_VERSION_EXTENSION)) |
| 87 | + release_base = strip_dev_suffix(extended) |
| 88 | + build_version = resolve_build_version( |
| 89 | + release_base, |
| 90 | + dev=args.dev, |
| 91 | + dev_version_override=os.environ.get("DEV_VERSION"), |
| 92 | + ) |
58 | 93 | try: |
59 | | - write_version(repo_root, dev_version) |
60 | | - print(f"Dev version: {dev_version}") |
61 | | - run_build() |
| 94 | + write_version(about, build_version) |
| 95 | + print(f"Version: {build_version}") |
| 96 | + run_build(no_sources=args.no_sources) |
62 | 97 | finally: |
63 | | - write_version(repo_root, original_version) |
| 98 | + about.write_text(original, encoding="utf-8", newline="\n") # restore on-tree version |
64 | 99 |
|
65 | 100 |
|
66 | 101 | if __name__ == "__main__": |
|
0 commit comments