"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "5e6417e9887be8f02ab5b4f5c548dff7f3a4c8f6"
setup.py 5.97 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
3
import sys, os, platform, sysconfig
Minjie Wang's avatar
Minjie Wang committed
4
5
6
7
8
import shutil
import glob

from setuptools import find_packages
from setuptools.dist import Distribution
9
10
11
12
13
14
15
16

# need to use distutils.core for correct placement of cython dll
if '--inplace' in sys.argv:
    from distutils.core import setup
    from distutils.extension import Extension
else:
    from setuptools import setup
    from setuptools.extension import Extension
Minjie Wang's avatar
Minjie Wang committed
17

Minjie Wang's avatar
Minjie Wang committed
18
19
class BinaryDistribution(Distribution):
    def has_ext_modules(self):
20
        return True
Minjie Wang's avatar
Minjie Wang committed
21
22
23
24
25
26
27
28
29
30
31

CURRENT_DIR = os.path.dirname(__file__)

def get_lib_path():
    """Get library path, name and version"""
     # We can not import `libinfo.py` in setup.py directly since __init__.py
    # Will be invoked which introduces dependences
    libinfo_py = os.path.join(CURRENT_DIR, './dgl/_ffi/libinfo.py')
    libinfo = {'__file__': libinfo_py}
    exec(compile(open(libinfo_py, "rb").read(), libinfo_py, 'exec'), libinfo, libinfo)
    version = libinfo['__version__']
Gan Quan's avatar
Gan Quan committed
32
33
34
35

    lib_path = libinfo['find_lib_path']()
    libs = [lib_path[0]]

Minjie Wang's avatar
Minjie Wang committed
36
37
    return libs, version

38
39
40
41
42
43
44
45
46
47
48
def get_ta_lib_pattern():
    if sys.platform.startswith('linux'):
        ta_lib_pattern = 'libtensoradapter_*.so'
    elif sys.platform.startswith('darwin'):
        ta_lib_pattern = 'libtensoradapter_*.dylib'
    elif sys.platform.startswith('win'):
        ta_lib_pattern = 'tensoradapter_*.dll'
    else:
        raise NotImplementedError('Unsupported system: %s' % sys.platform)
    return ta_lib_pattern

Minjie Wang's avatar
Minjie Wang committed
49
LIBS, VERSION = get_lib_path()
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
BACKENDS = ['pytorch']
TA_LIB_PATTERN = get_ta_lib_pattern()

def cleanup():
    # Wheel cleanup
    try:
        os.remove("MANIFEST.in")
    except:
        pass

    for path in LIBS:
        _, libname = os.path.split(path)
        try:
            os.remove(os.path.join("dgl", libname))
        except:
            pass
    for backend in BACKENDS:
        for ta_path in glob.glob(
            os.path.join(CURRENT_DIR, "dgl", "tensoradapter", backend, TA_LIB_PATTERN)):
            try:
                os.remove(ta_path)
            except:
                pass
Minjie Wang's avatar
Minjie Wang committed
73

74
75
def config_cython():
    """Try to configure cython and return cython configuration"""
76
    if sys.platform.startswith('win'):
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        print("WARNING: Cython is not supported on Windows, will compile without cython module")
        return []
    sys_cflags = sysconfig.get_config_var("CFLAGS")

    if "i386" in sys_cflags and "x86_64" in sys_cflags:
        print("WARNING: Cython library may not be compiled correctly with both i386 and x64")
        return []
    try:
        from Cython.Build import cythonize
        # from setuptools.extension import Extension
        if sys.version_info >= (3, 0):
            subdir = "_cy3"
        else:
            subdir = "_cy2"
        ret = []
        path = "dgl/_ffi/_cython"
93
94
        library_dirs = ['dgl', '../build/Release', '../build']
        libraries = ['dgl']
95
96
97
98
99
100
101
102
103
104
105
106
107
        for fn in os.listdir(path):
            if not fn.endswith(".pyx"):
                continue
            ret.append(Extension(
                "dgl._ffi.%s.%s" % (subdir, fn[:-4]),
                ["dgl/_ffi/_cython/%s" % fn],
                include_dirs=["../include/",
                              "../third_party/dmlc-core/include",
                              "../third_party/dlpack/include",
                ],
                library_dirs=library_dirs,
                libraries=libraries,
                language="c++"))
