If you are using GitLab outside of the ILL, then you will need to use HTTPS and not SSH for clone/push/pull operations. If you are using the VPN, then SSH will work normally.

setup.py 11.3 KB
Newer Older
eric pellegrini's avatar
eric pellegrini committed
1 2 3
import fnmatch
import glob
import os
4
import subprocess
eric pellegrini's avatar
eric pellegrini committed
5 6 7 8
import sys

import numpy

eric pellegrini's avatar
eric pellegrini committed
9
from Cython.Distutils import build_ext as cython_build_ext
eric pellegrini's avatar
eric pellegrini committed
10 11

from distutils.command.build import build
eric pellegrini's avatar
eric pellegrini committed
12
from distutils.core import setup, Extension
eric pellegrini's avatar
eric pellegrini committed
13 14 15
from distutils.sysconfig import get_config_vars
from distutils.util import convert_path

eric pellegrini's avatar
eric pellegrini committed
16 17 18 19 20 21 22 23 24 25
try:
    import sphinx
except ImportError:
    sphinx = None

try:
    import stdeb
except ImportError:
    stdeb = None

eric pellegrini's avatar
eric pellegrini committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#################################
# Modules variables
#################################
EXCLUDE = ['*.py', '*.pyc', '*$py.class', '*~', '.*', '*.bak', '*.so', '*.pyd']

EXCLUDE_DIRECTORIES = ('.*', 'CVS', '_darcs', './build','*svn','./dist', 'EGG-INFO', '*.egg-info')

EXTENSIONS_PATH = "Extensions"

INCLUDE_DIR = [numpy.get_include()]

QHULL_DIR = os.path.join("Extensions","qhull_lib")

QHULL_INCLUDE_DIR = INCLUDE_DIR + [EXTENSIONS_PATH] + [os.path.join(QHULL_DIR,"ext")] + [os.path.join(QHULL_DIR,"src")]

#################################
# Helper function
#################################

def is_package(path):
    return (os.path.isdir(path) and os.path.isfile(os.path.join(path, '__init__.py')))

48
def find_packages(path, base=None, exclude=None):
eric pellegrini's avatar
eric pellegrini committed
49

50 51 52 53 54 55 56 57
    packages = []

    for root,dirs,files in os.walk(path):
        if "__init__.py" in files:
            if base is not None:
                root = root.replace(path,base)
            package = root.replace(os.sep,".")
            packages.append(package)
eric pellegrini's avatar
eric pellegrini committed
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

    return packages

