1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#===============================================================================
5# Copyright (c) 2012 - 2014, GPy authors (see AUTHORS.txt).
6# Copyright (c) 2014, James Hensman, Max Zwiessele
7# Copyright (c) 2015, Max Zwiessele
8#
9# All rights reserved.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions are met:
13#
14# * Redistributions of source code must retain the above copyright notice, this
15#   list of conditions and the following disclaimer.
16#
17# * Redistributions in binary form must reproduce the above copyright notice,
18#   this list of conditions and the following disclaimer in the documentation
19#   and/or other materials provided with the distribution.
20#
21# * Neither the name of GPy nor the names of its
22#   contributors may be used to endorse or promote products derived from
23#   this software without specific prior written permission.
24#
25# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#===============================================================================
36
37from __future__ import print_function
38import os
39import sys
40from setuptools import setup, Extension
41import codecs
42
43try:
44    ModuleNotFoundError
45except NameError:
46    ModuleNotFoundError = ImportError
47
48def read(fname):
49    with codecs.open(fname, 'r', 'latin') as f:
50        return f.read()
51
52def read_to_rst(fname):
53    try:
54        import pypandoc
55        rstname = "{}.{}".format(os.path.splitext(fname)[0], 'rst')
56        pypandoc.convert(read(fname), 'rst', format='md', outputfile=rstname)
57        with open(rstname, 'r') as f:
58            rststr = f.read()
59        return rststr
60        #return read(rstname)
61    except ImportError:
62        return read(fname)
63
64desc = """
65
66Please refer to the github homepage for detailed instructions on installation and usage.
67
68"""
69
70version_dummy = {}
71exec(read('GPy/__version__.py'), version_dummy)
72__version__ = version_dummy['__version__']
73del version_dummy
74
75#Mac OS X Clang doesn't support OpenMP at the current time.
76#This detects if we are building on a Mac
77def ismac():
78    return sys.platform[:6] == 'darwin'
79
80if ismac():
81    compile_flags = [ '-O3', ]
82    link_args = []
83else:
84    compile_flags = [ '-fopenmp', '-O3']
85    link_args = ['-lgomp' ]
86
87try:
88    # So that we don't need numpy installed to determine it's a dependency.
89    import numpy as np
90
91    ext_mods = [Extension(name='GPy.kern.src.stationary_cython',
92                          sources=['GPy/kern/src/stationary_cython.pyx',
93                                   'GPy/kern/src/stationary_utils.c'],
94                          include_dirs=[np.get_include(), '.'],
95                          extra_compile_args=compile_flags,
96                          extra_link_args=link_args),
97                Extension(name='GPy.util.choleskies_cython',
98                          sources=['GPy/util/choleskies_cython.pyx'],
99                          include_dirs=[np.get_include(), '.'],
100                          extra_link_args=link_args,
101                          extra_compile_args=compile_flags),
102                Extension(name='GPy.util.linalg_cython',
103                          sources=['GPy/util/linalg_cython.pyx'],
104                          include_dirs=[np.get_include(), '.'],
105                          extra_compile_args=compile_flags,
106                          extra_link_args=link_args),
107                Extension(name='GPy.kern.src.coregionalize_cython',
108                          sources=['GPy/kern/src/coregionalize_cython.pyx'],
109                          include_dirs=[np.get_include(), '.'],
110                          extra_compile_args=compile_flags,
111                          extra_link_args=link_args),
112                Extension(name='GPy.models.state_space_cython',
113                          sources=['GPy/models/state_space_cython.pyx'],
114                          include_dirs=[np.get_include(), '.'],
115                          extra_compile_args=compile_flags,
116                          extra_link_args=link_args)]
117except ModuleNotFoundError:
118    ext_mods = []
119
120install_requirements = ['numpy>=1.7', 'six', 'paramz>=0.9.0', 'cython>=0.29']
121if sys.version_info < (3, 6):
122    install_requirements += ['scipy>=1.3.0,<1.5.0']
123else:
124    install_requirements += ['scipy>=1.3.0']
125
126setup(name = 'GPy',
127      version = __version__,
128      author = read_to_rst('AUTHORS.txt'),
129      author_email = "gpy.authors@gmail.com",
130      description = ("The Gaussian Process Toolbox"),
131      long_description = desc,
132      license = "BSD 3-clause",
133      keywords = "machine-learning gaussian-processes kernels",
134      url = "http://sheffieldml.github.com/GPy/",
135      download_url='https://github.com/SheffieldML/GPy/',
136      ext_modules = ext_mods,
137      packages = ["GPy",
138                  "GPy.core",
139                  "GPy.core.parameterization",
140                  "GPy.kern",
141                  "GPy.kern.src",
142                  "GPy.kern.src.psi_comp",
143                  "GPy.models",
144                  "GPy.inference",
145                  "GPy.inference.optimization",
146                  "GPy.inference.mcmc",
147                  "GPy.inference.latent_function_inference",
148                  "GPy.likelihoods",
149                  "GPy.mappings",
150                  "GPy.examples",
151                  "GPy.testing",
152                  "GPy.util",
153                  "GPy.plotting",
154                  "GPy.plotting.gpy_plot",
155                  "GPy.plotting.matplot_dep",
156                  "GPy.plotting.matplot_dep.controllers",
157                  "GPy.plotting.plotly_dep",
158                  ],
159      package_dir={'GPy': 'GPy'},
160      #package_data = {'GPy': ['defaults.cfg', 'installation.cfg',
161      #                        'util/data_resources.json',
162      #                        'util/football_teams.json',
163      #                        'testing/plotting_tests/baseline/*.png'
164      #                        ]},
165      #data_files=[('GPy/testing/plotting_tests/baseline', 'testing/plotting_tests/baseline/*.png'),
166      #            ('GPy/testing/', 'GPy/testing/pickle_test.pickle'),
167      #             ],
168      include_package_data = True,
169      py_modules = ['GPy.__init__'],
170      test_suite = 'GPy.testing',
171      setup_requires = ['numpy>=1.7'],
172      install_requires = install_requirements,
173      extras_require = {'docs':['sphinx'],
174                        'optional':['mpi4py',
175                                    'ipython>=4.0.0',
176                                    ],
177                        'plotting':['matplotlib >= 3.0',
178                                    'plotly >= 1.8.6'],
179                        'notebook':['jupyter_client >= 4.0.6',
180                                    'ipywidgets >= 4.0.3',
181                                    'ipykernel >= 4.1.0',
182                                    'notebook >= 4.0.5',
183                                    ],
184                        },
185      classifiers=['License :: OSI Approved :: BSD License',
186                   'Natural Language :: English',
187                   'Operating System :: MacOS :: MacOS X',
188                   'Operating System :: Microsoft :: Windows',
189                   'Operating System :: POSIX :: Linux',
190                   'Programming Language :: Python :: 3.5',
191                   'Programming Language :: Python :: 3.6',
192                   'Programming Language :: Python :: 3.7',
193                   'Programming Language :: Python :: 3.8',
194                   'Programming Language :: Python :: 3.9',
195                   'Framework :: IPython',
196                   'Intended Audience :: Science/Research',
197                   'Intended Audience :: Developers',
198                   'Topic :: Software Development',
199                   'Topic :: Software Development :: Libraries :: Python Modules',
200
201                   ]
202      )
203
204
205# Check config files and settings:
206local_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'GPy', 'installation.cfg'))
207home = os.getenv('HOME') or os.getenv('USERPROFILE')
208user_file = os.path.join(home,'.config', 'GPy', 'user.cfg')
209
210print("")
211try:
212    if not os.path.exists(user_file):
213        # Does an old config exist?
214        old_user_file = os.path.join(home,'.gpy_user.cfg')
215        if os.path.exists(old_user_file):
216            # Move it to new location:
217            print("GPy: Found old config file, moving to new location {}".format(user_file))
218            if not os.path.exists(os.path.dirname(user_file)):
219                os.makedirs(os.path.dirname(user_file))
220            os.rename(old_user_file, user_file)
221        else:
222            # No config file exists, save informative stub to user config folder:
223            print("GPy: Saving user configuration file to {}".format(user_file))
224            if not os.path.exists(os.path.dirname(user_file)):
225                os.makedirs(os.path.dirname(user_file))
226            with open(user_file, 'w') as f:
227                with open(local_file, 'r') as l:
228                    tmp = l.read()
229                    f.write(tmp)
230    else:
231        print("GPy: User configuration file at location {}".format(user_file))
232except:
233    print("GPy: Could not write user configuration file {}".format(user_file))
234