<commit_before>#!/bin/sh

# This script automatically builds a Conda package

cd "$(dirname "$0")/../.."
VT_DIR="$(pwd)"

# Clears Conda cache
ANACONDA_CACHE="$(dirname "$(which python)")/../conda-bld/src_cache/vistrails.tar.gz"
rm -f "$ANACONDA_CACHE"

if [ -z "$1" ]; then
    echo "Usage: $(basename $0) <target_directory> [version]" >&2
    exit 1
fi
if [ -z "$2" ]; then
    # describe gives us either "v2.1.4" or "v2.1.4-40-g1234567"
    # note: no 'sed -r' on OS X
    VERSION="$(git describe --always --tags | sed 's/^v//' | sed 's/^\([0-9.]*\)-\([0-9]*\)-g\([a-z0-9]*\)$/\1.\2/')"
else
    VERSION="$2"
fi

DEST_DIR="$1"

TEMP_DIR=$(mktemp -d /tmp/vt_conda_XXXXXXXX)

# Builds source distribution
if ! python setup.py sdist --dist-dir $TEMP_DIR; then
    rm -Rf $TEMP_DIR
    exit 1
fi

# Creates symlink
TEMP_FILE="$(echo $TEMP_DIR/*)"
ln -s "$TEMP_FILE" $TEMP_DIR/vistrails.tar.gz

# Copies conda recipe
cp -r dist/conda/vistrails $TEMP_DIR/vistrails

# Changes version in recipe
VERSION_ESCAPED="$(echo "$VERSION" | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')"
sed -i "s/_REPLACE_version_REPLACE_/$VERSION_ESCAPED/g" $TEMP_DIR/vistrails/meta.yaml

# Changes URL
URL_ESCAPED="$(echo "file://$TEMP_DIR/vistrails.tar.gz" | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')"
sed -i "s/_REPLACE_url_REPLACE_/$URL_ESCAPED/g" $TEMP_DIR/vistrails/meta.yaml

# Builds Conda package
cd $TEMP_DIR
OUTPUT_PKG="$(conda build --output vistrails)"
if ! conda build vistrails; then
    rm -Rf $TEMP_DIR
    rm -f "$ANACONDA_CACHE"
    exit 1
fi

# Copies result out
cp "$OUTPUT_PKG" $DEST_DIR/

# Removes temporary directory
rm -Rf $TEMP_DIR

# Clears Conda cache
rm -f "$ANACONDA_CACHE"<commit_msg>Works around sed -i on OS X<commit_after>#!/bin/sh

# This script automatically builds a Conda package

cd "$(dirname "$0")/../.."
VT_DIR="$(pwd)"

# Clears Conda cache
ANACONDA_CACHE="$(dirname "$(which python)")/../conda-bld/src_cache/vistrails.tar.gz"
rm -f "$ANACONDA_CACHE"

if [ -z "$1" ]; then
    echo "Usage: $(basename $0) <target_directory> [version]" >&2
    exit 1
fi
if [ -z "$2" ]; then
    # describe gives us either "v2.1.4" or "v2.1.4-40-g1234567"
    # note: no 'sed -r' on OS X
    VERSION="$(git describe --always --tags | sed 's/^v//' | sed 's/^\([0-9.]*\)-\([0-9]*\)-g\([a-z0-9]*\)$/\1.\2/')"
else
    VERSION="$2"
fi

DEST_DIR="$1"

TEMP_DIR=$(mktemp -d /tmp/vt_conda_XXXXXXXX)

# Builds source distribution
if ! python setup.py sdist --dist-dir $TEMP_DIR; then
    rm -Rf $TEMP_DIR
    exit 1
fi

# Creates symlink
TEMP_FILE="$(echo $TEMP_DIR/*)"
ln -s "$TEMP_FILE" $TEMP_DIR/vistrails.tar.gz

# Copies conda recipe
cp -r dist/conda/vistrails $TEMP_DIR/vistrails

sedi(){
    TEMPFILE=$(mktemp /tmp/vt_conda_XXXXXXXX)
    sed "$1" "$2" > $TEMPFILE
    mv $TEMPFILE "$2"
}

# Changes version in recipe
VERSION_ESCAPED="$(echo "$VERSION" | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')"
sedi "s/_REPLACE_version_REPLACE_/$VERSION_ESCAPED/g" $TEMP_DIR/vistrails/meta.yaml

# Changes URL
URL_ESCAPED="$(echo "file://$TEMP_DIR/vistrails.tar.gz" | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')"
sedi "s/_REPLACE_url_REPLACE_/$URL_ESCAPED/g" $TEMP_DIR/vistrails/meta.yaml

# Builds Conda package
cd $TEMP_DIR
OUTPUT_PKG="$(conda build --output vistrails)"
if ! conda build vistrails; then
    rm -Rf $TEMP_DIR
    rm -f "$ANACONDA_CACHE"
    exit 1
fi

# Copies result out
cp "$OUTPUT_PKG" $DEST_DIR/

# Removes temporary directory
rm -Rf $TEMP_DIR

# Clears Conda cache
rm -f "$ANACONDA_CACHE"
{'fraction_non_alphanumeric': 0.19528329019269486, 'fraction_numerical': 0.01984469370146678, 'mean_word_length': 3.3858764186633037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6771660', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1443, 'n_words': 345}