setup.py 2.42 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
3
import sys, os, platform
Minjie Wang's avatar
Minjie Wang committed
4
5
6
7
8
9
import shutil
import glob

from setuptools import find_packages
from setuptools.dist import Distribution
from setuptools import setup
Minjie Wang's avatar
Minjie Wang committed
10

Minjie Wang's avatar
Minjie Wang committed
11
12
class BinaryDistribution(Distribution):
    def has_ext_modules(self):
13
        return platform.system() == 'Darwin'
Minjie Wang's avatar
Minjie Wang committed
14
15
16
17
18
19
20
21
22
23
24

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
25
26
27
28

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

Minjie Wang's avatar
Minjie Wang committed
29
30
31
32
33
34
    return libs, version

LIBS, VERSION = get_lib_path()

include_libs = False
wheel_include_libs = False
Gan Quan's avatar
Gan Quan committed
35
36
37
38
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

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
54
# Conda build also includes the binary library
Minjie Wang's avatar
Minjie Wang committed
55
56
57
58
59
60
61
62
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
63
    name='dgl',
Minjie Wang's avatar
Minjie Wang committed
64
    version=VERSION,
Minjie Wang's avatar
Minjie Wang committed
65
    description='Deep Graph Library',
Minjie Wang's avatar
Minjie Wang committed
66
    zip_safe=False,
Minjie Wang's avatar
Minjie Wang committed
67
68
    maintainer='DGL Team',
    maintainer_email='wmjlyjemaine@gmail.com',
Minjie Wang's avatar
Minjie Wang committed
69
    packages=find_packages(),
Minjie Wang's avatar
Minjie Wang committed
70
71
72
73
74
    install_requires=[
        'numpy>=1.14.0',
        'scipy>=1.1.0',
        'networkx>=2.1',
    ],
Minjie Wang's avatar
Minjie Wang committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    url='https://github.com/jermainewang/dgl',
    distclass=BinaryDistribution,
    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)