|
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 | +``_about.py`` stores ``latest_released_version`` (the last tagged release) by |
| 17 | +hand; ``__version__`` is computed from it — add one to its last number, add |
| 18 | +``.dev0``. This script computes the version to build from |
| 19 | +``latest_released_version``, not from the on-tree ``__version__`` (which must |
| 20 | +never be treated as already released), writes it into ``_about.py``, builds, |
| 21 | +then restores the file. A repo that uses this one as a submodule (building |
| 22 | +one combined wheel) can add its own extra number to the version with |
| 23 | +``COREAI_OPT_VERSION_EXTENSION``; see |
| 24 | +``scripts/release/release_utils.next_release_base``. |
11 | 25 | """ |
12 | 26 |
|
13 | 27 | from __future__ import annotations |
|
24 | 38 | # internal-only scripts use the explicit `external.scripts.*` form instead. |
25 | 39 | from scripts._utils import find_repo_root as _find_repo_root |
26 | 40 | from scripts.release.release_utils import ( |
27 | | - get_dev_release_version, |
28 | | - get_package_version, |
| 41 | + ENV_VERSION_EXTENSION, |
| 42 | + next_release_base, |
| 43 | + read_latest_released_version, |
| 44 | + resolve_about_path, |
| 45 | + resolve_build_version, |
29 | 46 | write_version, |
30 | 47 | ) |
31 | 48 |
|
32 | 49 |
|
33 | | -def run_build() -> None: |
34 | | - """Run ``uv build`` to produce the wheel and sdist.""" |
| 50 | +def run_build(*, no_sources: bool) -> None: |
| 51 | + """Run ``uv build`` to produce the wheel and sdist. |
| 52 | +
|
| 53 | + Args: |
| 54 | + no_sources: Pass ``--no-sources`` to ``uv build``, ignoring |
| 55 | + ``[tool.uv.sources]`` so the artifact doesn't depend on uv-specific |
| 56 | + index overrides — used for the publishable release build. |
| 57 | + """ |
35 | 58 | print(f"Building package with python (version: {sys.version})...") |
36 | | - subprocess.run(["uv", "build"], check=True) |
| 59 | + command = ["uv", "build", *(["--no-sources"] if no_sources else [])] |
| 60 | + subprocess.run(command, check=True) |
37 | 61 | print("Build complete! Check dist/ directory") |
38 | 62 |
|
39 | 63 |
|
40 | 64 | def _build_parser() -> argparse.ArgumentParser: |
41 | 65 | parser = argparse.ArgumentParser(description="Build the coreai-opt package.") |
42 | | - parser.add_argument( |
| 66 | + mode = parser.add_mutually_exclusive_group(required=True) |
| 67 | + mode.add_argument( |
43 | 68 | "--dev", |
44 | 69 | action="store_true", |
45 | | - help="Build a dev wheel with a PEP 440 .dev version", |
| 70 | + help="Build a dev wheel with a timestamped PEP 440 .dev version", |
| 71 | + ) |
| 72 | + mode.add_argument( |
| 73 | + "--no-sources", |
| 74 | + action="store_true", |
| 75 | + help="Build a release via `uv build --no-sources`", |
46 | 76 | ) |
47 | 77 | return parser |
48 | 78 |
|
49 | 79 |
|
50 | 80 | def main() -> None: |
51 | 81 | args = _build_parser().parse_args() |
52 | | - if not args.dev: |
53 | | - run_build() |
54 | | - return |
55 | 82 | 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) |
| 83 | + |
| 84 | + about = resolve_about_path(repo_root) |
| 85 | + original = about.read_text(encoding="utf-8") # exact bytes to restore afterwards |
| 86 | + latest_released = read_latest_released_version(original) |
| 87 | + release_base = next_release_base(latest_released, os.environ.get(ENV_VERSION_EXTENSION)) |
| 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