"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "08cc36ddff49f97b5c9e34af9d96d24aef847ef2"
setup.py 4.27 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 platform.system() == 'Darwin'
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
38
39
    return libs, version

LIBS, VERSION = get_lib_path()

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
def config_cython():
    """Try to configure cython and return cython configuration"""
    if os.name == 'nt':
        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"
        if os.name == 'nt':
            library_dirs = ['dgl', '../build/Release', '../build']
            libraries = ['libtvm']
        else:
            library_dirs = None
            libraries = None
        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++"))
        return cythonize(ret)
    except ImportError:
        print("WARNING: Cython is not installed, will compile without cython module")
        return []

Minjie Wang's avatar
Minjie Wang committed
83
84
include_libs = False
wheel_include_libs = False
Gan Quan's avatar
Gan Quan committed
85
86
87
88
if "bdist_wheel" in sys.argv or os.getenv('CONDA_BUILD'):
    wheel_include_libs = True
else:
    include_libs = True
Minjie Wang's avatar
Minjie Wang committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

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'))
            _, libname = os.path.split(path)
            fo.write("include dgl/%s\n" % libname)
    setup_kwargs = {
        "include_package_data": True
    }

# For source tree setup
Gan Quan's avatar
Gan Quan committed
104
# Conda build also includes the binary library
Minjie Wang's avatar
Minjie Wang committed
105
106
107
108
109
110
111
112
if include_libs:
    rpath = [os.path.relpath(path, CURRENT_DIR) for path in LIBS]
    setup_kwargs = {
        "include_package_data": True,
        "data_files": [('dgl', rpath)]
    }

setup(
Minjie Wang's avatar
Minjie Wang committed
113
    name='dgl',
Minjie Wang's avatar
Minjie Wang committed
114
    version=VERSION,
Minjie Wang's avatar
Minjie Wang committed
115
    description='Deep Graph Library',
Minjie Wang's avatar
Minjie Wang committed
116
    zip_safe=False,
Minjie Wang's avatar
Minjie Wang committed
117
118
    maintainer='DGL Team',
    maintainer_email='wmjlyjemaine@gmail.com',
Minjie Wang's avatar
Minjie Wang committed
119
    packages=find_packages(),
Minjie Wang's avatar
Minjie Wang committed
120
121
122
123
124
    install_requires=[
        'numpy>=1.14.0',
        'scipy>=1.1.0',
        'networkx>=2.1',
    ],
Minjie Wang's avatar
Minjie Wang committed
125
    url='https://github.com/dmlc/dgl',
Minjie Wang's avatar
Minjie Wang committed
126
    distclass=BinaryDistribution,
127
    ext_modules=config_cython(),
Minjie Wang's avatar
Minjie Wang committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Programming Language :: Python :: 3',
        'License :: OSI Approved :: Apache Software License',
    ],
    license='APACHE',
    **setup_kwargs
)

if wheel_include_libs:
    # Wheel cleanup
    os.remove("MANIFEST.in")
    for path in LIBS:
        _, libname = os.path.split(path)
        os.remove("dgl/%s" % libname)