1import warnings
2
3try:
4    from Cython.Distutils import build_ext
5    from setuptools import setup, Extension
6    HAVE_CYTHON = True
7except ImportError as e:
8    warnings.warn(e.args[0])
9    from setuptools import setup, Extension
10    from setuptools.command.build_ext import build_ext
11    HAVE_CYTHON = False
12
13
14class CustomBuildExtCommand(build_ext):
15    """build_ext command for use when numpy headers are needed."""
16
17    def run(self):
18
19        # Import numpy here, only when headers are needed
20        import numpy
21
22        # Add numpy headers to include_dirs
23        self.include_dirs.append(numpy.get_include())
24
25        # Call original build_ext command
26        build_ext.run(self)
27
28
29_hdbscan_tree = Extension('hdbscan._hdbscan_tree',
30                          sources=['hdbscan/_hdbscan_tree.pyx'])
31_hdbscan_linkage = Extension('hdbscan._hdbscan_linkage',
32                             sources=['hdbscan/_hdbscan_linkage.pyx'])
33_hdbscan_boruvka = Extension('hdbscan._hdbscan_boruvka',
34                             sources=['hdbscan/_hdbscan_boruvka.pyx'])
35_hdbscan_reachability = Extension('hdbscan._hdbscan_reachability',
36                                  sources=['hdbscan/_hdbscan_reachability.pyx'])
37_prediction_utils = Extension('hdbscan._prediction_utils',
38                              sources=['hdbscan/_prediction_utils.pyx'])
39dist_metrics = Extension('hdbscan.dist_metrics',
40                         sources=['hdbscan/dist_metrics.pyx'])
41
42
43def readme():
44    with open('README.rst') as readme_file:
45        return readme_file.read()
46
47def requirements():
48    # The dependencies are the same as the contents of requirements.txt
49    with open('requirements.txt') as f:
50        return [line.strip() for line in f if line.strip()]
51
52configuration = {
53    'name': 'hdbscan',
54    'version': '0.8.27',
55    'description': 'Clustering based on density with variable density clusters',
56    'long_description': readme(),
57    'classifiers': [
58        'Development Status :: 4 - Beta',
59        'Intended Audience :: Science/Research',
60        'Intended Audience :: Developers',
61        'License :: OSI Approved',
62        'Programming Language :: C',
63        'Programming Language :: Python',
64        'Topic :: Software Development',
65        'Topic :: Scientific/Engineering',
66        'Operating System :: Microsoft :: Windows',
67        'Operating System :: POSIX',
68        'Operating System :: Unix',
69        'Operating System :: MacOS',
70        'Programming Language :: Python :: 3.4',
71    ],
72    'keywords': 'cluster clustering density hierarchical',
73    'url': 'http://github.com/scikit-learn-contrib/hdbscan',
74    'maintainer': 'Leland McInnes',
75    'maintainer_email': 'leland.mcinnes@gmail.com',
76    'license': 'BSD',
77    'packages': ['hdbscan', 'hdbscan.tests'],
78    'install_requires': requirements(),
79    'ext_modules': [_hdbscan_tree,
80                    _hdbscan_linkage,
81                    _hdbscan_boruvka,
82                    _hdbscan_reachability,
83                    _prediction_utils,
84                    dist_metrics],
85    'cmdclass': {'build_ext': CustomBuildExtCommand},
86    'test_suite': 'nose.collector',
87    'tests_require': ['nose'],
88    'data_files': ('hdbscan/dist_metrics.pxd',)
89}
90
91if not HAVE_CYTHON:
92    warnings.warn('Due to incompatibilities with Python 3.7 hdbscan now'
93                  'requires Cython to be installed in order to build it')
94    raise ImportError('Cython not found! Please install cython and try again')
95
96setup(**configuration)
97