Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conda build #374

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions conda_build/kenlm/bld.bat
Original file line number Diff line number Diff line change
@@ -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%"
20 changes: 20 additions & 0 deletions conda_build/kenlm/build.sh
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions conda_build/kenlm/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions conda_build/make_build.sh
Original file line number Diff line number Diff line change
@@ -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 <conda_env_name>] [-r] [-s] -n <package_name> -p <python_version>"
echo ""
echo "OPTIONS:"
echo " -h It displays this help message."
echo " -e <conda_env_name> 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 <package_name> Conda package name in order to retrieve the pkg path"
echo " -p <python_version> 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
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)