From 863775e41177c8c20d57ce10f419739683649935 Mon Sep 17 00:00:00 2001
From: Amir MOHAMMADI <amir.mohammadi@idiap.ch>
Date: Wed, 27 Sep 2017 15:41:30 +0200
Subject: [PATCH] Migrate to conda based CI

---
 .gitlab-ci.yml  | 344 ++++++++++++++++--------------------------------
 conda/meta.yaml |  64 +++++++++
 doc/conf.py     |   8 +-
 3 files changed, 180 insertions(+), 236 deletions(-)
 create mode 100644 conda/meta.yaml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b0fba4d..3114816 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,275 +1,161 @@
-# This build file heavily uses template features from YAML so it is generic
-# enough for any Bob project. Don't modify it unless you know what you're
-# doing.
+# This build file uses template features from YAML so it is generic enough for
+# any Bob project. Don't modify it unless you know what you're doing.
 
+# global variables
+variables:
+  CONDA_ENVS_PATH: "conda-env"
+  CONDA_BLD_PATH: "conda-env"
 
-# Definition of our build pipeline
+
+# Definition of our build pipeline order
 stages:
   - build
-  - test
-  - docs
-  - wheels
   - deploy
+  - pypi
 
 
-# ---------
-# Templates
-# ---------
-
-# Template for the build stage
-# Needs to run on all supported architectures, platforms and python versions
+# Build targets
 .build_template: &build_job
   stage: build
   before_script:
-    - git clean -ffdx
+    - export PATH=$CONDA_FOLDER/bin:$PATH
     - mkdir _ci
-    - curl --silent "https://gitlab.idiap.ch/bob/bob.admin/raw/master/gitlab/install.sh" > _ci/install.sh
+    - curl https://curl.haxx.se/ca/cacert.pem > _ci/cacert.pem
+    - export CURL_CA_BUNDLE=`pwd`/_ci/cacert.pem
+    - export SSL_CERT_FILE=`pwd`/_ci/cacert.pem
+    - curl "https://gitlab.idiap.ch/bob/bob.admin/raw/condapackage/gitlab/install.sh" > _ci/install.sh
     - chmod 755 _ci/install.sh
-    - ./_ci/install.sh _ci #updates
-    - ./_ci/before_build.sh
+    - ./_ci/install.sh _ci condapackage
   script:
     - ./_ci/build.sh
-  after_script:
-    - ./_ci/after_build.sh
+
+.build_linux_template: &linux_build_job
+  <<: *build_job
   artifacts:
     expire_in: 1 week
     paths:
       - _ci/
