This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup.py
178 lines (146 loc) · 4.67 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import re
import shutil
import subprocess
import sys
import sysconfig
from Cython.Distutils import build_ext
from pkg_resources import get_distribution
from setuptools import Extension
from setuptools import setup
CUDA_VERSION = subprocess.check_output(
'nvcc -V | grep -oP "release\s([0-9\.]+)" | grep -oP "([0-9\.]+)"',
shell=True).decode('utf-8').strip()
def create_extensions():
sourcefiles = [
'pynvvl/_nvvl.pyx',
]
# List up include paths
include_dirs = [
os.path.join(os.getcwd(), 'docker/include'),
'/usr/local/cuda/include',
sysconfig.get_config_var('INCLUDEPY'),
]
if 'CPATH' in os.environ:
include_dirs.insert(1, os.environ['CPATH'])
# List up library paths
library_dirs = [
os.path.join(os.getcwd(), 'docker/lib/cuda-{}'.format(CUDA_VERSION)),
]
if 'LD_LIBRARY_PATH' in os.environ:
library_dirs.append(os.environ['LD_LIBRARY_PATH'])
if 'LIBRARY_PATH' in os.environ:
library_dirs.append(os.environ['LIBRARY_PATH'])
# List up libraries
libraries = [
'nvvl',
]
# RPATH which will be set to pynvvl.so
rpath = [
'$ORIGIN/_lib',
]
extensions = [
Extension(
'pynvvl._nvvl',
sourcefiles,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
language='c++',
extra_compile_args=['-std=c++11'],
extra_link_args=['-std=c++11'],
runtime_library_dirs=rpath,
)
]
return extensions
def find_lib_from_pathlist(libname, pathlists, **kwargs):
"""Find library file from a list of paths"""
include_ver_variants = kwargs.pop('include_ver_variants', True)
include_library_path = kwargs.pop('include_library_path', True)
# pathlists is a list of strings (e.g. LIBRARY_PATH) or lists of paths
# so path_lists is a flattened list of directory paths
path_list = []
for lst in pathlists:
if type(lst) is str:
lst = re.split(r':', lst)
path_list += lst
if include_library_path:
path_list += re.split(r':', os.environ.get('LIBRARY_PATH') or "")
for path in path_list:
try:
files = os.listdir(path)
except IOError:
continue
if libname in files:
return os.path.join(path, libname)
if include_ver_variants:
regexp = re.escape(libname) + r'\.\d+$'
libs = [f for f in files if re.match(regexp, f)]
if len(libs) > 0:
return os.path.join(path, libs[0])
raise RuntimeError("Cannot find a library '{}' "
"in the specified paths".format(libname))
def prepare_package_data():
lib_names = [
'libnvvl.so',
'libavformat.so.57',
'libavfilter.so.6',
'libavcodec.so.57',
'libavutil.so.55',
]
docker_lib_dir = 'docker/lib/cuda-{}'.format(CUDA_VERSION)
wheel_libs = [find_lib_from_pathlist(l, [docker_lib_dir]) for l in lib_names]
lib_dir = 'pynvvl/_lib'
if not os.path.exists(lib_dir):
os.makedirs(lib_dir)
libs = []
for lib in wheel_libs:
libname = os.path.basename(lib)
libpath = os.path.join(lib_dir, libname)
shutil.copy2(lib, libpath)
libs.append(os.path.join('_lib', libname))
package_data = {
'pynvvl': libs
}
return package_data
parser = argparse.ArgumentParser()
parser.add_argument('--package-name', type=str, default='pynvvl')
args, sys.argv = parser.parse_known_args(sys.argv)
package_data = prepare_package_data()
extensions = create_extensions()
cupy_package_name = None
try:
cupy_package_name = get_distribution(
'cupy-cuda{}'.format(CUDA_VERSION.replace('.', '')))
cupy_package_name = cupy_package_name.project_name
except Exception:
cupy_package_name = 'cupy'
print('=' * 30)
print('CuPy Package Name:', cupy_package_name)
print('=' * 30)
description = \
'PyNVVL: A Python wrapper for NVIDIA Video Loader (NVVL) with CuPy'
setup(
name=args.package_name,
url='https://github.com/mitmul/pynvvl',
version='0.0.3a2',
author='Shunta Saito',
author_email='[email protected]',
description=description,
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
license='MIT License',
packages=['pynvvl'],
package_data=package_data,
install_requires=[
'{}>=4.5.0'.format(cupy_package_name),
],
setup_requires=[
'cython>=0.28.0',
],
ext_modules=extensions,
cmdclass={'build_ext': build_ext},
)