Skip to content

Commit aae009b

Browse files
authored
Update release script for sdist. (#11337)
1 parent 89ed221 commit aae009b

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

dev/release-artifacts.py renamed to ops/script/release_artifacts.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,30 @@
55
"""
66

77
import argparse
8-
import os
98
import shutil
109
import subprocess
1110
import tarfile
1211
import tempfile
1312
from pathlib import Path
14-
from typing import Any, Dict, List, Optional, Tuple, Union
13+
from typing import Dict, List, Optional, Tuple
1514
from urllib.request import urlretrieve
1615

1716
import tqdm
1817
from packaging import version
18+
from pypi_variants import make_pyproject
1919
from sh.contrib import git
20+
from test_utils import PY_PACKAGE
21+
from test_utils import ROOT as root_path
22+
from test_utils import DirectoryExcursion
2023

2124
# S3 bucket hosting the release artifacts
2225
S3_BUCKET_URL = "https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds"
23-
ROOT = Path(__file__).absolute().parent.parent
24-
DIST = ROOT / "python-package" / "dist"
26+
DIST = Path(PY_PACKAGE) / "dist"
27+
ROOT = Path(root_path)
2528

2629
pbar = None
2730

2831

29-
class DirectoryExcursion:
30-
def __init__(self, path: Path) -> None:
31-
self.path = path
32-
self.curdir = Path.cwd().resolve()
33-
34-
def __enter__(self) -> None:
35-
os.chdir(self.path)
36-
37-
def __exit__(self, *args: Any) -> None:
38-
os.chdir(self.curdir)
39-
40-
4132
def show_progress(block_num: int, block_size: int, total_size: int) -> None:
4233
"""Show file download progress."""
4334
global pbar
@@ -118,16 +109,24 @@ def make_python_sdist(
118109
dist_dir = outdir / "dist"
119110
dist_dir.mkdir(exist_ok=True)
120111

121-
# Apply patch to remove NCCL dependency
122-
# Save the original content of pyproject.toml so that we can restore it later
112+
# Build sdist for `xgboost-cpu`.
123113
with DirectoryExcursion(ROOT):
124-
with open("python-package/pyproject.toml", "r") as f:
125-
orig_pyproj_lines = f.read()
126-
with open("ops/patch/remove_nccl_dep.patch", "r") as f:
127-
patch_lines = f.read()
128-
subprocess.run(
129-
["patch", "-p0"], input=patch_lines, check=True, text=True, encoding="utf-8"
114+
make_pyproject("cpu")
115+
with DirectoryExcursion(ROOT / "python-package"):
116+
subprocess.run(["python", "-m", "build", "--sdist"], check=True)
117+
sdist_name = (
118+
f"xgboost_cpu-{release}{rc}{rc_ver}.tar.gz"
119+
if rc
120+
else f"xgboost_cpu-{release}.tar.gz"
130121
)
122+
src = DIST / sdist_name
123+
subprocess.run(["twine", "check", str(src)], check=True)
124+
dest = dist_dir / sdist_name
125+
shutil.move(src, dest)
126+
127+
# Build sdist for `xgboost`.
128+
with DirectoryExcursion(ROOT):
129+
make_pyproject("default")
131130

132131
with DirectoryExcursion(ROOT / "python-package"):
133132
subprocess.run(["python", "-m", "build", "--sdist"], check=True)
@@ -141,10 +140,6 @@ def make_python_sdist(
141140
dest = dist_dir / sdist_name
142141
shutil.move(src, dest)
143142

144-
with DirectoryExcursion(ROOT):
145-
with open("python-package/pyproject.toml", "w") as f:
146-
f.write(orig_pyproj_lines)
147-
148143

149144
def download_python_wheels(branch: str, commit_hash: str, outdir: Path) -> None:
150145
"""Download all Python binary wheels for the specified branch."""
@@ -318,6 +313,7 @@ def main(args: argparse.Namespace) -> None:
318313
rc_ver: Optional[int] = None
319314
else:
320315
# RC release
316+
assert release_parsed.pre is not None
321317
rc, rc_ver = release_parsed.pre
322318
if rc != "rc":
323319
raise ValueError(

0 commit comments

Comments
 (0)