From a64432dbbdf54224236648c4a52aca8a29c47af3 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 4 Oct 2022 11:35:26 +0800 Subject: [PATCH 1/2] Support building conda packages --- .github/workflows/build_conda_macos.yml | 69 +++++++++++++++++++++ .github/workflows/build_conda_ubuntu.yml | 71 ++++++++++++++++++++++ .github/workflows/build_conda_windows.yml | 73 +++++++++++++++++++++++ scripts/build_conda.sh | 32 ++++++++++ scripts/conda/kaldialign/meta.yaml | 33 ++++++++++ 5 files changed, 278 insertions(+) create mode 100644 .github/workflows/build_conda_macos.yml create mode 100644 .github/workflows/build_conda_ubuntu.yml create mode 100644 .github/workflows/build_conda_windows.yml create mode 100755 scripts/build_conda.sh create mode 100644 scripts/conda/kaldialign/meta.yaml diff --git a/.github/workflows/build_conda_macos.yml b/.github/workflows/build_conda_macos.yml new file mode 100644 index 0000000..d22acbc --- /dev/null +++ b/.github/workflows/build_conda_macos.yml @@ -0,0 +1,69 @@ +name: build_conda_macos + +on: + push: + tags: + - '*' + branches: + - conda + +concurrency: + group: build_conda_macos-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_conda_macos: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-10.15] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + + steps: + # refer to https://github.com/actions/checkout + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + python-version: ${{ matrix.python-version }} + activate-environment: kaldialign + + - name: Display Python version + shell: bash -l {0} + run: | + python3 -c "import sys; print(sys.version)" + which python3 + + - name: Install conda dependencies + shell: bash -l {0} + run: | + conda install -y -q anaconda-client + conda install -y -q conda-build + + - name: Display conda info + shell: bash -l {0} + run: | + which conda + conda env list + conda info + + - name: Build kaldialign + shell: bash -l {0} + env: + KALDIALIGN_CONDA_TOKEN: ${{ secrets.KALDIALIGN_CONDA_TOKEN }} + run: | + ./scripts/build_conda.sh + + - name: Display generated files + run: | + ls -lh /usr/local/miniconda/envs/kaldialign/conda-bld/osx-64 + + - name: Upload generated files + uses: actions/upload-artifact@v2 + with: + name: cpu-python-${{ matrix.python-version }}-${{ matrix.os }} + path: /usr/local/miniconda/envs/kaldialign/conda-bld/osx-64/*.tar.bz2 diff --git a/.github/workflows/build_conda_ubuntu.yml b/.github/workflows/build_conda_ubuntu.yml new file mode 100644 index 0000000..1cb0d22 --- /dev/null +++ b/.github/workflows/build_conda_ubuntu.yml @@ -0,0 +1,71 @@ +name: build_conda_ubuntu + +on: + push: + tags: + - '*' + branches: + - conda + +concurrency: + group: build_conda_ubuntu-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_conda_ubuntu: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-18.04] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + + steps: + # refer to https://github.com/actions/checkout + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + python-version: ${{ matrix.python-version }} + activate-environment: kaldialign + + - name: Display Python version + shell: bash -l {0} + run: | + python3 -c "import sys; print(sys.version)" + which python3 + + - name: Install conda dependencies + shell: bash -l {0} + run: | + conda install -y -q anaconda-client + conda install -y -q conda-build + conda install -y -q numpy + + - name: Display conda info + shell: bash -l {0} + run: | + which conda + conda env list + conda info + nproc + + - name: Build kaldialign + shell: bash -l {0} + env: + KALDIALIGN_CONDA_TOKEN: ${{ secrets.KALDIALIGN_CONDA_TOKEN }} + run: | + ./scripts/build_conda.sh + + - name: Display generated files + run: | + ls -lh /usr/share/miniconda/envs/kaldialign/conda-bld/linux-64 + + - name: Upload generated files + uses: actions/upload-artifact@v2 + with: + name: python-${{ matrix.python-version }}-${{ matrix.os }} + path: /usr/share/miniconda/envs/kaldialign/conda-bld/linux-64/*.tar.bz2 diff --git a/.github/workflows/build_conda_windows.yml b/.github/workflows/build_conda_windows.yml new file mode 100644 index 0000000..cfc48cf --- /dev/null +++ b/.github/workflows/build_conda_windows.yml @@ -0,0 +1,73 @@ +name: build_conda_windows + +on: + push: + tags: + - '*' + branches: + - conda + +concurrency: + group: build_conda_windows-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_conda_windows: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-2019] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + + steps: + # refer to https://github.com/actions/checkout + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + python-version: ${{ matrix.python-version }} + activate-environment: kaldialign + + - name: Display Python version + shell: bash -l {0} + run: | + python -c "import sys; print(sys.version)" + which python + + - name: Install conda dependencies + shell: bash -l {0} + run: | + conda install -y -q anaconda-client + conda install -y -q conda-build + + - name: Display conda info + shell: bash -l {0} + run: | + which conda + conda env list + conda info + which python + + - name: Build kaldialign + shell: bash -l {0} + env: + KALDIALIGN_CONDA_TOKEN: ${{ secrets.KALDIALIGN_CONDA_TOKEN }} + run: | + ./scripts/build_conda.sh + + - name: Display generated files + shell: bash -l {0} + run: | + ls -lh /c/Miniconda/envs/kaldialign/conda-bld + ls -lh /c/Miniconda/envs/kaldialign/conda-bld/*/* + ls -lh /c/Miniconda/envs/kaldialign/conda-bld/win-64/* + + - name: Upload generated files + uses: actions/upload-artifact@v2 + with: + name: python-${{ matrix.python-version }}-windows-2019 + path: c:/Miniconda/envs/kaldialign/conda-bld/win-64/*.tar.bz2 diff --git a/scripts/build_conda.sh b/scripts/build_conda.sh new file mode 100755 index 0000000..fcd8afa --- /dev/null +++ b/scripts/build_conda.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# The following environment variables are supposed to be set by users +# +# - KALDIALIGN_CONDA_TOKEN +# If not set, auto upload to anaconda.org is disabled. +# +# Its value is from https://anaconda.org/kaldialign/settings/access +# (You need to login as user kaldialign to see its value) +# +set -e +export CONDA_BUILD=1 + +cur_dir=$(cd $(dirname $BASH_SOURCE) && pwd) +kaldialign_dir=$(cd $cur_dir/.. && pwd) + +cd $kaldialign_dir + +export KALDIALIGN_ROOT_DIR=$kaldialign_dir +echo "KALDIALIGN_DIR: $KALDIALIGN_ROOT_DIR" + +KALDIALIGN_PYTHON_VERSION=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))") + +# Example value: 3.8 +export KALDIALIGN_PYTHON_VERSION + +if [ -z $KALDIALIGN_CONDA_TOKEN ]; then + echo "Auto upload to anaconda.org is disabled since KALDIALIGN_CONDA_TOKEN is not set" + conda build --no-test --no-anaconda-upload ./scripts/conda/kaldialign +else + conda build --no-test --token $KALDIALIGN_CONDA_TOKEN ./scripts/conda/kaldialign +fi diff --git a/scripts/conda/kaldialign/meta.yaml b/scripts/conda/kaldialign/meta.yaml new file mode 100644 index 0000000..0e56583 --- /dev/null +++ b/scripts/conda/kaldialign/meta.yaml @@ -0,0 +1,33 @@ +package: + name: kaldialign + version: "1.4" + +source: + path: "{{ environ.get('KALDIALIGN_ROOT_DIR') }}" + +build: + number: 0 + string: py{{ environ.get('KALDIALIGN_PYTHON_VERSION') }} + script: {{ PYTHON }} setup.py install --single-version-externally-managed --record=record.txt + +requirements: + build: + - {{ compiler('c') }} # [win] + - {{ compiler('cxx') }} # [win] + + host: + - anaconda-client + - conda-build + - cmake + - python + run: + - python + +about: + home: https://github.com/pzelasko/kaldialign + license: Apache V2 + license_file: LICENSE + summary: Python wrappers for Kaldi Levenshtein's distance and alignment code. + description: | + A small package that exposes edit distance computation functions from Kaldi. + It uses the original Kaldi code and wraps it using pybind11. From 7ce9a35c965f6174f12fa07bd6456a292ac6da7c Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 4 Oct 2022 11:46:06 +0800 Subject: [PATCH 2/2] Small fixes --- CMakeLists.txt | 1 + README.md | 8 +++++++- scripts/conda/kaldialign/meta.yaml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ccc01..023f768 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR) project(kaldialign CXX) +# Please remember to also change line 3 of ./scripts/conda/kaldialign/meta.yaml set(KALDIALIGN_VERSION "0.4") if(NOT CMAKE_BUILD_TYPE) diff --git a/README.md b/README.md index 4122ce8..6dea249 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ A small package that exposes edit distance computation functions from [Kaldi](ht ## Installation +```bash +conda install -c kaldialign kaldialign +``` + +or + ```bash pip install --verbose kaldialign ``` @@ -33,7 +39,7 @@ EPS = '*' a = ['a', 'b', 'c'] b = ['a', 's', 'x', 'c'] ali = align(a, b, EPS) -assert ali == [('a', 'a'), (b, 's'), (EPS, 'x'), ('c', 'c')] +assert ali == [('a', 'a'), ('b', 's'), (EPS, 'x'), ('c', 'c')] ``` - `edit_distance(seq1, seq2)` - used to obtain the total edit distance, as well as the number of insertions, deletions and substitutions. diff --git a/scripts/conda/kaldialign/meta.yaml b/scripts/conda/kaldialign/meta.yaml index 0e56583..0dbbb1a 100644 --- a/scripts/conda/kaldialign/meta.yaml +++ b/scripts/conda/kaldialign/meta.yaml @@ -1,6 +1,6 @@ package: name: kaldialign - version: "1.4" + version: "0.4" source: path: "{{ environ.get('KALDIALIGN_ROOT_DIR') }}"