Skip to content

Commit f47e00b

Browse files
authored
Merge pull request #3 from kmaehashi/build-wheel
add wheel build script
2 parents 64f0ce4 + 0e9f7a5 commit f47e00b

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,5 @@ venv.bak/
105105

106106
# Project-specific
107107
pypict/capi.cpp
108+
pypict/pict
109+
wheelhouse/

build_wheel.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -uex
2+
3+
# Build wheels using manylinux1 Docker image provided by PyPA:
4+
# https://github.com/pypa/manylinux
5+
6+
PKG_DIR="$(cd "$(dirname $0)"; pwd)"
7+
8+
function run_manylinux() {
9+
docker run \
10+
--rm \
11+
--user $(id -u):$(id -g) \
12+
--volume "${PKG_DIR}:/package" \
13+
--workdir /package \
14+
quay.io/pypa/manylinux1_x86_64 \
15+
"$@"
16+
}
17+
18+
rm -rf dist wheelhouse
19+
for PYTHON in cp27-cp27m cp27-cp27mu cp34-cp34m cp35-cp35m cp36-cp36m; do
20+
run_manylinux sh -uex -c "
21+
export PATH=/opt/python/${PYTHON}/bin:\${PATH}
22+
export HOME=/tmp
23+
export LD_LIBRARY_PATH=\${PWD}/pict
24+
25+
pip install --user 'Cython==0.28.3'
26+
rm -rf dist
27+
python setup.py build_pict test bdist_wheel --package-command
28+
29+
auditwheel --verbose repair dist/*-*-${PYTHON}-linux_x86_64.whl
30+
"
31+
done

pypict/cmd.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import csv
22
import io
3+
import os
34
import subprocess
45
import tempfile
56

67

8+
_PICT = 'pict'
9+
10+
11+
def _get_pict_command():
12+
pictcmd = os.path.join(os.path.dirname(__file__), _PICT)
13+
if os.path.exists(pictcmd):
14+
return pictcmd
15+
return _PICT
16+
17+
718
def _pict(model_file, order=None, random_seed=None):
819
# TODO: support more options
9-
cmdline = ['pict', model_file]
20+
cmdline = [_get_pict_command(), model_file]
1021
if order is not None:
1122
cmdline += ['/o:{}'.format(order)]
1223
if random_seed is not None:

setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/env python
22

3+
import shutil
34
import subprocess
5+
import sys
46

57
from setuptools import setup, Command, Extension
68
from Cython.Build import cythonize
79

810

11+
package_command = False
12+
13+
914
class BuildPictCommand(Command):
1015

1116
description = 'build PICT shared library'
@@ -18,7 +23,19 @@ def finalize_options(self):
1823
pass
1924

2025
def run(self):
26+
subprocess.check_call(['make', '-C', 'pict', 'clean'])
2127
subprocess.check_call(['make', '-C', 'pict', 'libpict.so'])
28+
if package_command:
29+
subprocess.check_call(['make', '-C', 'pict', 'pict'])
30+
shutil.copy2('pict/pict', 'pypict/pict')
31+
32+
33+
package_data = {}
34+
35+
if '--package-command' in sys.argv:
36+
sys.argv.remove('--package-command')
37+
package_command = True
38+
package_data = {'pypict': ['pict']}
2239

2340

2441
with open('pypict/_version.py') as f:
@@ -35,6 +52,7 @@ def run(self):
3552
packages=[
3653
'pypict',
3754
],
55+
package_data=package_data,
3856
test_suite='tests',
3957
ext_modules=cythonize(
4058
Extension(

0 commit comments

Comments
 (0)