From b245241335d5b710b4fffd5c29d9a90d14dc34d4 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 15 Aug 2022 16:19:21 -0700 Subject: [PATCH] Conda build (#99) * Added conda build --- .../workflows/siemens_to_ismrmrd_conda.yml | 36 +++++++++ CMakeLists.txt | 2 +- conda/.gitignore | 3 + conda/build.sh | 9 +++ conda/environment.yml | 7 ++ conda/meta.yaml | 39 ++++++++++ conda/package.sh | 25 ++++++ conda/publish_package.sh | 77 +++++++++++++++++++ conda/run_test.sh | 10 +++ main.cpp | 4 +- 10 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/siemens_to_ismrmrd_conda.yml create mode 100644 conda/.gitignore create mode 100755 conda/build.sh 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.sh diff --git a/.github/workflows/siemens_to_ismrmrd_conda.yml b/.github/workflows/siemens_to_ismrmrd_conda.yml new file mode 100644 index 0000000..f0a8782 --- /dev/null +++ b/.github/workflows/siemens_to_ismrmrd_conda.yml @@ -0,0 +1,36 @@ +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: siemens-to-ismrmrd-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 siemens_to_ismrmrd*.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: | + ./publish_package.sh -u ismrmrd -t "$ANACONDA_TOKEN" -p `find build_pkg -name siemens_to_ismrmrd*.tar.bz2` diff --git a/CMakeLists.txt b/CMakeLists.txt index a3a0379..d1c0d35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ message(STATUS "Looking for packages in : ${CMAKE_PREFIX_PATH}") #VERSIONING set(SIEMENS_TO_ISMRMRD_VERSION_MAJOR 1) set(SIEMENS_TO_ISMRMRD_VERSION_MINOR 2) -set(SIEMENS_TO_ISMRMRD_VERSION_PATCH 3) +set(SIEMENS_TO_ISMRMRD_VERSION_PATCH 4) set(SIEMENS_TO_ISMRMRD_VERSION_STRING ${SIEMENS_TO_ISMRMRD_VERSION_MAJOR}.${SIEMENS_TO_ISMRMRD_VERSION_MINOR}.${SIEMENS_TO_ISMRMRD_VERSION_PATCH}) # Generate the converter_version.h header 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..2399a65 --- /dev/null +++ b/conda/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -euo pipefail + +mkdir -p build +cd build +cmake -G Ninja -DBUILD_DYNAMIC=ON -DCMAKE_PREFIX_PATH=${PREFIX} -DCMAKE_INSTALL_PREFIX=${PREFIX} ../ +ninja +ninja install \ No newline at end of file diff --git a/conda/environment.yml b/conda/environment.yml new file mode 100644 index 0000000..f5a9234 --- /dev/null +++ b/conda/environment.yml @@ -0,0 +1,7 @@ +name: siemens-to-ismrmrd-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..30de777 --- /dev/null +++ b/conda/meta.yaml @@ -0,0 +1,39 @@ +{% set major = load_file_regex(load_file='CMakeLists.txt', regex_pattern='(?<=set\(SIEMENS_TO_ISMRMRD_VERSION_MAJOR )([^\)]+)') %} +{% set minor = load_file_regex(load_file='CMakeLists.txt', regex_pattern='(?<=set\(SIEMENS_TO_ISMRMRD_VERSION_MINOR )([^\)]+)') %} +{% set patch = load_file_regex(load_file='CMakeLists.txt', regex_pattern='(?<=set\(SIEMENS_TO_ISMRMRD_VERSION_PATCH )([^\)]+)') %} + +package: + name: siemens_to_ismrmrd + version: {{ major.group(1) }}.{{ minor.group(1) }}.{{ patch.group(1) }} + +source: + path: ../ + +requirements: + build: + - boost=1.76.0 + - clang>=13.0.1 # [osx] + - clangxx>=13.0.1 # [osx] + - cmake>=3.20.0 + - gcc_linux-64>=9.0.0 # [linux64] + - gxx_linux-64>=9.0.0 # [linux64] + - ismrmrd=1.11.1 + - libxml2=2.9.12 + - libxslt=1.1.33 + - ninja=1.10.* + + run: + - ismrmrd=1.11.1 + - boost=1.76.0 + - libxml2=2.9.12 + - libxslt=1.1.33 + +about: + home: https://github.com/ismrmrd/siemens_to_ismrmrd + license: MIT + summary: 'Siemens to ISMRM Raw Data (ISMRMRD) converter' + description: | + Command line tool for converting Siemens raw data (*.dat) files to ISMRMRD files. + dev_url: https://github.com/ismrmrd/siemens_to_ismrmrd + doc_url: https://github.com/ismrmrd/siemens_to_ismrmrd + doc_source_url: https://github.com/ismrmrd/siemens_to_ismrmrd/blob/master/README.md \ No newline at end of file diff --git a/conda/package.sh b/conda/package.sh new file mode 100755 index 0000000..ac0774d --- /dev/null +++ b/conda/package.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail + +usage() +{ + cat << EOF + +Builds the siemens_to_ismrmrd conda package. + +Usage: $0 +EOF +} + +output_path="$(dirname "$0")/build_pkg" + +# Build up channel directives +channels=( + ismrmrd + conda-forge +) + +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.sh b/conda/run_test.sh new file mode 100644 index 0000000..01f05f0 --- /dev/null +++ b/conda/run_test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +# We are just printing help text, which will fail if dependencies are missing +siemens_to_ismrmrd -h +siemens_to_ismrmrd -v + + + diff --git a/main.cpp b/main.cpp index cf560cd..0dd5582 100644 --- a/main.cpp +++ b/main.cpp @@ -515,7 +515,7 @@ int main(int argc, char* argv[]) { if (vm.count("help")) { std::cout << display_options << "\n"; - return 1; + return 0; } if (vm.count("version")) { @@ -523,7 +523,7 @@ int main(int argc, char* argv[]) { << SIEMENS_TO_ISMRMRD_VERSION_MINOR << "." << SIEMENS_TO_ISMRMRD_VERSION_PATCH << "\n"; std::cout << "Built against ISMRMRD version: " << ISMRMRD_VERSION_MAJOR << "." << ISMRMRD_VERSION_MINOR << "." << ISMRMRD_VERSION_PATCH << "\n"; - return 1; + return 0; } }