|
| 1 | +import sys |
| 2 | +import os |
| 3 | +from collections import OrderedDict |
| 4 | + |
| 5 | +try: |
| 6 | + from distutils.core import setup |
| 7 | + from distutils.extension import Extension |
| 8 | +except ImportError: |
| 9 | + print("The distutils package is required to build or install RMG Py.") |
| 10 | + raise |
| 11 | + |
| 12 | +try: |
| 13 | + from Cython.Build import cythonize |
| 14 | + from Cython.Compiler import Options |
| 15 | +except ImportError: |
| 16 | + print("Cython (http://www.cython.org/) is required to build or install RMG Py.") |
| 17 | + raise |
| 18 | + |
| 19 | +try: |
| 20 | + import numpy |
| 21 | +except ImportError: |
| 22 | + print("NumPy (http://numpy.scipy.org/) is required to build or install RMG Py.") |
| 23 | + raise |
| 24 | + |
| 25 | +# Create annotated HTML files for each of the Cython modules |
| 26 | +Options.annotate = True |
| 27 | + |
| 28 | +directives = { |
| 29 | + # Set input language version to python 3 |
| 30 | + "language_level": 3, |
| 31 | + # Turn on profiling capacity for all Cython modules |
| 32 | + # 'profile': True, |
| 33 | + # Embed call signatures in cythonized files - enable when building documentation |
| 34 | + # 'embedsignature': True, |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +main_ext_modules = [ |
| 39 | + # Molecules and molecular representations |
| 40 | + Extension( |
| 41 | + "rmgpy.molecule.atomtype", |
| 42 | + ["rmgpy/molecule/atomtype.py"], |
| 43 | + include_dirs=["."], |
| 44 | + ), |
| 45 | + Extension( |
| 46 | + "rmgpy.molecule.element", |
| 47 | + ["rmgpy/molecule/element.py"], |
| 48 | + include_dirs=["."], |
| 49 | + ), |
| 50 | + Extension( |
| 51 | + "rmgpy.molecule.graph", |
| 52 | + ["rmgpy/molecule/graph.pyx"], |
| 53 | + include_dirs=["."], |
| 54 | + ), |
| 55 | + Extension( |
| 56 | + "rmgpy.molecule.group", |
| 57 | + ["rmgpy/molecule/group.py"], |
| 58 | + include_dirs=["."], |
| 59 | + ), |
| 60 | + Extension( |
| 61 | + "rmgpy.molecule.molecule", |
| 62 | + ["rmgpy/molecule/molecule.py"], |
| 63 | + include_dirs=["."], |
| 64 | + ), |
| 65 | + Extension( |
| 66 | + "rmgpy.molecule.symmetry", |
| 67 | + ["rmgpy/molecule/symmetry.py"], |
| 68 | + include_dirs=["."], |
| 69 | + ), |
| 70 | + Extension( |
| 71 | + "rmgpy.molecule.vf2", |
| 72 | + ["rmgpy/molecule/vf2.pyx"], |
| 73 | + include_dirs=["."], |
| 74 | + ), |
| 75 | + Extension( |
| 76 | + "rmgpy.molecule.converter", |
| 77 | + ["rmgpy/molecule/converter.py"], |
| 78 | + include_dirs=["."], |
| 79 | + ), |
| 80 | + Extension( |
| 81 | + "rmgpy.molecule.translator", |
| 82 | + ["rmgpy/molecule/translator.py"], |
| 83 | + include_dirs=["."], |
| 84 | + ), |
| 85 | + Extension( |
| 86 | + "rmgpy.molecule.util", |
| 87 | + ["rmgpy/molecule/util.py"], |
| 88 | + include_dirs=["."], |
| 89 | + ), |
| 90 | + Extension( |
| 91 | + "rmgpy.molecule.inchi", |
| 92 | + ["rmgpy/molecule/inchi.py"], |
| 93 | + include_dirs=["."], |
| 94 | + ), |
| 95 | + Extension( |
| 96 | + "rmgpy.molecule.resonance", |
| 97 | + ["rmgpy/molecule/resonance.py"], |
| 98 | + include_dirs=["."], |
| 99 | + ), |
| 100 | + Extension( |
| 101 | + "rmgpy.molecule.pathfinder", |
| 102 | + ["rmgpy/molecule/pathfinder.py"], |
| 103 | + include_dirs=["."], |
| 104 | + ), |
| 105 | + Extension( |
| 106 | + "rmgpy.molecule.kekulize", |
| 107 | + ["rmgpy/molecule/kekulize.pyx"], |
| 108 | + include_dirs=["."], |
| 109 | + ), |
| 110 | + Extension( |
| 111 | + "rmgpy.constants", |
| 112 | + ["rmgpy/constants.py"], |
| 113 | + include_dirs=["."], |
| 114 | + ), |
| 115 | + Extension( |
| 116 | + "rmgpy.quantity", |
| 117 | + ["rmgpy/quantity.py"], |
| 118 | + include_dirs=["."], |
| 119 | + ), |
| 120 | + Extension( |
| 121 | + "rmgpy.rmgobject", |
| 122 | + ["rmgpy/rmgobject.pyx"], |
| 123 | + ), |
| 124 | +] |
| 125 | + |
| 126 | +ext_modules = [] |
| 127 | +if "install" in sys.argv: |
| 128 | + # This is so users can still do simply `python setup.py install` |
| 129 | + ext_modules.extend(main_ext_modules) |
| 130 | +if "main" in sys.argv: |
| 131 | + # This is for `python setup.py build_ext main` |
| 132 | + sys.argv.remove("main") |
| 133 | + ext_modules.extend(main_ext_modules) |
| 134 | +if "minimal" in sys.argv: |
| 135 | + # This starts with the full install list, but removes anything that has a pure python mode |
| 136 | + # i.e. in only includes things whose source is .pyx |
| 137 | + sys.argv.remove("minimal") |
| 138 | + temporary_list = [] |
| 139 | + temporary_list.extend(main_ext_modules) |
| 140 | + for module in temporary_list: |
| 141 | + for source in module.sources: |
| 142 | + if os.path.splitext(source)[1] == ".pyx": |
| 143 | + ext_modules.append(module) |
| 144 | + |
| 145 | +# Remove duplicates while preserving order: |
| 146 | +ext_modules = list(OrderedDict.fromkeys(ext_modules)) |
| 147 | + |
| 148 | +scripts = [] |
| 149 | + |
| 150 | +modules = ["rmgpy.exceptions", "rmgpy.version"] |
| 151 | + |
| 152 | +__version__ = "1.0.0" |
| 153 | + |
| 154 | +import logging |
| 155 | + |
| 156 | +logging.error(ext_modules) |
| 157 | +# Initiate the build and/or installation |
| 158 | +setup( |
| 159 | + name="RMG-Py", |
| 160 | + version=__version__, |
| 161 | + description="Reaction Mechanism Generator", |
| 162 | + author="William H. Green and the RMG Team", |
| 163 | + |
| 164 | + url="http://reactionmechanismgenerator.github.io", |
| 165 | + packages=[ |
| 166 | + "rmgpy.molecule", |
| 167 | + ], |
| 168 | + py_modules=modules, |
| 169 | + scripts=scripts, |
| 170 | + ext_modules=cythonize( |
| 171 | + ext_modules, |
| 172 | + build_dir="build", |
| 173 | + compiler_directives=directives, |
| 174 | + ), |
| 175 | + include_dirs=[".", numpy.get_include()], |
| 176 | +) |
0 commit comments