def find_package_data(where='.', package='', exclude=EXCLUDE, exclude_directories=EXCLUDE_DIRECTORIES, only_in_packages=True, show_ignored=False):
    
    out = {}
    stack = [(convert_path(where), '', package, only_in_packages)]
    while stack:
        where, prefix, package, only_in_packages = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where, name)
            if os.path.isdir(fn):
                bad_name = False
                for pattern in exclude_directories:
                    if (fnmatch.fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, ("Directory %s ignored by pattern %s" % (fn, pattern))
                        break
                if bad_name:
                    continue
                if (os.path.isfile(os.path.join(fn, '__init__.py')) and not prefix):
                    if not package:
                        new_package = name
                    else:
                        new_package = package + '.' + name
                    stack.append((fn, '', new_package, False))
                else:
                    stack.append((fn, prefix + name + '/', package, only_in_packages))
            elif package or not only_in_packages:
                # is a file
                bad_name = False
                for pattern in exclude:
                    if (fnmatch.fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, ("File %s ignored by pattern %s" % (fn, pattern))
                        break
                if bad_name:
                    continue
                out.setdefault(package, []).append(prefix+name)
    
    return out


def find_data(where=".", exclude=EXCLUDE, exclude_directories=EXCLUDE_DIRECTORIES, prefix=""):

    out = {}
    stack = [convert_path(where)]
    while stack:
        where = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where, name)
            d = os.path.join(prefix,os.path.dirname(fn))
            if os.path.isdir(fn):
                stack.append(fn)
            else:
                bad_name = False
                for pattern in exclude:
                    if (fnmatch.fnmatchcase(name, pattern) or fn.lower() == pattern.lower()):
                        bad_name = True
                        break
                if bad_name:
                    continue
                out.setdefault(d, []).append(fn)
            
    out = [(k,v) for k, v in out.items()]
    
    return out


#################################
# Packages section
#################################

PACKAGE_INFO = {}
136
execfile('Src/__pkginfo__.py', {}, PACKAGE_INFO)
eric pellegrini's avatar
eric pellegrini committed
137

138
PACKAGES = find_packages(path="Src",base="MDANSE")
eric pellegrini's avatar
eric pellegrini committed
139 140 141 142 143

#################################
# Package data section
#################################

144
# Retrieve all the data related to the MDANSE package.
145
PACKAGE_DATA = find_package_data(where='Src', package='MDANSE', show_ignored=False)
eric pellegrini's avatar
eric pellegrini committed
146 147 148 149 150 151

#################################
# User data section
#################################

DATA_FILES = []
eric pellegrini's avatar
eric pellegrini committed
152
DATA_FILES.extend(find_data('Doc',exclude=[],prefix='conf_'))
eric pellegrini's avatar
eric pellegrini committed
153 154 155 156 157

#################################
# Scripts section
#################################

158 159
SCRIPTS_PATH = "Scripts"
SCRIPTS = glob.glob(os.path.join(SCRIPTS_PATH,'mdanse*'))
eric pellegrini's avatar
eric pellegrini committed
160

161 162 163 164
#################################
# Documentation
#################################

eric pellegrini's avatar
eric pellegrini committed
165
if sphinx:
166

167
    import sphinx.setup_command
168 169 170 171 172 173

    try:
        from sphinx.ext.apidoc import main as sphinx_apidoc_main
    except ImportError:
        from sphinx.apidoc import main as sphinx_apidoc_main

eric pellegrini's avatar
eric pellegrini committed
174
    class mdanse_build_doc(sphinx.setup_command.BuildDoc):
175

eric pellegrini's avatar
eric pellegrini committed
176 177 178
        def run(self):
            
            build = self.get_finalized_command('build')
179

eric pellegrini's avatar
eric pellegrini committed
180
            buildDir = os.path.abspath(build.build_lib)
181

182 183 184
            if not os.path.exists(buildDir):
                raise IOError("build command must be performed prior building the doc")

eric pellegrini's avatar
eric pellegrini committed
185
            sys.path.insert(0,buildDir)
186

187 188 189 190
            sphinxDir = os.path.abspath(os.path.join(build.build_base,'sphinx',self.doctype))

            if not os.path.exists(sphinxDir):
                os.mkdir(sphinxDir)
eric pellegrini's avatar
eric pellegrini committed
191 192
                                 
            metadata = self.distribution.metadata
193
            args = ["-F",
194 195 196 197 198 199 200 201
                    "--separate",
                    "-H%s" % metadata.name,
                    "-A%s" % metadata.author,
                    "-R%s" % metadata.version,
                    "-o%s" % sphinxDir,
                    os.path.join(buildDir,'MDANSE'),
                    os.path.join(buildDir,'MDANSE','Externals')]

202 203 204 205 206 207

            # /!\ apidoc.main is deprecated. The API has been broken in sphinx 1.7.0, see https://github.com/sphinx-doc/sphinx/issues/4615
            if int(sphinx.__version__.split(".")[1]) <= 6:
                args.insert(0,"")

            sphinx_apidoc_main(args)
208 209
                             
            currentDirectory = os.getcwd()
210
            
eric pellegrini's avatar
eric pellegrini committed
211
            import shutil
212 213 214
            shutil.copy(os.path.join(currentDirectory,'Doc','conf_%s.py' % self.doctype),os.path.join(sphinxDir,'conf.py'))
            shutil.copy(os.path.join(currentDirectory,'Doc','mdanse_logo.png'),os.path.join(sphinxDir,'_static'))
            shutil.copy(os.path.join(currentDirectory,'Doc','layout.html'),os.path.join(sphinxDir,'_templates'))
eric pellegrini's avatar
eric pellegrini committed
215 216 217 218 219 220 221 222 223
     
            # The directory where the rst files are located.
            self.source_dir = sphinxDir
            # The directory where the conf.py file is located.
            self.config_dir = self.source_dir
     
            # The directory where the documentation will be built
            self.build_dir = os.path.join(buildDir,'MDANSE','Doc',self.doctype)
            
224 225 226 227 228 229 230
            if isinstance(self.builder,basestring):
                builders = [self.builder]
            else:
                builders = self.builder

            for builder in builders:
                self.builder_target_dir = os.path.join(self.build_dir, builder)
231
                sphinx.setup_command.BuildDoc.finalize_options(self)
232
                sphinx.setup_command.BuildDoc.run(self)
eric pellegrini's avatar
eric pellegrini committed
233 234 235 236
                 
            sys.path.pop(0)
            
    class mdanse_build_help(mdanse_build_doc):
237
        
eric pellegrini's avatar
eric pellegrini committed
238
        doctype = 'help'
239

eric pellegrini's avatar
eric pellegrini committed
240
    class mdanse_build_api(mdanse_build_doc):
241
        
eric pellegrini's avatar
eric pellegrini committed
242 243
        doctype = 'api'
                        
eric pellegrini's avatar
eric pellegrini committed
244 245 246 247 248 249 250 251
#################################
# Extensions section
#################################

if 'linux' in sys.platform:
    (opt,) = get_config_vars('OPT')
    os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes')

252
EXTENSIONS = [Extension('MDANSE.Extensions.distance_histogram',
eric pellegrini's avatar
eric pellegrini committed
253 254
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'distance_histogram.pyx')]),
255
              Extension('MDANSE.Extensions.fast_calculation',
eric pellegrini's avatar
eric pellegrini committed
256 257
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'fast_calculation.pyx')]),
258
              Extension('MDANSE.Extensions.sas_fast_calc',
eric pellegrini's avatar
eric pellegrini committed
259 260
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'sas_fast_calc.pyx')]),
261
              Extension('MDANSE.Extensions.mt_fast_calc',
eric pellegrini's avatar
eric pellegrini committed
262 263
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'mt_fast_calc.pyx')]),
264
              Extension('MDANSE.Extensions.sd_fast_calc',
eric pellegrini's avatar
eric pellegrini committed
265 266
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'sd_fast_calc.pyx')]),
267
              Extension('MDANSE.Extensions.mic_fast_calc', 
eric pellegrini's avatar
eric pellegrini committed
268 269 270
                        include_dirs=INCLUDE_DIR,
                        sources = [os.path.join("Extensions",'mic_fast_calc.pyx')],
                        language="c++"),
