From 4edc37bbf366290121059fbff606a86b1e0c8dcf Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Wed, 31 Aug 2022 09:30:10 -0700 Subject: [PATCH] Adding conda build and publish --- .github/workflows/gadgetron_python_conda.yml | 39 ++++++++++ conda/.gitignore | 3 + conda/build.sh | 5 ++ conda/conda_build_config.yaml | 3 + conda/environment.yml | 7 ++ conda/meta.yaml | 32 ++++++++ conda/package.sh | 25 +++++++ conda/publish_package.sh | 77 ++++++++++++++++++++ conda/run_test.py | 10 +++ gadgetron/version.py | 4 +- setup.py | 6 +- 11 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/gadgetron_python_conda.yml create mode 100644 conda/.gitignore create mode 100755 conda/build.sh create mode 100644 conda/conda_build_config.yaml create mode 100644 conda/environment.yml create mode 100644 conda/meta.yaml create mode 100755 conda/package.sh create mode 100755 conda/publish_package.sh create mode 100644 conda/run_test.py diff --git a/.github/workflows/gadgetron_python_conda.yml b/.github/workflows/gadgetron_python_conda.yml new file mode 100644 index 0000000..cef022c --- /dev/null +++ b/.github/workflows/gadgetron_python_conda.yml @@ -0,0 +1,39 @@ +on: + pull_request: + branches: + - master + release: + types: + - created + +jobs: + build-conda-packages: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + - uses: conda-incubator/setup-miniconda@e81abac10ce2c37423b54eae5af93aa3b4d3475c + with: + activate-environment: ismrmrd-python-build + environment-file: conda/environment.yml + python-version: 3.9 + auto-activate-base: false + - name: Build conda package + shell: bash -l {0} + working-directory: conda + run: | + ./package.sh + echo "Packages built: $(find build_pkg -name gadgetron-python*.tar.bz2)" + - name: Push conda package + shell: bash -l {0} + if: ${{ github.event_name == 'release' }} + env: + ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} + working-directory: conda + run: | + for p in $(find build_pkg -name gadgetron-python*.tar.bz2) + do + ./publish_package.sh -u gadgetron -t "$ANACONDA_TOKEN" -p "$p" + done \ No newline at end of file diff --git a/conda/.gitignore b/conda/.gitignore new file mode 100644 index 0000000..846c4f9 --- /dev/null +++ b/conda/.gitignore @@ -0,0 +1,3 @@ +build_pkg/ +.pytest_cache/ +__pycache__/ \ No newline at end of file diff --git a/conda/build.sh b/conda/build.sh new file mode 100755 index 0000000..16796e3 --- /dev/null +++ b/conda/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -euo pipefail + +pip install . diff --git a/conda/conda_build_config.yaml b/conda/conda_build_config.yaml new file mode 100644 index 0000000..65ea6b8 --- /dev/null +++ b/conda/conda_build_config.yaml @@ -0,0 +1,3 @@ +python: + - 3.9 + - 3.10 \ No newline at end of file diff --git a/conda/environment.yml b/conda/environment.yml new file mode 100644 index 0000000..3c76a7b --- /dev/null +++ b/conda/environment.yml @@ -0,0 +1,7 @@ +name: gadgetron-python-build +channels: + - conda-forge +dependencies: + - conda-build + - anaconda-client + diff --git a/conda/meta.yaml b/conda/meta.yaml new file mode 100644 index 0000000..d1b8b10 --- /dev/null +++ b/conda/meta.yaml @@ -0,0 +1,32 @@ +{% set data = load_setup_py_data() %} + +package: + name: gadgetron-python + version: {{ data.get('version') }} + +source: + path: ../ + +requirements: + build: + - python {{ python }} + - ismrmrd-python>=1.12.5 + - numpy>=1.22.0 + - pyFFTW>=0.11 + - multimethod>=1.0 + + run: + - python + - numpy>=1.22.0 + - pyFFTW>=0.11 + - multimethod>=1.0 + - ismrmrd-python>=1.12.5 + +about: + home: https://github.com/gadgetron/gadgetron-python + license: MIT + summary: 'Python interface for Gadgetron' + description: | + Interface and utilities for the writing Gadgetron applications in Python. + dev_url: https://github.com/gadgetron/gadgetron-python + doc_url: https://github.com/gadgetron/gadgetron-python diff --git a/conda/package.sh b/conda/package.sh new file mode 100755 index 0000000..28a66e7 --- /dev/null +++ b/conda/package.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail + +usage() +{ + cat << EOF + +Builds the gadgetron-python conda package. + +Usage: $0 +EOF +} + +output_path="$(dirname "$0")/build_pkg" + +# Build up channel directives +channels=( + conda-forge + ismrmrd +) + +channel_directives=$(printf -- "-c %s " "${channels[@]}") + +mkdir -p "$output_path" +bash -c "conda build --no-anaconda-upload --output-folder $output_path $channel_directives $(dirname "$0")" diff --git a/conda/publish_package.sh b/conda/publish_package.sh new file mode 100755 index 0000000..6c3b922 --- /dev/null +++ b/conda/publish_package.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -euo pipefail + +usage() +{ + cat << EOF + +Publishes a conda package. + +Usage: $0 [options] + +Options: + -p|--package_path Path to the package (tar.gz) to push + -u|--user Anaconda.org channeluser or organization + -t|--token Token for uploading to anaconda.org + -f|--force Force push even if package exists + -h| --help Brings up this menu +EOF +} + +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -p|--package_path) + package_path="$2" + shift + shift + ;; + -u|--user) + user="$2" + shift + shift + ;; + -t|--token) + token="$2" + shift + shift + ;; + --force) + force=1 + shift + ;; + -h|--help) + usage + exit + ;; + *) + echo "ERROR: unknown option \"$key\"" + usage + exit 1 + ;; + esac +done + +if [[ -z "${package_path:-}" ]]; then + echo "You cannot push to anaconda without a package" + echo "Please supply a package path with the --package_path argument" + exit 1 +fi +if [[ -z "${token:-}" ]]; then + echo "You cannot push to anaconda without a token" + echo "Please supply a token with the --token argument" + exit 1 +fi +if [[ -z "${user:-}" ]]; then + echo "You cannot push to anaconda without a user" + echo "Please supply a user with the --user argument" + exit 1 +fi + +force_directive="--skip-existing" +if [[ -n ${force:-} ]]; then + force_directive="--force" +fi + +anaconda -t "$token" upload -u "$user" $force_directive "$package_path" diff --git a/conda/run_test.py b/conda/run_test.py new file mode 100644 index 0000000..9c8111e --- /dev/null +++ b/conda/run_test.py @@ -0,0 +1,10 @@ +import sys + +def ensure_importable(): + try: + import gadgetron + except ModuleNotFoundError or ImportError as ee: + print('This dummy test script can only run if gadgetron is importable : {0}'.format(ee.msg), file=sys.stderr) + exit(1) + +ensure_importable() \ No newline at end of file diff --git a/gadgetron/version.py b/gadgetron/version.py index 86d80ec..e3e8923 100644 --- a/gadgetron/version.py +++ b/gadgetron/version.py @@ -1,6 +1,6 @@ major = 1 -minor = 3 -build = 6 +minor = 4 +build = 0 version = f"{major}.{minor}.{build}" diff --git a/setup.py b/setup.py index 90e40cd..bac4f93 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,9 @@ author_email='kristofferlknudsen@gradientsoftware.net', description='', install_requires=[ - 'numpy>=1.15.1', - 'ismrmrd>=1.6.2', + 'numpy>=1.22', + 'ismrmrd>=1.12.5', 'pyFFTW>=0.11', - 'multimethod >= 1.0' + 'multimethod>=1.0' ] )