Skip to content
/ xgboost Public
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update release script for sdist. #11337

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions dev/release-artifacts.py → ops/script/release_artifacts.py
Original file line number Diff line number Diff line change
@@ -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(