5
5
"""
6
6
7
7
import argparse
8
- import os
9
8
import shutil
10
9
import subprocess
11
10
import tarfile
12
11
import tempfile
13
12
from pathlib import Path
14
- from typing import Any , Dict , List , Optional , Tuple , Union
13
+ from typing import Dict , List , Optional , Tuple
15
14
from urllib .request import urlretrieve
16
15
17
16
import tqdm
18
17
from packaging import version
18
+ from pypi_variants import make_pyproject
19
19
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
20
23
21
24
# S3 bucket hosting the release artifacts
22
25
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 )
25
28
26
29
pbar = None
27
30
28
31
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
-
41
32
def show_progress (block_num : int , block_size : int , total_size : int ) -> None :
42
33
"""Show file download progress."""
43
34
global pbar
@@ -118,16 +109,24 @@ def make_python_sdist(
118
109
dist_dir = outdir / "dist"
119
110
dist_dir .mkdir (exist_ok = True )
120
111
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`.
123
113
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"
130
121
)
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" )
131
130
132
131
with DirectoryExcursion (ROOT / "python-package" ):
133
132
subprocess .run (["python" , "-m" , "build" , "--sdist" ], check = True )
@@ -141,10 +140,6 @@ def make_python_sdist(
141
140
dest = dist_dir / sdist_name
142
141
shutil .move (src , dest )
143
142
144
- with DirectoryExcursion (ROOT ):
145
- with open ("python-package/pyproject.toml" , "w" ) as f :
146
- f .write (orig_pyproj_lines )
147
-
148
143
149
144
def download_python_wheels (branch : str , commit_hash : str , outdir : Path ) -> None :
150
145
"""Download all Python binary wheels for the specified branch."""
@@ -318,6 +313,7 @@ def main(args: argparse.Namespace) -> None:
318
313
rc_ver : Optional [int ] = None
319
314
else :
320
315
# RC release
316
+ assert release_parsed .pre is not None
321
317
rc , rc_ver = release_parsed .pre
322
318
if rc != "rc" :
323
319
raise ValueError (
0 commit comments