diff --git a/conda_build/kenlm/bld.bat b/conda_build/kenlm/bld.bat new file mode 100644 index 000000000..bfd413338 --- /dev/null +++ b/conda_build/kenlm/bld.bat @@ -0,0 +1,22 @@ + +@echo off + +set PIP_NO_INDEX="False" +set PIP_NO_DEPENDENCIES="False" +set PIP_IGNORE_INSTALLED="False" + +set BDIR="./build" + +if exist %BDIR% ( rmdir /S /Q %BDIR% ) +mkdir %BDIR% + +:: Build +pushd %BDIR% +cmake .. -DKENLM_MAX_ORDER=%KENLM_MAX_ORDER% -DCMAKE_INSTALL_PREFIX:PATH=%PREFIX% +:: Install +make -j all install +popd +rmdir /S /Q %BDIR% + +:: Install python module +"%PYTHON%" -m pip install . --install-option="--max_order %KENLM_MAX_ORDER%" diff --git a/conda_build/kenlm/build.sh b/conda_build/kenlm/build.sh new file mode 100644 index 000000000..0dd5d3d26 --- /dev/null +++ b/conda_build/kenlm/build.sh @@ -0,0 +1,20 @@ + +PIP_NO_INDEX=False # Allow requisites from PyPi +PIP_NO_DEPENDENCIES=False # Install dependencies from our defined dependencies +PIP_IGNORE_INSTALLED=False # Take into account the current installed dependencies + +BDIR="./build" + +[[ -d $BDIR ]] && rm -rf $BDIR +mkdir $BDIR + +# Build +pushd $BDIR +cmake .. -DKENLM_MAX_ORDER=$KENLM_MAX_ORDER -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX +# Install +make -j all install +popd +rm -rf $BDIR + +# Install python module +$PYTHON -m pip install . --install-option="--max_order $KENLM_MAX_ORDER" diff --git a/conda_build/kenlm/meta.yaml b/conda_build/kenlm/meta.yaml new file mode 100644 index 000000000..c720661d1 --- /dev/null +++ b/conda_build/kenlm/meta.yaml @@ -0,0 +1,42 @@ + +{% set rdir = "../.." %} +{% set data = load_setup_py_data(setup_file=''+rdir+'/setup.py', from_recipe_dir=True) %} + +package: + name: kenlm + version: {{ data.get('version') }} + +source: + path: {{ rdir }} + +build: + string: "py{{ environ.get('CONDA_PY') }}_{{ environ.get('GIT_DESCRIBE_HASH') }}" + script_env: + - KENLM_MAX_ORDER=7 + +requirements: + build: + - {{ compiler('cxx') }} + - make + - cmake + host: + - pip + - setuptools + - python {{ python }} + - libboost>=1.71.0 + - eigen + - zlib + - bzip2 + - xz + run: + - python {{ python }} + - libboost>=1.71.0 + - eigen + - zlib + - bzip2 + - xz + +about: + home: https://github.com/kpu/kenlm + license: LGPL + summary: Faster and Smaller Language Model Queries diff --git a/conda_build/make_build.sh b/conda_build/make_build.sh new file mode 100755 index 000000000..4c390383d --- /dev/null +++ b/conda_build/make_build.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PACKAGE_VERBOSE_NAME="KenLM" + +usage() +{ + echo "$(basename $0) [-h] [-e ] [-r] [-s] -n -p " + echo "" + echo "OPTIONS:" + echo " -h It displays this help message." + echo " -e Name of the conda environment which will be used to build" + echo " ${PACKAGE_VERBOSE_NAME}. If not specified, the default value is" + echo " the provided package name with the suffix '-build'." + echo " -r It removes the conda environment before start if exists." + echo " -s Skip untracked files check." + echo " -n Conda package name in order to retrieve the pkg path" + echo " -p Python version to be used to build ${PACKAGE_VERBOSE_NAME}." +} + +CONDA_ENV_NAME="" +CONDA_PACKAGE_NAME="" +REMOVE_ENV_IF_EXISTS="" +CONDA_PYTHON_VERSION="" +SKIP_UNTRACKED_FILES_CHECK="" + +while getopts "e:n:p:rsh" options +do + case "${options}" in + h) usage + exit 0;; + e) CONDA_ENV_NAME=$OPTARG;; + r) REMOVE_ENV_IF_EXISTS="y";; + s) SKIP_UNTRACKED_FILES_CHECK="y";; + n) CONDA_PACKAGE_NAME=$OPTARG;; + p) CONDA_PYTHON_VERSION=$OPTARG;; + \?) usage 1>&2 + exit 1;; + esac +done + +# Info +echo "git describe --tags: $(git describe --tags || true)" +echo "git describe --always: $(git describe --always)" + +if [[ -z "$CONDA_PACKAGE_NAME" ]] || [[ -z "$CONDA_PYTHON_VERSION" ]]; then + >&2 echo "Error: not all mandatory parameters were provided" + >&2 echo "" + usage 1>&2 + exit 1 +fi + +if [[ -z "$CONDA_ENV_NAME" ]]; then + CONDA_ENV_NAME="${CONDA_PACKAGE_NAME}-build" +fi + +CONDA_PACKAGE_PATH="${SCRIPT_DIR}/${CONDA_PACKAGE_NAME}" + +if [[ ! -f "${CONDA_PACKAGE_PATH}/meta.yaml" ]]; then + >&2 echo "File 'meta.yaml' not found: ${CONDA_PACKAGE_PATH}/meta.yaml" + exit 1 +fi + +BASE_PACKAGE_PATH="${SCRIPT_DIR}/.." +UNTRACKED_FILES=$(git ls-files "$BASE_PACKAGE_PATH" --ignored --exclude-standard --others | wc -l) +CHANGED_FILES=$(git diff --name-only | wc -l) + +if [[ "$UNTRACKED_FILES" -ne "0" ]]; then + if [[ -z "$SKIP_UNTRACKED_FILES_CHECK" ]]; then + >&2 echo "Error: there are $UNTRACKED_FILES untracked files in the repository" + exit 1 + else + >&2 echo "Warning: there are $UNTRACKED_FILES untracked files in the repository" + fi +fi + +if [[ "$CHANGED_FILES" -ne "0" ]]; then + >&2 echo "Warning: there are $CHANGED_FILES changed files in the repository" +fi + +source $(conda info --base)/etc/profile.d/conda.sh + +if [[ -n "$REMOVE_ENV_IF_EXISTS" ]]; then + conda remove -y -n $CONDA_ENV_NAME --all +fi + +if [[ -n "$(conda env list | grep ^$CONDA_ENV_NAME[\ +])" ]]; then + >&2 echo "Error: conda environment '$CONDA_ENV_NAME' already exists" + >&2 echo "" + usage 1>&2 + exit 1 +fi + +conda create -y -n $CONDA_ENV_NAME -c conda-forge conda-build conda-verify python=$CONDA_PYTHON_VERSION +conda activate $CONDA_ENV_NAME +conda update -y conda + +CONDA_CHANNELS="-c conda-forge -c bitextor" + +# Make build +conda-build --no-test --no-anaconda-upload $CONDA_CHANNELS $CONDA_PACKAGE_PATH --python=$CONDA_PYTHON_VERSION diff --git a/setup.py b/setup.py index 9e0f0d155..26b9e418a 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import os import sys import re +from datetime import date #Does gcc compile with this header and library? def compile_test(header, library): @@ -57,6 +58,7 @@ def compile_test(header, library): setup( name='kenlm', + version=date.today().strftime('%Y%m%d'), ext_modules=ext_modules, include_package_data=True, )