Skip to content

Commit a8a3b7c

Browse files
Merge pull request #459 from puneetmatharu/remove-sudo-commands-from-pytorch-build-scripts
Remove `sudo` commands from PyTorch build script
2 parents 670ef64 + de2e11f commit a8a3b7c

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

ML-Frameworks/pytorch-aarch64/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ where `YY` is the year, and `MM` the month of the increment.
4141
- Removes PRs that have already been merged.
4242

4343
### Fixed
44+
- Disables `sudo` commands in PyTorch scripts used to build wheel.
4445
- Constrains `pytest` to the 8.4 series to keep PyTorch's copied unit tests compatible with pytest hook deprecation handling.
4546

4647
## [r26.04] 2026-04-10

ML-Frameworks/pytorch-aarch64/get-source.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ git-shallow-clone https://github.com/pytorch/pytorch.git $PYTORCH_HASH
4949
if [[ "$source_variant" != patched ]]; then
5050
echo "Not applying extra patches to PyTorch build for source variant '$source_variant'"
5151
else
52+
# Disable the sudo commands in the manywheel build which restart the Docker daemon
53+
replace_once .ci/docker/manywheel/build.sh \
54+
'if [ "$(uname -m)" != "s390x" ] && [ -v CI ]; then' \
55+
'if false; then'
56+
git add .ci/docker/manywheel/build.sh
57+
git-with-credentials commit -m "Disable sudo commands in manywheel build"
58+
5259
# https://github.com/pytorch/pytorch/pull/182655 - Update ACL/OpenBLAS/manywheel build scripts and add ccache support
5360
apply-github-patch pytorch/pytorch 159406ab7f210bacadb757fabef28ac9ddacb706
5461

ML-Frameworks/utils/git-utils.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ patch_cache_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/patch_cache"
1111
mkdir -p "$patch_cache_dir"
1212
export patch_cache_dir
1313

14+
function git-with-credentials() {
15+
git -c user.name="apply-github-patch" \
16+
-c user.email="noreply@example.com" \
17+
-c commit.gpgsign="false" \
18+
"$@"
19+
}
20+
1421
function git-shallow-clone {
1522
(
1623
local repo_name=$(basename "$1" .git)
@@ -51,16 +58,9 @@ function apply-github-patch {
5158
fi
5259
fi
5360

54-
_git_with_credentials() {
55-
git -c user.name="apply-github-patch" \
56-
-c user.email="noreply@example.com" \
57-
-c commit.gpgsign="false" \
58-
"$@"
59-
}
60-
6161
# Approach #1: Try a simple patch application with 'git am'
62-
_git_with_credentials am --keep-cr "$patch_file" && return 0
63-
_git_with_credentials am --abort || true # wokeignore:rule=abort/terminate
62+
git-with-credentials am --keep-cr "$patch_file" && return 0
63+
git-with-credentials am --abort || true # wokeignore:rule=abort/terminate
6464

6565
# Approach #2: Try a three-way merge after fetching the parent commit. It can handle
6666
# scenarios in which the context of the patch has moved. However, we need the parent
@@ -70,12 +70,25 @@ function apply-github-patch {
7070
fetch_url="https://x-access-token:${GITHUB_TOKEN}@github.com/$1.git"
7171
fi
7272
git fetch --no-tags --quiet --depth=2 "$fetch_url" "$2" || true
73-
_git_with_credentials am --3way --keep-cr "$patch_file" && return 0
74-
_git_with_credentials am --abort || true # wokeignore:rule=abort/terminate
73+
git-with-credentials am --3way --keep-cr "$patch_file" && return 0
74+
git-with-credentials am --abort || true # wokeignore:rule=abort/terminate
7575

7676
# Approach #3: Fall back to GNU 'patch'
7777
patch -p1 < "$patch_file" || return 1
7878
git add -A
79-
_git_with_credentials commit -m "Applied patch $2 from $1."
79+
git-with-credentials commit -m "Applied patch $2 from $1."
8080
return 0
8181
}
82+
83+
function replace_once() {
84+
python3 - "$@" <<'PY'
85+
import sys
86+
from pathlib import Path
87+
88+
path, old, new = Path(sys.argv[1]), sys.argv[2], sys.argv[3]
89+
text = path.read_text(encoding="utf-8")
90+
if old not in text:
91+
raise SystemExit(f"{path}: expected text not found: {old!r}")
92+
path.write_text(text.replace(old, new, 1), encoding="utf-8")
93+
PY
94+
}

0 commit comments

Comments
 (0)