Skip to content

Commit

Permalink
Conda build (#56)
Browse files Browse the repository at this point in the history
* Added conda build and fixed broken tests

* Remove debug code

* Removed Azure DevOps pipeline

* Disabling nosetests on mac

* PR review

* Removed macos conda build for now

* bump numpy in requirements file

Co-authored-by: Michael Hansen <mihansen@microsoft>
  • Loading branch information
hansenms and Michael Hansen authored Aug 12, 2022
1 parent b4ab63b commit 2cdf828
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 52 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ismrmrd_python_conda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
pull_request:
branches:
- master
release:
types:
- created

jobs:
build-conda-packages:
strategy:
matrix:
os: [ubuntu-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 ismrmrd-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: |
./publish_package.sh -u ismrmrd -t "$ANACONDA_TOKEN" -p `find build_pkg -name ismrmrd-python*.tar.bz2`
47 changes: 0 additions & 47 deletions azure-pipelines.yml

This file was deleted.

3 changes: 3 additions & 0 deletions conda/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build_pkg/
.pytest_cache/
__pycache__/
5 changes: 5 additions & 0 deletions conda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -euo pipefail

python setup.py install
7 changes: 7 additions & 0 deletions conda/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: ismrmrd-python-build
channels:
- conda-forge
dependencies:
- conda-build
- anaconda-client

36 changes: 36 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% set data = load_setup_py_data() %}

package:
name: ismrmrd-python
version: {{ data.get('version') }}

source:
path: ../

requirements:
build:
- numpy>=1.22.0
- h5py>=2.3
- nose>=1.0
- xsdata>=22.2

run:
- xsdata>=22.2
- numpy>=1.22.0
- h5py>=2.3

test:
source_files:
- tests
requires:
- nose

about:
home: https://github.com/ismrmrd/ismrmrd-python
license: MIT
summary: 'Python interface for ISMRMRD'
description: |
Python interface and utilities for the ISMRM Raw Data (ISMRMRD a.k.a. MRD) format.
dev_url: https://github.com/ismrmrd/ismrmrd-python
doc_url: https://github.com/ismrmrd/ismrmrd-python
doc_source_url: https://github.com/ismrmrd/ismrmrd-python/blob/main/README.md
24 changes: 24 additions & 0 deletions conda/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail

usage()
{
cat << EOF
Builds the ismrmrd-python conda package.
Usage: $0
EOF
}

output_path="$(dirname "$0")/build_pkg"

# Build up channel directives
channels=(
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")"
77 changes: 77 additions & 0 deletions conda/publish_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
set -euo pipefail

usage()
{
cat << EOF
Publishes a conda package.
Usage: $0 [options]
Options:
-p|--package_path <path> Path to the package (tar.gz) to push
-u|--user <user> Anaconda.org channeluser or organization
-t|--token <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"
7 changes: 7 additions & 0 deletions conda/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail

cd tests
nosetests

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
h5py==2.9.0
nose==1.3.7
numpy==1.21.0
numpy==1.22.0
PyXB==1.2.6
six==1.12.0
xsdata==22.2
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def to_uri(filename):
version='1.12.0',
author='ISMRMRD Developers',
description='Python implementation of the ISMRMRD',
license='Public Domain',
license='MIT',
keywords='ismrmrd',
url='https://ismrmrd.github.io',
long_description = long_description,
Expand All @@ -70,7 +70,7 @@ def to_uri(filename):
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: Public Domain',
'License :: MIT',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering :: Medical Science Apps.'
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def create_random_image(seed=42):
header = create_random_image_properties()

image = ismrmrd.Image.from_array(data, **header)
image.attribute_string = "This is a random attribute: {}".format(random.randint(0, 1000))
image.attribute_string = "<?xml version='1.0' encoding='UTF-8'?>\n<ismrmrdMeta><meta><name>rando</name><value>{}</value></meta></ismrmrdMeta>".format(random.randint(0, 1000))

return image

Expand Down
3 changes: 2 additions & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_new_instance():
eq_(type(img.data), np.ndarray)
eq_(img.data.dtype, np.complex64)

attr = "this is a fake attribute string"
attr = "<?xml version='1.0' encoding='UTF-8'?>\n<ismrmrdMeta><meta><name>rando</name><value>blah</value></meta></ismrmrdMeta>"

head = ismrmrd.ImageHeader()
head.attribute_string_len = len(attr) # must set attribute_string_len
head.data_type = ismrmrd.DATATYPE_CXFLOAT # must set data_type
Expand Down

0 comments on commit 2cdf828

Please sign in to comment.