Skip to content

Commit 4f05f71

Browse files
Merge branch 'main' into release-3.4.3
2 parents 0b2b55d + 7662217 commit 4f05f71

12 files changed

+261
-10
lines changed

template/v2/dirs/etc/patches/apply_patches.sh

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,79 @@
22

33
set -eux
44

5+
# Function to compare version numbers
6+
# Returns 0 if version1 >= version2, 1 otherwise
7+
version_gte() {
8+
local version1="$1"
9+
local version2="$2"
10+
11+
# Handle empty versions
12+
[ -z "$version1" ] && return 1
13+
[ -z "$version2" ] && return 0
14+
15+
# If versions are identical, return true
16+
[ "$version1" = "$version2" ] && return 0
17+
18+
# Use sort -V (version sort) to compare versions
19+
# Check if version1 comes after version2 in version sort
20+
local sorted=$(printf '%s\n%s\n' "$version1" "$version2" | sort -V)
21+
local first_line=$(echo "$sorted" | head -n1)
22+
23+
# If version2 comes first in sort, then version1 >= version2
24+
[ "$first_line" = "$version2" ]
25+
}
26+
27+
get_package_version() {
28+
local package_name="$1"
29+
30+
# Try to get version using pip show
31+
local pkg_version=$(pip show "$package_name" 2>/dev/null | grep "Version:" | cut -d' ' -f2)
32+
33+
if [ -z "$pkg_version" ]; then
34+
# Try using conda list as fallback
35+
pkg_version=$(conda list "$package_name" 2>/dev/null | grep "^$package_name " | awk '{print $2}' | head -n1)
36+
fi
37+
38+
echo "$pkg_version"
39+
}
40+
41+
# NOTE: Consider removing these patches entirely if all non-deprecating SMD versions
42+
# have package versions larger than the specified thresholds, as the patches would
43+
# no longer be needed.
44+
should_skip_patch() {
45+
local patch_file="$1"
46+
local patch_basename=$(basename "$patch_file")
47+
48+
# Check if patch filename contains "fix-ipython-display"
49+
if [[ "$patch_basename" == *"fix-ipython-display"* ]]; then
50+
# Skip this patch if hdijupyterutils >= 0.23.0
51+
local hdijupyterutils_version=$(get_package_version "hdijupyterutils")
52+
if [ -n "$hdijupyterutils_version" ]; then
53+
if version_gte "$hdijupyterutils_version" "0.23.0"; then
54+
echo "Skipping $patch_basename: hdijupyterutils version $hdijupyterutils_version >= 0.23"
55+
return 0
56+
fi
57+
fi
58+
fi
59+
60+
# Check if patch filename contains "fix-boto3-endpoints"
61+
if [[ "$patch_basename" == *"fix-boto3-endpoints"* ]]; then
62+
# Skip this patch if botocore >= 1.37.17
63+
local botocore_version=$(get_package_version "botocore")
64+
if [ -n "$botocore_version" ]; then
65+
if version_gte "$botocore_version" "1.37.17"; then
66+
echo "Skipping $patch_basename: botocore version $botocore_version >= 1.37.17"
67+
return 0
68+
fi
69+
fi
70+
fi
71+
72+
return 1
73+
}
74+
575
# Check if parameter is provided
676
if [ $# -ne 1 ]; then
7-
echo "Usage: $0 [smus|studio-ai]"
77+
echo "Usage: $0 [smus|smus-code-editor]"
878
exit 1
979
fi
1080

@@ -14,11 +84,11 @@ case "$1" in
1484
bash "/etc/patches/smus-script/replace-job-with-schedule.sh"
1585
PATCH_DIR="/etc/patches/smus"
1686
;;
17-
"studio-ai")
18-
PATCH_DIR="/etc/patches/studio-ai"
87+
"smus-code-editor")
88+
PATCH_DIR="/etc/patches/smus-code-editor"
1989
;;
2090
*)
21-
echo "Error: Parameter must be either 'smus' or 'studio-ai'"
91+
echo "Error: Parameter must be either 'smus' or 'smus-code-editor'"
2292
exit 1
2393
;;
2494
esac
@@ -33,6 +103,12 @@ fi
33103
# See https://www.thegeekstuff.com/2014/12/patch-command-examples/
34104
for PATCHFILE in "$PATCH_DIR"/*.patch; do
35105
[ -f "$PATCHFILE" ] || continue
106+
107+
# Check if this patch should be skipped due to version constraints
108+
if should_skip_patch "$PATCHFILE"; then
109+
continue
110+
fi
111+
36112
echo "Applying $PATCHFILE"
37113
(cd "/opt/conda" && patch --strip=3 < "$PATCHFILE")
38114
done
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- /opt/conda/lib/python3.11/site-packages/sparkmagic/livyclientlib/command.py
2+
+++ /opt/conda/lib/python3.11/site-packages/sparkmagic/livyclientlib/command.py
3+
@@ -54,6 +54,7 @@
4+
try:
5+
session.wait_for_idle()
6+
data = {"code": self.code}
7+
+ data["kind"] = session.kind
8+
response = session.http_client.post_statement(session.id, data)
9+
statement_id = response["id"]
10+
output = self._get_statement_output(session, statement_id)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--- /opt/conda/lib/python3.11/site-packages/sparkmagic/utils/utils.py
2+
+++ /opt/conda/lib/python3.11/site-packages/sparkmagic/utils/utils.py
3+
@@ -94,15 +94,7 @@
4+
5+
6+
def get_sessions_info_html(info_sessions, current_session_id):
7+
- html = (
8+
- """<table>
9+
-<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>User</th><th>Current session?</th></tr>"""
10+
- + "".join(
11+
- [session.get_row_html(current_session_id) for session in info_sessions]
12+
- )
13+
- + "</table>"
14+
- )
15+
-
16+
+ html = ""
17+
return html
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--- /opt/conda/lib/python3.11/site-packages/hdijupyterutils/ipythondisplay.py
2+
+++ /opt/conda/lib/python3.11/site-packages/hdijupyterutils/ipythondisplay.py
3+
@@ -1,4 +1,4 @@
4+
-from IPython.core.display import display, HTML
5+
+from IPython.display import display, HTML
6+
from IPython import get_ipython
7+
import sys
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- /opt/conda/lib/python3.11/site-packages/botocore/data/endpoints.json
2+
+++ /opt/conda/lib/python3.11/site-packages/botocore/data/endpoints.json
3+
@@ -5404,6 +5404,9 @@
4+
"ap-northeast-3" : {
5+
"hostname" : "datazone.ap-northeast-3.api.aws"
6+
},
7+
+ "ap-south-1" : {
8+
+ "hostname" : "datazone.ap-south-1.api.aws"
9+
+ },
10+
"ap-south-2" : {
11+
"hostname" : "datazone.ap-south-2.api.aws"
12+
},

template/v2/dirs/usr/local/bin/entrypoint-sagemaker-ui-code-editor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ set -e
66
# micromamba commands (e.g. using `micromamba activate` to activate environments)
77
eval "$(micromamba shell hook --shell=bash)"
88

9+
# apply patches for SMUS
10+
/etc/patches/apply_patches.sh smus-code-editor && sudo rm -rf /etc/patches
11+
912
# Activate conda environment 'base', where supervisord is installed
1013
micromamba activate base
1114

1215
export SAGEMAKER_APP_TYPE_LOWERCASE=$(echo $SAGEMAKER_APP_TYPE | tr '[:upper:]' '[:lower:]')
1316
export SERVICE_NAME='SageMakerUnifiedStudio'
1417

1518
mkdir -p $STUDIO_LOGGING_DIR/$SAGEMAKER_APP_TYPE_LOWERCASE/supervisord
16-
exec supervisord -c /etc/supervisor/conf.d/supervisord-sagemaker-ui-code-editor.conf -n
19+
exec supervisord -c /etc/supervisor/conf.d/supervisord-sagemaker-ui-code-editor.conf -n

template/v3/dirs/etc/patches/apply_patches.sh

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,79 @@
22

33
set -eux
44

5+
# Function to compare version numbers
6+
# Returns 0 if version1 >= version2, 1 otherwise
7+
version_gte() {
8+
local version1="$1"
9+
local version2="$2"
10+
11+
# Handle empty versions
12+
[ -z "$version1" ] && return 1
13+
[ -z "$version2" ] && return 0
14+
15+
# If versions are identical, return true
16+
[ "$version1" = "$version2" ] && return 0
17+
18+
# Use sort -V (version sort) to compare versions
19+
# Check if version1 comes after version2 in version sort
20+
local sorted=$(printf '%s\n%s\n' "$version1" "$version2" | sort -V)
21+
local first_line=$(echo "$sorted" | head -n1)
22+
23+
# If version2 comes first in sort, then version1 >= version2
24+
[ "$first_line" = "$version2" ]
25+
}
26+
27+
get_package_version() {
28+
local package_name="$1"
29+
30+
# Try to get version using pip show
31+
local pkg_version=$(pip show "$package_name" 2>/dev/null | grep "Version:" | cut -d' ' -f2)
32+
33+
if [ -z "$pkg_version" ]; then
34+
# Try using conda list as fallback
35+
pkg_version=$(conda list "$package_name" 2>/dev/null | grep "^$package_name " | awk '{print $2}' | head -n1)
36+
fi
37+
38+
echo "$pkg_version"
39+
}
40+
41+
# NOTE: Consider removing these patches entirely if all non-deprecating SMD versions
42+
# have package versions larger than the specified thresholds, as the patches would
43+
# no longer be needed.
44+
should_skip_patch() {
45+
local patch_file="$1"
46+
local patch_basename=$(basename "$patch_file")
47+
48+
# Check if patch filename contains "fix-ipython-display"
49+
if [[ "$patch_basename" == *"fix-ipython-display"* ]]; then
50+
# Skip this patch if hdijupyterutils >= 0.23.0
51+
local hdijupyterutils_version=$(get_package_version "hdijupyterutils")
52+
if [ -n "$hdijupyterutils_version" ]; then
53+
if version_gte "$hdijupyterutils_version" "0.23.0"; then
54+
echo "Skipping $patch_basename: hdijupyterutils version $hdijupyterutils_version >= 0.23"
55+
return 0
56+
fi
57+
fi
58+
fi
59+
60+
# Check if patch filename contains "fix-boto3-endpoints"
61+
if [[ "$patch_basename" == *"fix-boto3-endpoints"* ]]; then
62+
# Skip this patch if botocore >= 1.37.17
63+
local botocore_version=$(get_package_version "botocore")
64+
if [ -n "$botocore_version" ]; then
65+
if version_gte "$botocore_version" "1.37.17"; then
66+
echo "Skipping $patch_basename: botocore version $botocore_version >= 1.37.17"
67+
return 0
68+
fi
69+
fi
70+
fi
71+
72+
return 1
73+
}
74+
575
# Check if parameter is provided
676
if [ $# -ne 1 ]; then
7-
echo "Usage: $0 [smus|studio-ai]"
77+
echo "Usage: $0 [smus|smus-code-editor]"
878
exit 1
979
fi
1080

@@ -14,11 +84,11 @@ case "$1" in
1484
bash "/etc/patches/smus-script/replace-job-with-schedule.sh"
1585
PATCH_DIR="/etc/patches/smus"
1686
;;
17-
"studio-ai")
18-
PATCH_DIR="/etc/patches/studio-ai"
87+
"smus-code-editor")
88+
PATCH_DIR="/etc/patches/smus-code-editor"
1989
;;
2090
*)
21-
echo "Error: Parameter must be either 'smus' or 'studio-ai'"
91+
echo "Error: Parameter must be either 'smus' or 'smus-code-editor'"
2292
exit 1
2393
;;
2494
esac
@@ -33,6 +103,12 @@ fi
33103
# See https://www.thegeekstuff.com/2014/12/patch-command-examples/
34104
for PATCHFILE in "$PATCH_DIR"/*.patch; do
35105
[ -f "$PATCHFILE" ] || continue
106+
107+
# Check if this patch should be skipped due to version constraints
108+
if should_skip_patch "$PATCHFILE"; then
109+
continue
110+
fi
111+
36112
echo "Applying $PATCHFILE"
37113
(cd "/opt/conda" && patch --strip=3 < "$PATCHFILE")
38114
done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- /opt/conda/lib/python3.12/site-packages/sparkmagic/livyclientlib/command.py
2+
+++ /opt/conda/lib/python3.12/site-packages/sparkmagic/livyclientlib/command.py
3+
@@ -54,6 +54,7 @@
4+
try:
5+
session.wait_for_idle()
6+
data = {"code": self.code}
7+
+ data["kind"] = session.kind
8+
response = session.http_client.post_statement(session.id, data)
9+
statement_id = response["id"]
10+
output = self._get_statement_output(session, statement_id)
11+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--- /opt/conda/lib/python3.12/site-packages/sparkmagic/utils/utils.py
2+
+++ /opt/conda/lib/python3.12/site-packages/sparkmagic/utils/utils.py
3+
@@ -94,15 +94,7 @@
4+
5+
6+
def get_sessions_info_html(info_sessions, current_session_id):
7+
- html = (
8+
- """<table>
9+
-<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>User</th><th>Current session?</th></tr>"""
10+
- + "".join(
11+
- [session.get_row_html(current_session_id) for session in info_sessions]
12+
- )
13+
- + "</table>"
14+
- )
15+
-
16+
+ html = ""
17+
return html
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--- /opt/conda/lib/python3.12/site-packages/hdijupyterutils/ipythondisplay.py
2+
+++ /opt/conda/lib/python3.12/site-packages/hdijupyterutils/ipythondisplay.py
3+
@@ -1,4 +1,4 @@
4+
-from IPython.core.display import display, HTML
5+
+from IPython.display import display, HTML
6+
from IPython import get_ipython
7+
import sys

0 commit comments

Comments
 (0)