108
        return cythonize(ret, force=True)
109
110
111
112
    except ImportError:
        print("WARNING: Cython is not installed, will compile without cython module")
        return []

Minjie Wang's avatar
Minjie Wang committed
113
114
include_libs = False
wheel_include_libs = False
Gan Quan's avatar
Gan Quan committed
115
116
if "bdist_wheel" in sys.argv or os.getenv('CONDA_BUILD'):
    wheel_include_libs = True
117
118
elif "clean" in sys.argv:
    cleanup()
Gan Quan's avatar
Gan Quan committed
119
120
else:
    include_libs = True
Minjie Wang's avatar
Minjie Wang committed
121
122
123
124
125
126
127
128

setup_kwargs = {}

# For bdist_wheel only
if wheel_include_libs:
    with open("MANIFEST.in", "w") as fo:
        for path in LIBS:
            shutil.copy(path, os.path.join(CURRENT_DIR, 'dgl'))
129
            dir_, libname = os.path.split(path)
Minjie Wang's avatar
Minjie Wang committed
130
            fo.write("include dgl/%s\n" % libname)
131
132
133
134
135
136
137
138
139
140

        for backend in BACKENDS:
            for ta_path in glob.glob(os.path.join(dir_, "tensoradapter", backend, TA_LIB_PATTERN)):
                ta_name = os.path.basename(ta_path)
                os.makedirs(os.path.join(CURRENT_DIR, 'dgl', 'tensoradapter', backend), exist_ok=True)
                shutil.copy(
                    os.path.join(dir_, 'tensoradapter', backend, ta_name),
                    os.path.join(CURRENT_DIR, 'dgl', 'tensoradapter', backend))
                fo.write("include dgl/tensoradapter/%s/%s\n" % (backend, ta_name))

Minjie Wang's avatar
Minjie Wang committed
141
142
143
144
145
    setup_kwargs = {
        "include_package_data": True
    }

# For source tree setup
Gan Quan's avatar
Gan Quan committed
146
# Conda build also includes the binary library
Minjie Wang's avatar
Minjie Wang committed
147
148
if include_libs:
    rpath = [os.path.relpath(path, CURRENT_DIR) for path in LIBS]
149
150
151
152
153
154
155
156
    data_files = [('dgl', rpath)]
    for path in LIBS:
        for backend in BACKENDS:
            data_files.append((
                'dgl/tensoradapter/%s' % backend,
                glob.glob(os.path.join(
                    os.path.dirname(os.path.relpath(path, CURRENT_DIR)),
                    'tensoradapter', backend, TA_LIB_PATTERN))))
Minjie Wang's avatar
Minjie Wang committed
157
158
    setup_kwargs = {
        "include_package_data": True,
159
        "data_files": data_files
Minjie Wang's avatar
Minjie Wang committed
160
161
162
    }

setup(
163
    name='dgl' + os.getenv('DGL_PACKAGE_SUFFIX', ''),
Minjie Wang's avatar
Minjie Wang committed
164
    version=VERSION,
Minjie Wang's avatar
Minjie Wang committed
165
    description='Deep Graph Library',
Minjie Wang's avatar
Minjie Wang committed
166
    zip_safe=False,
Minjie Wang's avatar
Minjie Wang committed
167
168
    maintainer='DGL Team',
    maintainer_email='wmjlyjemaine@gmail.com',
Minjie Wang's avatar
Minjie Wang committed
169
    packages=find_packages(),
Minjie Wang's avatar
Minjie Wang committed
170
171
172
173
    install_requires=[
        'numpy>=1.14.0',
        'scipy>=1.1.0',
        'networkx>=2.1',
174
        'requests>=2.19.0',
Minjie Wang's avatar
Minjie Wang committed
175
    ],
Minjie Wang's avatar
Minjie Wang committed
176
    url='https://github.com/dmlc/dgl',
Minjie Wang's avatar
Minjie Wang committed
177
    distclass=BinaryDistribution,
178
    ext_modules=config_cython(),
Minjie Wang's avatar
Minjie Wang committed
179
180
181
182
183
184
185
186
187
188
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Programming Language :: Python :: 3',
        'License :: OSI Approved :: Apache Software License',
    ],
    license='APACHE',
    **setup_kwargs
)

if wheel_include_libs:
189
    cleanup()