|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Build a conda package from the locally build python package. |
| 4 | +# This is used in CI to test that the conda package can be built successfully. |
| 5 | +# |
| 6 | +# Prerequisites: |
| 7 | +# - Python package builds at ./dist/emsarray-X.Y.Z.tar.gz |
| 8 | +# - conda-forge/emsarray-feedstock cloned at ./emsarray-feedstock |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +HERE="$( cd -- "$( dirname -- "$( realpath -- "$0" )" )" && pwd )" |
| 13 | +PROJECT="$( dirname -- "$HERE" )" |
| 14 | + |
| 15 | +dist_path="$PROJECT/dist" |
| 16 | +feedstock_path="$PROJECT/emsarray-feedstock" |
| 17 | + |
| 18 | +files_to_clean=() |
| 19 | + |
| 20 | +function main() { |
| 21 | + trap cleanup EXIT |
| 22 | + |
| 23 | + local package_path="$( get_package_path )" |
| 24 | + local package_name="$( basename -- "$package_path")" |
| 25 | + local package_version=$( get_package_version "$package_name" ) |
| 26 | + |
| 27 | + tmp_dir="$( mktemp -d --tmpdir "emsarray-conda-build.XXXXXXX" )" |
| 28 | + files_to_clean+=( "$tmp_dir" ) |
| 29 | + cd "$tmp_dir" |
| 30 | + |
| 31 | + cp -R "$feedstock_path/recipe" "$tmp_dir/recipe" |
| 32 | + recipe_path="$tmp_dir/recipe/meta.yaml" |
| 33 | + update_recipe "$recipe_path" "$package_path" "$package_version" |
| 34 | + |
| 35 | + cat "$recipe_path" |
| 36 | + |
| 37 | + conda build \ |
| 38 | + --override-channels \ |
| 39 | + --channel conda-forge \ |
| 40 | + "$tmp_dir" |
| 41 | +} |
| 42 | + |
| 43 | +function get_package_path() { |
| 44 | + find "$dist_path" -name 'emsarray-*.tar.gz' -print -quit |
| 45 | +} |
| 46 | + |
| 47 | +function get_package_version() { |
| 48 | + local package_name="$1" |
| 49 | + local package_version=$( |
| 50 | + echo "$package_name" \ |
| 51 | + | sed 's/^emsarray-\(.*\)\.tar\.gz/\1/' |
| 52 | + ) |
| 53 | + if [[ "$package_name" == "$package_version" ]] ; then |
| 54 | + echo "Could not extract version from package name!" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + echo "$package_version" |
| 58 | +} |
| 59 | + |
| 60 | +function update_recipe() { |
| 61 | + local recipe_path="$1" |
| 62 | + local package_path="$2" |
| 63 | + local package_version="$3" |
| 64 | + |
| 65 | + sed \ |
| 66 | + -e 's!set version = ".*"!set version = "'"$package_version"'"!' \ |
| 67 | + -e 's!url: https://pypi.io/.*!url: "file://'"$package_path"'"!' \ |
| 68 | + -e '/sha256:/d' \ |
| 69 | + -i "$recipe_path" |
| 70 | +} |
| 71 | + |
| 72 | +function cleanup() { |
| 73 | + rm -rf "${files_to_clean[@]}" |
| 74 | +} |
| 75 | + |
| 76 | +main |
0 commit comments