Skip to content

Commit cc752e5

Browse files
authored
release k2 as a pip package. (k2-fsa#208)
* release k2 as a pip package. * fix style issues.
1 parent 1af991b commit cc752e5

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ statistics=true
44
max-line-length=80
55
exclude =
66
.git,
7+
setup.py,
78
build,
89
k2/python/host,
910
k2/docs

scripts/build_pip.sh

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2020 Mobvoi Inc. (authors: Fangjun Kuang)
4+
#
5+
# Steps to build a pip package:
6+
#
7+
# (1)
8+
# pip install wheel twine
9+
# sudo apt-get install chrpath
10+
#
11+
# (2)
12+
# cd /path/to/k2
13+
# mkdir build
14+
# cd build
15+
# cmake -DCMAKE_BUILD_TYPE=Release ..
16+
# make -j _k2
17+
#
18+
# It will generate 3 files in the folder `lib`:
19+
# libcontext.so
20+
# libfsa.so
21+
# _k2.cpython-3?m-x86_64-linux-gnu.so, where ? depends on your python version.
22+
#
23+
# Please delete other files inside `lib`; otherwise, they will be copied to
24+
# the final `whl`!
25+
#
26+
# (3)
27+
# cd /path/to/k2
28+
# ./scripts/build_pip.sh
29+
#
30+
# (4) You will find the `whl` file in the `dist` directory.
31+
#
32+
# (5) Upload the generated `whl` file to pypi. Example:
33+
#
34+
# twine upload dist/k2-0.0.1-py36-none-any.whl
35+
#
36+
# Enter your username and password!
37+
#
38+
# (6) Done.
39+
40+
if ! command -v chrpath > /dev/null 2>&1; then
41+
echo "Please install chrpath first"
42+
exit 1
43+
fi
44+
45+
cur_dir=$(cd $(dirname $BASH_SOURCE) && pwd)
46+
k2_dir=$(cd $cur_dir/.. && pwd)
47+
build_dir=$k2_dir/build
48+
49+
cd $k2_dir
50+
51+
if [ ! -d $build_dir/lib ]; then
52+
echo "Please run: "
53+
echo " mkdir $build_dir"
54+
echo " cd $build_dir"
55+
echo " cmake .."
56+
echo " make -j _k2 "
57+
echo "before running this script"
58+
exit 1
59+
fi
60+
61+
for lib in $build_dir/lib/*.so; do
62+
chrpath -r '$ORIGIN' $lib
63+
done
64+
65+
tag=$(python -c "import sys; print(sys.version[:3].replace('.', ''))")
66+
67+
python3 setup.py bdist_wheel --python-tag py$tag

setup.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import setuptools
2+
3+
4+
def get_long_description():
5+
with open('README.md', 'r') as f:
6+
long_description = f.read()
7+
return long_description
8+
9+
10+
version = '0.0.1'
11+
description = 'FSA/FST algorithms, intended to (eventually) be interoperable with PyTorch and similar'
12+
13+
setuptools.setup(
14+
python_requires='>=3.6',
15+
name='k2',
16+
version=version,
17+
author='Daniel Povey',
18+
author_email='[email protected]',
19+
description=description,
20+
keywords='k2, FSA, FST',
21+
long_description=get_long_description(),
22+
long_description_content_type='text/markdown',
23+
url='https://github.com/k2-fsa/k2',
24+
package_dir={'': 'k2/python'},
25+
packages=['k2'],
26+
install_requires=['torch', 'graphviz'],
27+
data_files=[('', ['LICENSE'])],
28+
classifiers=[
29+
'Development Status :: 3 - Alpha',
30+
'Programming Language :: Python :: 3',
31+
'Programming Language :: C++',
32+
'Programming Language :: Python :: Implementation :: CPython',
33+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
34+
'Operating System :: OS Independent',
35+
],
36+
)

0 commit comments

Comments
 (0)