2015-09-28 19:56:37 -07:00
# pylint: disable=invalid-name, exec-used
""" Setup mxnet package. """
2015-08-05 22:51:03 -06:00
from __future__ import absolute_import
2016-09-08 19:10:58 -07:00
import os
import sys
2016-09-07 22:49:04 -07:00
# need to use distutils.core for correct placement of cython dll
2017-05-23 09:04:37 -07:00
kwargs = { }
2016-11-20 22:23:15 -08:00
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
2017-05-23 09:04:37 -07:00
kwargs = { ' install_requires ' : [ ' numpy ' ] , ' zip_safe ' : False }
if ' --with-cython ' in sys . argv :
with_cython = True
sys . argv . remove ( ' --with-cython ' )
2015-08-05 22:51:03 -06:00
2015-09-28 19:56:37 -07:00
# We can not import `mxnet.info.py` in setup.py directly since mxnet/__init__.py
# Will be invoked which introduces dependences
CURRENT_DIR = os . path . dirname ( __file__ )
libinfo_py = os . path . join ( CURRENT_DIR , ' mxnet/libinfo.py ' )
libinfo = { ' __file__ ' : libinfo_py }
exec ( compile ( open ( libinfo_py , " rb " ) . read ( ) , libinfo_py , ' exec ' ) , libinfo , libinfo )
LIB_PATH = libinfo [ ' find_lib_path ' ] ( )
__version__ = libinfo [ ' __version__ ' ]
2015-08-05 22:51:03 -06:00
2016-09-18 00:34:46 +08:00
2016-09-07 16:08:55 -07:00
def config_cython ( ) :
2017-01-18 18:51:32 -08:00
""" Try to configure cython and return cython configuration """
2017-05-23 09:04:37 -07:00
if not with_cython :
return [ ]
2017-02-24 09:21:33 -08:00
# pylint: disable=unreachable
2017-01-18 18:51:32 -08:00
if os . name == ' nt ' :
print ( " WARNING: Cython is not supported on Windows, will compile without cython module " )
return [ ]
2016-09-07 16:08:55 -07:00
try :
from Cython . Build import cythonize
2016-09-18 00:34:46 +08:00
# from setuptools.extension import Extension
2016-09-07 16:08:55 -07:00
if sys . version_info > = ( 3 , 0 ) :
subdir = " _cy3 "
else :
subdir = " _cy2 "
ret = [ ]
path = " mxnet/cython "
2016-09-18 00:34:46 +08:00
if os . name == ' nt ' :
2016-12-23 16:43:01 +08:00
library_dirs = [ ' mxnet ' , ' ../build/Release ' , ' ../build ' ]
2016-09-18 00:34:46 +08:00
libraries = [ ' libmxnet ' ]
else :
library_dirs = None
libraries = None
2016-09-07 16:08:55 -07:00
for fn in os . listdir ( path ) :
if not fn . endswith ( " .pyx " ) :
continue
ret . append ( Extension (
2016-09-15 01:36:37 +08:00
" mxnet/ %s /. %s " % ( subdir , fn [ : - 4 ] ) ,
2016-09-07 16:08:55 -07:00
[ " mxnet/cython/ %s " % fn ] ,
include_dirs = [ " ../include/ " , " ../nnvm/include " ] ,
2016-09-18 00:34:46 +08:00
library_dirs = library_dirs ,
libraries = libraries ,
2016-09-07 16:08:55 -07:00
language = " c++ " ) )
return cythonize ( ret )
2016-09-07 22:49:04 -07:00
except ImportError :
2016-09-07 16:08:55 -07:00
print ( " WARNING: Cython is not installed, will compile without cython module " )
return [ ]
2016-09-18 00:34:46 +08:00
2015-08-05 22:51:03 -06:00
setup ( name = ' mxnet ' ,
2015-09-28 19:56:37 -07:00
version = __version__ ,
description = open ( os . path . join ( CURRENT_DIR , ' README.md ' ) ) . read ( ) ,
2016-09-10 12:13:13 -04:00
packages = [
2017-02-04 14:02:36 -08:00
' mxnet ' , ' mxnet.module ' , ' mxnet._ctypes ' , ' mxnet.rnn ' ,
2017-03-21 11:37:53 -07:00
' mxnet._cy2 ' , ' mxnet._cy3 ' , ' mxnet.notebook ' , ' mxnet.contrib '
2016-09-10 12:13:13 -04:00
] ,
2015-08-05 22:51:03 -06:00
data_files = [ ( ' mxnet ' , [ LIB_PATH [ 0 ] ] ) ] ,
2016-09-07 16:08:55 -07:00
url = ' https://github.com/dmlc/mxnet ' ,
2017-05-23 09:04:37 -07:00
ext_modules = config_cython ( ) ,
* * kwargs )