From 440ff34f047bdde6b3760b4ed575a1c98db5619e Mon Sep 17 00:00:00 2001
From: Amir Mohammadi <183.amir@gmail.com>
Date: Fri, 21 Oct 2016 17:42:11 +0200
Subject: [PATCH] Add conda-forge deploy script

---
 conda/batch-update-bob.sh             |  2 +-
 gitlab/deploy.sh                      | 36 +++++++++++++++++++++++++++
 gitlab/functions.sh                   |  7 ++++++
 gitlab/install.sh                     |  1 +
 {conda => gitlab}/update_feedstock.py | 16 +++++++++---
 install/install-conda.sh              |  5 ++++
 6 files changed, 63 insertions(+), 4 deletions(-)
 rename {conda => gitlab}/update_feedstock.py (91%)

diff --git a/conda/batch-update-bob.sh b/conda/batch-update-bob.sh
index 6a2261a..4a40d29 100755
--- a/conda/batch-update-bob.sh
+++ b/conda/batch-update-bob.sh
@@ -33,5 +33,5 @@ esac
 for pkg in "${packages[@]}"
 do
 	gh re --fork $pkg-feedstock --user conda-forge --organization bioidiap || true
-	python update_feedstock.py $pkg
+	python ../gitlab/update_feedstock.py $pkg
 done
diff --git a/gitlab/deploy.sh b/gitlab/deploy.sh
index 9ad085c..009d951 100755
--- a/gitlab/deploy.sh
+++ b/gitlab/deploy.sh
@@ -20,3 +20,39 @@ if [ -d sphinx ]; then
 fi
 
 unlock_pypirc
+
+condaforge_packages=("bob.extension" \
+"bob.blitz" \
+"bob.core" \
+"bob.ip.draw" \
+"bob.io.base" \
+"bob.sp" \
+"bob.math" \
+"bob.ap" \
+"bob.measure" \
+"bob.db.base" \
+"bob.io.image" \
+"bob.io.video" \
+"bob.io.matlab" \
+"bob.ip.base" \
+"bob.ip.color" \
+"bob.ip.gabor" \
+"bob.learn.activation" \
+"bob.learn.libsvm" \
+"bob.learn.boosting" \
+"bob.io.audio" \
+"bob.learn.linear" \
+"bob.learn.mlp" \
+"bob.db.wine" \
+"bob.db.mnist" \
+"bob.db.atnt" \
+"bob.ip.flandmark" \
+"bob.ip.facedetect" \
+"bob.ip.optflow.hornschunck" \
+"bob.ip.optflow.liu" \
+"bob.learn.em" \
+"bob.db.iris")
+
+if contains_element ${CI_PROJECT_NAME}  "${condaforge_packages[@]}"; then
+  run_cmd ${CONDA_FOLDER}/bin/python _ci/update_feedstock.py ${CI_PROJECT_NAME} --no-gui
+fi
diff --git a/gitlab/functions.sh b/gitlab/functions.sh
index ea4640d..e82893c 100644
--- a/gitlab/functions.sh
+++ b/gitlab/functions.sh
@@ -246,3 +246,10 @@ if [ -z "${CI_BUILD_TAG}" ]; then
 else
   log_info "Building tag, not setting BOB_DOCUMENTATION_SERVER"
 fi
+
+# taken from here: https://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value
+contains_element () {
+  local e
+  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
+  return 1
+}
diff --git a/gitlab/install.sh b/gitlab/install.sh
index 07c0cb5..8adb34b 100755
--- a/gitlab/install.sh
+++ b/gitlab/install.sh
@@ -57,3 +57,4 @@ for stage in "build" "test" "docs" "wheels" "deploy"; do
   get_exec ${1} ${stage}.sh
   get_exec ${1} after_${stage}.sh
 done
+get_exec ${1} update_feedstock.py
diff --git a/conda/update_feedstock.py b/gitlab/update_feedstock.py
similarity index 91%
rename from conda/update_feedstock.py
rename to gitlab/update_feedstock.py
index 1357ba3..a220e9d 100755
--- a/conda/update_feedstock.py
+++ b/gitlab/update_feedstock.py
@@ -64,7 +64,7 @@ def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024):
   return hash.hexdigest()
 
 
-def main(package):
+def main(package, gui=True):
   stable_version = get_version(package)
   print('latest stable version for {} is {}'.format(package, stable_version))
   url = 'https://pypi.io/packages/source/{0}/{1}/{1}-{2}.zip'.format(package[0], package, stable_version)
@@ -100,12 +100,17 @@ def main(package):
     doc = re.sub(r'\s+home\:.*', '\n  home: https://www.idiap.ch/software/bob/', doc, count=1)
     with open('recipe/meta.yaml', 'w') as f:
       f.write(doc)
+    if gui:
+      browse = '--browse'
+    else:
+      browse = ''
+
     run_commands(['conda-smithy', 'rerender'],
                  ['git', '--no-pager', 'diff'],
                  ['git', 'add', '-A'],
                  ['git', 'commit', '-am', 'Update to version {}'.format(stable_version)],
                  ['git', 'push', '--force', '--set-upstream', 'bioidiap', stable_version],
-                 ['hub', 'pull-request', '--browse', '-b', 'conda-forge:master', '-h', 'bioidiap:{}'.format(stable_version), '-m', 'Update to version {}'.format(stable_version)])
+                 ['hub', 'pull-request', browse, '-b', 'conda-forge:master', '-h', 'bioidiap:{}'.format(stable_version), '-m', 'Update to version {}'.format(stable_version)])
     print('\nPlease create the pull request in the webpage that was openned.')
   finally:
     shutil.rmtree(temp_dir)
@@ -113,4 +118,9 @@ def main(package):
 
 if __name__ == '__main__':
   import sys
-  main(*sys.argv[1:])
+  pkg = sys.argv[1]
+  if len(sys.argv) > 2:
+    gui = False
+  else:
+    gui = True
+  main(pkg, gui)
diff --git a/install/install-conda.sh b/install/install-conda.sh
index 80d6fb0..f87a793 100755
--- a/install/install-conda.sh
+++ b/install/install-conda.sh
@@ -34,3 +34,8 @@ fi
 
 echo "[>>] Updating conda in the root environment..."
 ${CONDA} update --yes -n root conda
+
+echo "[>>] Installing conda-smithy..."
+${CONDA} install --yes -n root conda-smithy
+
+echo "You need to manually install https://hub.github.com/ too ..."
-- 
GitLab