diff --git a/dev/release-artifacts.py b/ops/script/release_artifacts.py similarity index 92% rename from dev/release-artifacts.py rename to ops/script/release_artifacts.py index fc6c0f3b1307..52963fac8ded 100644 --- a/dev/release-artifacts.py +++ b/ops/script/release_artifacts.py @@ -5,39 +5,30 @@ """ import argparse -import os import shutil import subprocess import tarfile import tempfile from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Dict, List, Optional, Tuple from urllib.request import urlretrieve import tqdm from packaging import version +from pypi_variants import make_pyproject from sh.contrib import git +from test_utils import PY_PACKAGE +from test_utils import ROOT as root_path +from test_utils import DirectoryExcursion # S3 bucket hosting the release artifacts S3_BUCKET_URL = "https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds" -ROOT = Path(__file__).absolute().parent.parent -DIST = ROOT / "python-package" / "dist" +DIST = Path(PY_PACKAGE) / "dist" +ROOT = Path(root_path) pbar = None -class DirectoryExcursion: - def __init__(self, path: Path) -> None: - self.path = path - self.curdir = Path.cwd().resolve() - - def __enter__(self) -> None: - os.chdir(self.path) - - def __exit__(self, *args: Any) -> None: - os.chdir(self.curdir) - - def show_progress(block_num: int, block_size: int, total_size: int) -> None: """Show file download progress.""" global pbar @@ -118,16 +109,24 @@ def make_python_sdist( dist_dir = outdir / "dist" dist_dir.mkdir(exist_ok=True) - # Apply patch to remove NCCL dependency - # Save the original content of pyproject.toml so that we can restore it later + # Build sdist for `xgboost-cpu`. with DirectoryExcursion(ROOT): - with open("python-package/pyproject.toml", "r") as f: - orig_pyproj_lines = f.read() - with open("ops/patch/remove_nccl_dep.patch", "r") as f: - patch_lines = f.read() - subprocess.run( - ["patch", "-p0"], input=patch_lines, check=True, text=True, encoding="utf-8" + make_pyproject("cpu") + with DirectoryExcursion(ROOT / "python-package"): + subprocess.run(["python", "-m", "build", "--sdist"], check=True) + sdist_name = ( + f"xgboost_cpu-{release}{rc}{rc_ver}.tar.gz" + if rc + else f"xgboost_cpu-{release}.tar.gz" ) + src = DIST / sdist_name + subprocess.run(["twine", "check", str(src)], check=True) + dest = dist_dir / sdist_name + shutil.move(src, dest) + + # Build sdist for `xgboost`. + with DirectoryExcursion(ROOT): + make_pyproject("default") with DirectoryExcursion(ROOT / "python-package"): subprocess.run(["python", "-m", "build", "--sdist"], check=True) @@ -141,10 +140,6 @@ def make_python_sdist( dest = dist_dir / sdist_name shutil.move(src, dest) - with DirectoryExcursion(ROOT): - with open("python-package/pyproject.toml", "w") as f: - f.write(orig_pyproj_lines) - def download_python_wheels(branch: str, commit_hash: str, outdir: Path) -> None: """Download all Python binary wheels for the specified branch.""" @@ -318,6 +313,7 @@ def main(args: argparse.Namespace) -> None: rc_ver: Optional[int] = None else: # RC release + assert release_parsed.pre is not None rc, rc_ver = release_parsed.pre if rc != "rc": raise ValueError(