Skip to content

Commit 82d846b

Browse files
authored
Update change_scala_version.py to also change scala.version property (#9897)
1 parent 71d330a commit 82d846b

File tree

12 files changed

+89
-35
lines changed

12 files changed

+89
-35
lines changed

dev/change_scala_version.py

+54-20
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,71 @@
33
import re
44
import shutil
55

6-
try:
7-
import sh
8-
except ImportError as e:
9-
raise ImportError(
10-
"Please install sh in your Python environment.\n"
11-
" - Pip: pip install sh\n"
12-
" - Conda: conda install -c conda-forge sh"
13-
) from e
14-
156

167
def main(args):
8+
if args.scala_version == "2.12":
9+
scala_ver = "2.12"
10+
scala_patchver = "2.12.18"
11+
elif args.scala_version == "2.13":
12+
scala_ver = "2.13"
13+
scala_patchver = "2.13.11"
14+
else:
15+
raise ValueError(f"Unsupported Scala version: {args.scala_version}")
16+
1717
# Clean artifacts
18-
for target in pathlib.Path("jvm-packages/").glob("**/target"):
19-
if target.is_dir():
20-
print(f"Removing {target}...")
21-
shutil.rmtree(target)
18+
if args.purge_artifacts:
19+
for target in pathlib.Path("jvm-packages/").glob("**/target"):
20+
if target.is_dir():
21+
print(f"Removing {target}...")
22+
shutil.rmtree(target)
2223

2324
# Update pom.xml
2425
for pom in pathlib.Path("jvm-packages/").glob("**/pom.xml"):
2526
print(f"Updating {pom}...")
26-
sh.sed(
27-
[
28-
"-i",
29-
f"s/<artifactId>xgboost-jvm_[0-9\\.]*/<artifactId>xgboost-jvm_{args.scala_version}/g",
30-
str(pom),
31-
]
32-
)
27+
with open(pom, "r", encoding="utf-8") as f:
28+
lines = f.readlines()
29+
with open(pom, "w", encoding="utf-8") as f:
30+
replaced_scalaver = False
31+
replaced_scala_binver = False
32+
for line in lines:
33+
for artifact in [
34+
"xgboost-jvm",
35+
"xgboost4j",
36+
"xgboost4j-gpu",
37+
"xgboost4j-spark",
38+
"xgboost4j-spark-gpu",
39+
"xgboost4j-flink",
40+
"xgboost4j-example",
41+
]:
42+
line = re.sub(
43+
f"<artifactId>{artifact}_[0-9\\.]*",
44+
f"<artifactId>{artifact}_{scala_ver}",
45+
line,
46+
)
47+
# Only replace the first occurrence of scala.version
48+
if not replaced_scalaver:
49+
line, nsubs = re.subn(
50+
r"<scala.version>[0-9\.]*",
51+
f"<scala.version>{scala_patchver}",
52+
line,
53+
)
54+
if nsubs > 0:
55+
replaced_scalaver = True
56+
# Only replace the first occurrence of scala.binary.version
57+
if not replaced_scala_binver:
58+
line, nsubs = re.subn(
59+
r"<scala.binary.version>[0-9\.]*",
60+
f"<scala.binary.version>{scala_ver}",
61+
line,
62+
)
63+
if nsubs > 0:
64+
replaced_scala_binver = True
65+
f.write(line)
3366

3467

3568
if __name__ == "__main__":
3669
parser = argparse.ArgumentParser()
70+
parser.add_argument("--purge-artifacts", action="store_true")
3771
parser.add_argument(
3872
"--scala-version",
3973
type=str,

dev/prepare_jvm_release.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def main():
229229
print(
230230
"5. Remove the Scala 2.12 artifacts and build Scala 2.13 artifacts:\n"
231231
" export MAVEN_SKIP_NATIVE_BUILD=1\n"
232-
" python dev/change_scala_version.py --scala-version 2.13\n"
232+
" python dev/change_scala_version.py --scala-version 2.13 --purge-artifacts\n"
233233
" GPG_TTY=$(tty) mvn deploy -Prelease-cpu-only,scala-2.13 -DskipTests"
234234
)
235235
print(

jvm-packages/xgboost4j-example/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>2.0.3</version>
1010
</parent>
1111
<name>xgboost4j-example</name>
12-
<artifactId>xgboost4j-example_${scala.binary.version}</artifactId>
12+
<artifactId>xgboost4j-example_2.12</artifactId>
1313
<version>2.0.3</version>
1414
<packaging>jar</packaging>
1515
<build>
@@ -26,7 +26,7 @@
2626
<dependencies>
2727
<dependency>
2828
<groupId>ml.dmlc</groupId>
29-
<artifactId>xgboost4j-spark_${scala.binary.version}</artifactId>
29+
<artifactId>xgboost4j-spark_2.12</artifactId>
3030
<version>${project.version}</version>
3131
</dependency>
3232
<dependency>
@@ -37,7 +37,7 @@
3737
</dependency>
3838
<dependency>
3939
<groupId>ml.dmlc</groupId>
40-
<artifactId>xgboost4j-flink_${scala.binary.version}</artifactId>
40+
<artifactId>xgboost4j-flink_2.12</artifactId>
4141
<version>${project.version}</version>
4242
</dependency>
4343
</dependencies>

jvm-packages/xgboost4j-flink/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<name>xgboost4j-flink</name>
13-
<artifactId>xgboost4j-flink_${scala.binary.version}</artifactId>
13+
<artifactId>xgboost4j-flink_2.12</artifactId>
1414
<version>2.0.3</version>
1515
<properties>
1616
<flink-ml.version>2.2.0</flink-ml.version>
@@ -30,7 +30,7 @@
3030
<dependencies>
3131
<dependency>
3232
<groupId>ml.dmlc</groupId>
33-
<artifactId>xgboost4j_${scala.binary.version}</artifactId>
33+
<artifactId>xgboost4j_2.12</artifactId>
3434
<version>${project.version}</version>
3535
</dependency>
3636
<dependency>

jvm-packages/xgboost4j-gpu/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<artifactId>xgboost-jvm_2.12</artifactId>
99
<version>2.0.3</version>
1010
</parent>
11-
<artifactId>xgboost4j-gpu_${scala.binary.version}</artifactId>
11+
<artifactId>xgboost4j-gpu_2.12</artifactId>
1212
<name>xgboost4j-gpu</name>
1313
<version>2.0.3</version>
1414
<packaging>jar</packaging>

jvm-packages/xgboost4j-spark-gpu/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>2.0.3</version>
1010
</parent>
1111
<name>xgboost4j-spark-gpu</name>
12-
<artifactId>xgboost4j-spark-gpu_${scala.binary.version}</artifactId>
12+
<artifactId>xgboost4j-spark-gpu_2.12</artifactId>
1313
<build>
1414
<plugins>
1515
<plugin>
@@ -24,7 +24,7 @@
2424
<dependencies>
2525
<dependency>
2626
<groupId>ml.dmlc</groupId>
27-
<artifactId>xgboost4j-gpu_${scala.binary.version}</artifactId>
27+
<artifactId>xgboost4j-gpu_2.12</artifactId>
2828
<version>${project.version}</version>
2929
</dependency>
3030
<dependency>

jvm-packages/xgboost4j-spark/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>2.0.3</version>
1010
</parent>
1111
<name>xgboost4j-spark</name>
12-
<artifactId>xgboost4j-spark_${scala.binary.version}</artifactId>
12+
<artifactId>xgboost4j-spark_2.12</artifactId>
1313
<build>
1414
<plugins>
1515
<plugin>
@@ -24,7 +24,7 @@
2424
<dependencies>
2525
<dependency>
2626
<groupId>ml.dmlc</groupId>
27-
<artifactId>xgboost4j_${scala.binary.version}</artifactId>
27+
<artifactId>xgboost4j_2.12</artifactId>
2828
<version>${project.version}</version>
2929
</dependency>
3030
<dependency>

jvm-packages/xgboost4j/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>2.0.3</version>
1010
</parent>
1111
<name>xgboost4j</name>
12-
<artifactId>xgboost4j_${scala.binary.version}</artifactId>
12+
<artifactId>xgboost4j_2.12</artifactId>
1313
<version>2.0.3</version>
1414
<packaging>jar</packaging>
1515

tests/buildkite/build-jvm-packages.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ echo "--- Build XGBoost JVM packages scala 2.12"
88
tests/ci_build/ci_build.sh jvm docker tests/ci_build/build_jvm_packages.sh \
99
${SPARK_VERSION}
1010

11+
echo "--- Stash XGBoost4J JARs (Scala 2.12)"
12+
buildkite-agent artifact upload "jvm-packages/xgboost4j/target/*.jar"
13+
buildkite-agent artifact upload "jvm-packages/xgboost4j-spark/target/*.jar"
14+
buildkite-agent artifact upload "jvm-packages/xgboost4j-flink/target/*.jar"
15+
buildkite-agent artifact upload "jvm-packages/xgboost4j-example/target/*.jar"
1116

1217
echo "--- Build XGBoost JVM packages scala 2.13"
1318

1419
tests/ci_build/ci_build.sh jvm docker tests/ci_build/build_jvm_packages.sh \
1520
${SPARK_VERSION} "" "" "true"
1621

17-
echo "--- Stash XGBoost4J JARs"
22+
echo "--- Stash XGBoost4J JARs (Scala 2.13)"
1823
buildkite-agent artifact upload "jvm-packages/xgboost4j/target/*.jar"
1924
buildkite-agent artifact upload "jvm-packages/xgboost4j-spark/target/*.jar"
2025
buildkite-agent artifact upload "jvm-packages/xgboost4j-flink/target/*.jar"

tests/ci_build/build_jvm_packages.sh

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ fi
2727
mvn_profile_string=""
2828
if [ "x$use_scala213" != "x" ]; then
2929
export mvn_profile_string="-Pdefault,scala-2.13"
30+
cd ..
31+
python dev/change_scala_version.py --scala-version 2.13 --purge-artifacts
32+
cd jvm-packages
3033
fi
3134

3235
mvn --no-transfer-progress package $mvn_profile_string -Dspark.version=${spark_version} $gpu_options

tests/ci_build/deploy_jvm_packages.sh

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ rm -rf ../build/
2727
# Deploy to S3 bucket xgboost-maven-repo
2828
mvn --no-transfer-progress package deploy -P default,gpu,release-to-s3 -Dspark.version=${spark_version} -DskipTests
2929
# Deploy scala 2.13 to S3 bucket xgboost-maven-repo
30+
cd ..
31+
python dev/change_scala_version.py --scala-version 2.13 --purge-artifacts
32+
cd jvm-packages/
3033
mvn --no-transfer-progress package deploy -P release-to-s3,default,scala-2.13 -Dspark.version=${spark_version} -DskipTests
3134

3235

tests/ci_build/test_jvm_cross.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ if [ ! -z "$RUN_INTEGRATION_TEST" ]; then
2121
fi
2222

2323
# including maven profiles for different scala versions: 2.12 is the default at the moment.
24-
for _maven_profile_string in "" "-Pdefault,scala-2.13"; do
24+
for scala_binary_version in "2.12" "2.13"; do
25+
cd ..
26+
python dev/change_scala_version.py --scala-version ${scala_binary_version}
27+
cd jvm-packages
2528
scala_version=$(mvn help:evaluate $_maven_profile_string -Dexpression=scala.version -q -DforceStdout)
26-
scala_binary_version=$(mvn help:evaluate $_maven_profile_string -Dexpression=scala.binary.version -q -DforceStdout)
29+
if [[ "$scala_binary_version" == "2.12" ]]; then
30+
_maven_profile_string=""
31+
elif [[ "$scala_binary_version" == "2.13" ]]; then
32+
_maven_profile_string="-Pdefault,scala-2.13"
33+
else
34+
echo "Unexpected scala version: $scala_version ($scala_binary_version)."
35+
fi
2736

2837
# Install XGBoost4J JAR into local Maven repository
2938
mvn --no-transfer-progress install:install-file -Dfile=./xgboost4j/target/xgboost4j_${scala_binary_version}-${xgboost4j_version}.jar -DgroupId=ml.dmlc -DartifactId=xgboost4j_${scala_binary_version} -Dversion=${xgboost4j_version} -Dpackaging=jar

0 commit comments

Comments
 (0)