271
              Extension('MDANSE.Extensions.qhull',
eric pellegrini's avatar
eric pellegrini committed
272 273
                        include_dirs  = QHULL_INCLUDE_DIR,
                        sources =  glob.glob(os.path.join(QHULL_DIR, 'src','*.c')) + [os.path.join("Extensions",'qhull.pyx')],
274 275
                        define_macros = [('qh_QHpointer','1')]),
              Extension('MDANSE.Extensions.xtc',
276
                        include_dirs=[numpy.get_include(),os.path.join('Extensions','xtc','include')],
277
                        sources=glob.glob(os.path.join('Extensions','xtc','src','*.c')) + [os.path.join('Extensions','xtc','xtc.pyx')])
eric pellegrini's avatar
eric pellegrini committed
278 279
              ]

280
CMDCLASS = {'build_ext' : cython_build_ext}
eric pellegrini's avatar
eric pellegrini committed
281

eric pellegrini's avatar
eric pellegrini committed
282 283 284
if sphinx:
    CMDCLASS['build_api'] = mdanse_build_api
    CMDCLASS['build_help'] = mdanse_build_help
eric pellegrini's avatar
eric pellegrini committed
285 286 287 288 289
             
#################################
# The setup section
#################################

290
setup (name             = "MDANSE",
eric pellegrini's avatar
eric pellegrini committed
291
       version          = PACKAGE_INFO["__version__"],
292 293 294 295 296 297 298 299
       description      = PACKAGE_INFO["__description__"],
       long_description = PACKAGE_INFO["__long_description__"],
       author           = PACKAGE_INFO["__author__"],
       author_email     = PACKAGE_INFO["__author_email__"],
       maintainer       = PACKAGE_INFO["__maintainer__"],
       maintainer_email = PACKAGE_INFO["__maintainer_email__"],
       url              = PACKAGE_INFO["__url__"],
       license          = PACKAGE_INFO["__license__"],
eric pellegrini's avatar
eric pellegrini committed
300 301
       packages         = PACKAGES,
       package_data     = PACKAGE_DATA,
302
       package_dir      = {"MDANSE":"Src"},
eric pellegrini's avatar
eric pellegrini committed
303 304 305 306
       data_files       = DATA_FILES,
       platforms        = ['Unix','Windows'],
       ext_modules      = EXTENSIONS,
       scripts          = SCRIPTS,
307
       cmdclass         = CMDCLASS)