From b59afb9121dbf7bec8163b5f39b447122dc6c7f7 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sat, 26 Nov 2022 12:51:19 +0100 Subject: [PATCH 1/9] Add script to downstream PRs from aesara. --- bin/downstream_pr.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bin/downstream_pr.sh diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh new file mode 100644 index 0000000000..b809348fdb --- /dev/null +++ b/bin/downstream_pr.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +if [ -z "$1" ] + then + echo "Usage: downstream_pr.sh " + echo "Will create a new branch, apply changes, and create a new PR" + exit 1 +fi + +set -e + +git checkout main +git pull origin main +git checkout -b downstream_$1 + +echo "Downloading patch..." +wget -O $1.patch https://patch-diff.githubusercontent.com/raw/aesara-devs/aesara/pull/$1.patch + +echo "Replacing aesara strings..." +declare -a replace_strings=( + "s/aesara/pytensor/g" + "s/Aesara/PyTensor/g" +# "s/import pytensor.tensor as at/import pytensor.tensor as pt/g" + "s/at\./pt./g" +# "s/from pytensor import tensor as pt/from pytensor import tensor as pt/g" +) + +for replace in "${replace_strings[@]}"; do + find . -name "*$1.patch" -type f -exec sed -i -e "/png/!$replace" {} \; +done + +echo "Applying patch..." +git am -3 --reject $1.patch + +echo "Running pre-commit" +pre-commit run --all + +git push origin downstream_$1 + +gh pr create --repo pymc-devs/pytensor --title "Downstreaming $1" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1" From bc1e689cfafbd3973e3968cf8422032d362bd546 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sat, 26 Nov 2022 13:54:39 +0100 Subject: [PATCH 2/9] Do not replace at -> pt. --- bin/downstream_pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index b809348fdb..61a2483c6f 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -21,7 +21,7 @@ declare -a replace_strings=( "s/aesara/pytensor/g" "s/Aesara/PyTensor/g" # "s/import pytensor.tensor as at/import pytensor.tensor as pt/g" - "s/at\./pt./g" +# "s/at\./pt./g" # "s/from pytensor import tensor as pt/from pytensor import tensor as pt/g" ) From 14d912ee8270cb8aab1d331f86400ebe9d11fdb6 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 12:32:14 +0100 Subject: [PATCH 3/9] Add better description, simplify sed statement. Add instructions to fix patch if it fails. --- bin/downstream_pr.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index 61a2483c6f..764f9b3ea9 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -3,7 +3,7 @@ if [ -z "$1" ] then echo "Usage: downstream_pr.sh " - echo "Will create a new branch, apply changes, and create a new PR" + echo "Port a specified PR from the Aesara repo to the PyTensor repo. Will create a new branch, adapt and apply the upstream PR, and create a new PR to PyTensor." exit 1 fi @@ -26,11 +26,15 @@ declare -a replace_strings=( ) for replace in "${replace_strings[@]}"; do - find . -name "*$1.patch" -type f -exec sed -i -e "/png/!$replace" {} \; + sed -i -e "$replace" *$1.patch done echo "Applying patch..." -git am -3 --reject $1.patch +if git am -3 --reject $1.patch ; then + echo "Patch applied successfully..." +else + echo "Patch failed. Find the .rej file and apply the changes manually. Then 'git add' all changed files, followed by 'git am --continue'. Then, create a PR manually." +fi echo "Running pre-commit" pre-commit run --all From ba3bbc81500ca422f014c478b0002415f76c35c8 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 12:34:12 +0100 Subject: [PATCH 4/9] Exit upon error. --- bin/downstream_pr.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index 764f9b3ea9..3d194a820f 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -31,9 +31,10 @@ done echo "Applying patch..." if git am -3 --reject $1.patch ; then - echo "Patch applied successfully..." + echo "Patch applied successfully..." else - echo "Patch failed. Find the .rej file and apply the changes manually. Then 'git add' all changed files, followed by 'git am --continue'. Then, create a PR manually." + echo "Patch failed. Find the .rej file and apply the changes manually. Then 'git add' all changed files, followed by 'git am --continue'. Then create a PR manually." + exit 1 fi echo "Running pre-commit" From 90f2ecb251a75799eba3ad6724291774605f1d62 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 12:35:26 +0100 Subject: [PATCH 5/9] Better PR description. --- bin/downstream_pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index 3d194a820f..8fdfc8d9eb 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -42,4 +42,4 @@ pre-commit run --all git push origin downstream_$1 -gh pr create --repo pymc-devs/pytensor --title "Downstreaming $1" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1" +gh pr create --repo pymc-devs/pytensor --title "Downstreaming Aesara PR $1" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1. PR port done by downstream_pr.sh script." From 0dfa57a2d060090bb8f5d36b720bee670daaf02f Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 12:36:59 +0100 Subject: [PATCH 6/9] Typo --- bin/downstream_pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index 8fdfc8d9eb..c3ca6ffc56 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -26,7 +26,7 @@ declare -a replace_strings=( ) for replace in "${replace_strings[@]}"; do - sed -i -e "$replace" *$1.patch + sed -i -e "$replace" $1.patch done echo "Applying patch..." From eab8ad9931c942ed5004a84e2b519a9ed9e81adc Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 12:37:23 +0100 Subject: [PATCH 7/9] Remove commented lines. --- bin/downstream_pr.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index c3ca6ffc56..a9fc56caee 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -20,9 +20,6 @@ echo "Replacing aesara strings..." declare -a replace_strings=( "s/aesara/pytensor/g" "s/Aesara/PyTensor/g" -# "s/import pytensor.tensor as at/import pytensor.tensor as pt/g" -# "s/at\./pt./g" -# "s/from pytensor import tensor as pt/from pytensor import tensor as pt/g" ) for replace in "${replace_strings[@]}"; do From 6dd76e2190845b7d89bddac6a7d9a69ac5d779a8 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 22:20:23 +0100 Subject: [PATCH 8/9] Update bin/downstream_pr.sh Co-authored-by: Maxim Kochurov --- bin/downstream_pr.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index a9fc56caee..549c83562c 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -38,5 +38,6 @@ echo "Running pre-commit" pre-commit run --all git push origin downstream_$1 - +# get the informative title +title=$(curl https://api.github.com/repos/aesara-devs/aesara/pulls/$1 2>/dev/null | jq '.title') gh pr create --repo pymc-devs/pytensor --title "Downstreaming Aesara PR $1" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1. PR port done by downstream_pr.sh script." From b2fbbfefd5715c052934f0d467a2efbcc9508645 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Sun, 27 Nov 2022 22:20:32 +0100 Subject: [PATCH 9/9] Update bin/downstream_pr.sh Co-authored-by: Maxim Kochurov --- bin/downstream_pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/downstream_pr.sh b/bin/downstream_pr.sh index 549c83562c..f610cd0b82 100644 --- a/bin/downstream_pr.sh +++ b/bin/downstream_pr.sh @@ -40,4 +40,4 @@ pre-commit run --all git push origin downstream_$1 # get the informative title title=$(curl https://api.github.com/repos/aesara-devs/aesara/pulls/$1 2>/dev/null | jq '.title') -gh pr create --repo pymc-devs/pytensor --title "Downstreaming Aesara PR $1" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1. PR port done by downstream_pr.sh script." +gh pr create --repo pymc-devs/pytensor --title "Downstreaming Aesara PR $1: $title" --body "Downstreaming https://github.com/aesara-devs/aesara/pull/$1. PR port done by downstream_pr.sh script."