Skip to content

Commit

Permalink
Merge pull request #3 from kmaehashi/build-wheel
Browse files Browse the repository at this point in the history
add wheel build script
  • Loading branch information
kmaehashi authored May 30, 2018
2 parents 64f0ce4 + 0e9f7a5 commit f47e00b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ venv.bak/

# Project-specific
pypict/capi.cpp
pypict/pict
wheelhouse/
31 changes: 31 additions & 0 deletions build_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash -uex

# Build wheels using manylinux1 Docker image provided by PyPA:
# https://github.com/pypa/manylinux

PKG_DIR="$(cd "$(dirname $0)"; pwd)"

function run_manylinux() {
docker run \
--rm \
--user $(id -u):$(id -g) \
--volume "${PKG_DIR}:/package" \
--workdir /package \
quay.io/pypa/manylinux1_x86_64 \
"$@"
}

rm -rf dist wheelhouse
for PYTHON in cp27-cp27m cp27-cp27mu cp34-cp34m cp35-cp35m cp36-cp36m; do
run_manylinux sh -uex -c "
export PATH=/opt/python/${PYTHON}/bin:\${PATH}
export HOME=/tmp
export LD_LIBRARY_PATH=\${PWD}/pict
pip install --user 'Cython==0.28.3'
rm -rf dist
python setup.py build_pict test bdist_wheel --package-command
auditwheel --verbose repair dist/*-*-${PYTHON}-linux_x86_64.whl
"
done
13 changes: 12 additions & 1 deletion pypict/cmd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import csv
import io
import os
import subprocess
import tempfile


_PICT = 'pict'


def _get_pict_command():
pictcmd = os.path.join(os.path.dirname(__file__), _PICT)
if os.path.exists(pictcmd):
return pictcmd
return _PICT


def _pict(model_file, order=None, random_seed=None):
# TODO: support more options
cmdline = ['pict', model_file]
cmdline = [_get_pict_command(), model_file]
if order is not None:
cmdline += ['/o:{}'.format(order)]
if random_seed is not None:
Expand Down
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python

import shutil
import subprocess
import sys

from setuptools import setup, Command, Extension
from Cython.Build import cythonize


package_command = False


class BuildPictCommand(Command):

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

def run(self):
subprocess.check_call(['make', '-C', 'pict', 'clean'])
subprocess.check_call(['make', '-C', 'pict', 'libpict.so'])
if package_command:
subprocess.check_call(['make', '-C', 'pict', 'pict'])
shutil.copy2('pict/pict', 'pypict/pict')


package_data = {}

if '--package-command' in sys.argv:
sys.argv.remove('--package-command')
package_command = True
package_data = {'pypict': ['pict']}


with open('pypict/_version.py') as f:
Expand All @@ -35,6 +52,7 @@ def run(self):
packages=[
'pypict',
],
package_data=package_data,
test_suite='tests',
ext_modules=cythonize(
Extension(
Expand Down

0 comments on commit f47e00b

Please sign in to comment.