Skip to content

Commit

Permalink
bake binary dictionary in the wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
eiennohito committed Jul 31, 2023
1 parent 462d569 commit 2ef2223
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions package_python.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
#!/bin/bash
set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# guess versions
if [ -z "$1" ]; then
dict_version=`./gradlew -q showVersion`
version=${dict_version}
DICT_VERSION=$("$SCRIPT_DIR/gradlew" -q showVersion)
VERSION=${DICT_VERSION}
else
dict_version=$1
DICT_VERSION=$1
if [ -z "$2" ]; then
version=${dict_version}
VERSION=${DICT_VERSION}
else
version=$2
VERSION=$2
fi
fi

echo "VERSION=$VERSION, DICT_VERSION=$DICT_VERSION"

PACKAGES_ROOT="$SCRIPT_DIR/build/python"
BINARY_DIC_ROOT="$SCRIPT_DIR/build/dict/bin/$DICT_VERSION"

if [ ! -d "$BINARY_DIC_ROOT" ]; then
echo "binary dictionaries are not present in $BINARY_DIC_ROOT"
echo "run ./gradlew build to compile binary dictionaries"
exit 1
fi

set +e
rm -rf build/python/${version}
rm -rf "$PACKAGES_ROOT/$VERSION"
WHEELS_DIR="$PACKAGES_ROOT/wheels"
mkdir -p "$WHEELS_DIR"

set -e
home=`pwd`
home=$SCRIPT_DIR
for dict_type in small core full
do
temp=build/python/${version}/${dict_type}
pkg=${temp}/sudachidict_${dict_type}
temp="$PACKAGES_ROOT/$VERSION/$dict_type"
pkg="${temp}/sudachidict_${dict_type}"
mkdir -p ${pkg}
mkdir ${pkg}/resources
touch ${pkg}/__init__.py
Expand All @@ -30,8 +46,11 @@ do
cp LICENSE-2.0.txt ${temp}
cp python/MANIFEST.in ${temp}
cp python/setup.py ${temp}
cat python/INFO.json | sed "s/%%VERSION%%/${version}/g" | sed "s/%%DICT_VERSION%%/${dict_version}/g" | sed "s/%%DICT_TYPE%%/${dict_type}/g" > ${temp}/INFO.json
cd ${temp}
python setup.py sdist
cd ${home}
cat python/INFO.json | sed "s/%%VERSION%%/${VERSION}/g" | sed "s/%%DICT_VERSION%%/${DICT_VERSION}/g" | sed "s/%%DICT_TYPE%%/${dict_type}/g" > ${temp}/INFO.json
cp "$BINARY_DIC_ROOT/system_${dict_type}.dic" "${temp}/sudachidict_${dict_type}/resources/system.dic"
pip wheel \
--wheel-dir "$WHEELS_DIR" \
--no-deps --no-build-isolation \
"${temp}"
# python setup.py bdist_wheel sdist
done

0 comments on commit 2ef2223

Please sign in to comment.