Skip to content

Commit 096c62c

Browse files
committed
Improve Python binary distribution
Signed-off-by: Vadim Markovtsev <[email protected]>
1 parent 238d45b commit 096c62c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ _install: &_install
99
- pip install numpy auditwheel==1.4 setuptools twine
1010
- python3 setup.py bdist_wheel
1111
- auditwheel repair -w dist dist/*
12+
- unzip dist/*manylinux*
13+
- ldd libMHCUDA-*.data/purelib/libMHCUDA.so
1214

1315
_deploy: &_deploy
1416
provider: script

setup.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55
from setuptools.dist import Distribution
66
from shutil import copyfile
77
from subprocess import check_call
8-
from sys import platform
8+
import sys
9+
import sysconfig
10+
11+
12+
def get_python_library():
13+
"""Get path to the python library associated with the current python
14+
interpreter."""
15+
cfgvar = sysconfig.get_config_var
16+
libname = cfgvar("LDLIBRARY")
17+
python_library = os.path.join(
18+
cfgvar("LIBDIR") + (cfgvar("multiarchsubdir") or ""),
19+
libname)
20+
if os.path.exists(python_library):
21+
return python_library
22+
for root, dirnames, filenames in os.walk(cfgvar("base")):
23+
for filename in filenames:
24+
if filename == libname:
25+
return os.path.join(root, filename)
26+
raise FileNotFoundError(libname)
927

1028

1129
class CMakeBuild(build_py):
12-
SHLIBEXT = "dylib" if platform == "darwin" else "so"
30+
SHLIBEXT = "dylib" if sys.platform == "darwin" else "so"
1331

1432
def run(self):
1533
if not self.dry_run:
@@ -22,10 +40,15 @@ def get_outputs(self, *args, **kwargs):
2240
return outputs
2341

2442
def _build(self, builddir=None):
43+
syspaths = sysconfig.get_paths()
2544
check_call(("cmake", "-DCMAKE_BUILD_TYPE=Release",
2645
"-DCUDA_TOOLKIT_ROOT_DIR=%s" % os.getenv(
2746
"CUDA_TOOLKIT_ROOT_DIR",
2847
"must_export_CUDA_TOOLKIT_ROOT_DIR"),
48+
"-DPYTHON_DEFAULT_EXECUTABLE=python3",
49+
"-DPYTHON_INCLUDE_DIRS=" + syspaths["include"],
50+
"-DPYTHON_EXECUTABLE=" + sys.executable,
51+
"-DPYTHON_LIBRARY=" + get_python_library(),
2952
"."))
3053
check_call(("make", "-j%d" % cpu_count()))
3154
self.mkpath(self.build_lib)
@@ -55,7 +78,7 @@ def is_pure(self):
5578
py_modules=["libMHCUDA"],
5679
install_requires=["numpy"],
5780
distclass=BinaryDistribution,
58-
cmdclass={'build_py': CMakeBuild},
81+
cmdclass={"build_py": CMakeBuild},
5982
classifiers=[
6083
"Development Status :: 5 - Production/Stable",
6184
"Intended Audience :: Developers",

0 commit comments

Comments
 (0)