-      - dist/
-      - sphinx/
-
-
-# Template for the test stage - re-installs from uploaded wheels
-# Needs to run on all supported architectures, platforms and python versions
-.test_template: &test_job
-  stage: test
-  before_script:
-    - ./_ci/install.sh _ci #updates
-    - ./_ci/before_test.sh
-  script:
-    - ./_ci/test.sh
-  after_script:
-    - ./_ci/after_test.sh
-
-
-# Template for the wheel uploading stage
-# Needs to run against all combinations of python and operating systems
-.wheels_template: &wheels_job
-  stage: wheels
-  environment: intranet
-  only:
-    - master
-    - /^v\d+\.\d+\.\d+([abc]\d*)?$/  # PEP-440 compliant version (tags)
-  before_script:
-    - ./_ci/install.sh _ci #updates
-    - ./_ci/before_wheels.sh
-  script:
-    - ./_ci/wheels.sh
-  after_script:
-    - ./_ci/after_wheels.sh
-
-
-# Template for (latest) documentation upload stage
-# Only one real job needs to do this
-.docs_template: &docs_job
-  stage: docs
-  environment: intranet
-  only:
-    - master
-  before_script:
-    - ./_ci/install.sh _ci #updates
-    - ./_ci/before_docs.sh
-  script:
-    - ./_ci/docs.sh
-  after_script:
-    - ./_ci/after_docs.sh
-
-
-# Template for the deployment stage - re-installs from uploaded wheels
-# Needs to run on a single architecture only
-# Will deploy your package to PyPI and other required services
-# Only runs for tags
-.deploy_template: &deploy_job
-  stage: deploy
-  environment: internet
-  only:
-    - /^v\d+\.\d+\.\d+([abc]\d*)?$/  # PEP-440 compliant version (tags)
-  except:
-    - branches
-  before_script:
-    - ./_ci/install.sh _ci #updates
-    - ./_ci/before_deploy.sh
-  script:
-    - ./_ci/deploy.sh
-  after_script:
-    - ./_ci/after_deploy.sh
-
-
-# -------------
-# Build Targets
-# -------------
+      - ${CONDA_ENVS_PATH}/linux-64/*.tar.bz2
+  tags:
+    - docker
+  image: continuumio/conda_builder_linux
+  variables: &linux_variables
+    CONDA_FOLDER: "/opt/miniconda"
+  cache:
+    key: "linux-cache"
+    paths:
+      - ${CONDA_ENVS_PATH}/.pkgs/*.tar.bz2
+      - ${CONDA_ENVS_PATH}/.pkgs/urls.txt
 
-# Linux + Python 2.7: Builds, tests, uploads wheel and deploys (if needed)
-build_linux_27:
+.build_macosx_template: &macosx_build_job
   <<: *build_job
-  variables: &linux_27_build_variables
-    PYTHON_VERSION: "2.7"
-  tags:
-    - conda-linux
-
-test_linux_27:
-  <<: *test_job
-  variables: *linux_27_build_variables
-  dependencies:
-    - build_linux_27
-  tags:
-    - conda-linux
-
-wheels_linux_27:
-  <<: *wheels_job
-  variables: *linux_27_build_variables
-  dependencies:
-    - build_linux_27
+  artifacts:
+    expire_in: 1 week
+    paths:
+      - _ci/
+      - ${CONDA_ENVS_PATH}/osx-64/*.tar.bz2
   tags:
-    - conda-linux
+    - macosx
+  variables: &macosx_variables
+    CONDA_FOLDER: "${CI_PROJECT_DIR}/${CONDA_ENVS_PATH}"
+  cache:
+    key: "macosx-cache"
+    paths:
+      - miniconda.sh
+      - ${CONDA_ENVS_PATH}/pkgs/*.tar.bz2
+      - ${CONDA_ENVS_PATH}/pkgs/urls.txt
 
-deploy_linux_27:
-  <<: *deploy_job
-  variables: *linux_27_build_variables
-  dependencies:
-    - build_linux_27
-  tags:
-    - conda-linux
 
+build_linux_27:
+  <<: *linux_build_job
+  variables:
+    <<: *linux_variables
+    PYTHON_VERSION: "2.7"
 
-# Linux + Python 3.5: Builds, tests and uploads wheel
 build_linux_35:
-  <<: *build_job
-  variables: &linux_35_build_variables
+  <<: *linux_build_job
+  variables:
+    <<: *linux_variables
     PYTHON_VERSION: "3.5"
-  tags:
-    - conda-linux
-
-test_linux_35:
-  <<: *test_job
-  variables: *linux_35_build_variables
-  dependencies:
-    - build_linux_35
-  tags:
-    - conda-linux
-
-wheels_linux_35:
-  <<: *wheels_job
-  variables: *linux_35_build_variables
-  dependencies:
-    - build_linux_35
-  tags:
-    - conda-linux
-
-docs_linux_35:
-  <<: *docs_job
-  variables: *linux_35_build_variables
-  dependencies:
-    - build_linux_35
-  tags:
-    - conda-linux
-
 
-# Linux + Python 3.6: Builds and tests
 build_linux_36:
-  <<: *build_job
-  variables: &linux_36_build_variables
+  <<: *linux_build_job
+  variables:
+    <<: *linux_variables
     PYTHON_VERSION: "3.6"
-  tags:
-    - conda-linux
-
-test_linux_36:
-  <<: *test_job
-  variables: *linux_36_build_variables
-  dependencies:
-    - build_linux_36
-  tags:
-    - conda-linux
-
-wheels_linux_36:
-  <<: *wheels_job
-  variables: *linux_36_build_variables
-  dependencies:
-    - build_linux_36
-  tags:
-    - conda-linux
-
+    BUILD_EGG: "true"
+  artifacts:
+    expire_in: 1 week
+    paths:
+      - _ci/
+      - dist/*.zip
+      - sphinx
+      - ${CONDA_ENVS_PATH}/linux-64/*.tar.bz2
 
-# Mac OSX + Python 2.7: Builds and tests
 build_macosx_27:
-  <<: *build_job
-  variables: &macosx_27_build_variables
+  <<: *macosx_build_job
+  variables:
+    <<: *macosx_variables
     PYTHON_VERSION: "2.7"
-  tags:
-    - conda-macosx
-
-test_macosx_27:
-  <<: *test_job
-  variables: *macosx_27_build_variables
-  dependencies:
-    - build_macosx_27
-  tags:
-    - conda-macosx
-
-wheels_macosx_27:
-  <<: *wheels_job
-  variables: *macosx_27_build_variables
-  dependencies:
-    - build_macosx_27
-  tags:
-    - conda-macosx
 
-
-# Mac OSX + Python 3.5: Builds and tests
 build_macosx_35:
-  <<: *build_job
-  variables: &macosx_35_build_variables
+  <<: *macosx_build_job
+  variables:
+    <<: *macosx_variables
     PYTHON_VERSION: "3.5"
-  tags:
-    - conda-macosx
 
-test_macosx_35:
-  <<: *test_job
-  variables: *macosx_35_build_variables
-  dependencies:
-    - build_macosx_35
-  tags:
-    - conda-macosx
+build_macosx_36:
+  <<: *macosx_build_job
+  variables:
+    <<: *macosx_variables
+    PYTHON_VERSION: "3.6"
 
-wheels_macosx_35:
-  <<: *wheels_job
-  variables: *macosx_35_build_variables
+
+# Deploy targets
+.deploy_template: &deploy_job
+  stage: deploy
+  before_script:
+    - ./_ci/install.sh _ci condapackage
+  script:
+    - ./_ci/deploy.sh
   dependencies:
+    - build_linux_27
+    - build_linux_35
+    - build_linux_36
+    - build_macosx_27
     - build_macosx_35
+    - build_macosx_36
   tags:
-    - conda-macosx
+    - deployer
 
+deploy_beta:
+  <<: *deploy_job
+  environment: beta
+  only:
+    - master
+    - condapackage
 
-# Mac OSX + Python 3.6: Builds and tests
-build_macosx_36:
-  <<: *build_job
-  variables: &macosx_36_build_variables
-    PYTHON_VERSION: "3.6"
-  tags:
-    - conda-macosx
+deploy_stable:
+  <<: *deploy_job
+  environment: stable
+  only:
+    - /^v\d+\.\d+\.\d+([abc]\d*)?$/  # PEP-440 compliant version (tags)
+  except:
+    - branches
 
-test_macosx_36:
-  <<: *test_job
-  variables: *macosx_36_build_variables
-  dependencies:
-    - build_macosx_36
-  tags:
-    - conda-macosx
 
-wheels_macosx_36:
-  <<: *wheels_job
-  variables: *macosx_36_build_variables
+pypi:
+  stage: pypi
+  environment: pypi
+  only:
+    - /^v\d+\.\d+\.\d+([abc]\d*)?$/  # PEP-440 compliant version (tags)
+  except:
+    - branches
+  before_script:
+    - ./_ci/install.sh _ci condapackage
+  script:
+    - ./_ci/pypi.sh
   dependencies:
-    - build_macosx_36
+    - build_linux_36
   tags:
-    - conda-macosx
+    - deployer
diff --git a/conda/meta.yaml b/conda/meta.yaml
new file mode 100644
index 0000000..9e233fa
--- /dev/null
+++ b/conda/meta.yaml
@@ -0,0 +1,64 @@
+{% set name = 'bob.learn.libsvm' %}
+{% set project_dir = environ.get('RECIPE_DIR') + '/..' %}
+
+package:
+  name: {{ name }}
+  version: {{ environ.get('BOB_PACKAGE_VERSION', '0.0.1') }}
+
+build:
+  number: {{ environ.get('BOB_BUILD_NUMBER', 0) }}
+  script:
+    - cd {{ project_dir }}
+    {% if environ.get('BUILD_EGG') %}
+    - python setup.py sdist --formats=zip
+    {% endif %}
+    - pip install --verbose .
+
+requirements:
+  build:
+    - python {{ python }}
+    - setuptools {{ setuptools }}
+    - toolchain {{ toolchain }}
+    - bob.extension
+    - bob.blitz
+    - bob.core
+    - bob.io.base
+    - libblitz {{ libblitz }}
+    - libsvm {{ libsvm }}
+    - boost {{ boost }}
+    - numpy {{ numpy }}
+    - cmake {{ cmake }}
+    - pkg-config {{ pkg_config }}
+    - gcc {{ gcc }}  # [linux]
+    - libgcc {{ libgcc }}  # [linux]
+  run:
+    - python
+    - setuptools
+    - bob.extension
+    - bob.blitz
+    - bob.core
+    - bob.io.base
+    - libblitz
+    - libsvm
+    - boost
+    - {{ pin_compatible('numpy', min_pin='x.x', max_pin='x.x') }}
+    - libgcc  # [linux]
+
+test:
+  imports:
+    - {{ name }}
+  commands:
+    - nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
+    - sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
+    - sphinx-build -aEb doctest {{ project_dir }}/doc sphinx
+  requires:
+    - nose {{ nose }}.*
+    - coverage {{ coverage }}.*
+    - sphinx {{ sphinx }}.*
+    - sphinx_rtd_theme {{ sphinx_rtd_theme }}.*
+
+about:
+  home: https://www.idiap.ch/software/bob/
+  license: BSD 3-Clause
+  summary: Bob's Python bindings to LIBSVM
+  license_family: BSD
diff --git a/doc/conf.py b/doc/conf.py
index 65e39a2..1e5cfdd 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -25,15 +25,9 @@ extensions = [
     'sphinx.ext.intersphinx',
     'sphinx.ext.napoleon',
     'sphinx.ext.viewcode',
+    'sphinx.ext.mathjax',
     ]
 
-import sphinx
-if sphinx.__version__ >= "1.4.1":
-    extensions.append('sphinx.ext.imgmath')
-    imgmath_image_format = 'svg'
-else:
-    extensions.append('sphinx.ext.pngmath')
-
 # Be picky about warnings
 nitpicky = True
 
-- 
GitLab