File: setup.py

package info (click to toggle)
spglib 1.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,712 kB
  • sloc: ansic: 27,746; python: 5,784; ruby: 792; f90: 716; makefile: 97; sh: 69
file content (164 lines) | stat: -rw-r--r-- 5,226 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
import sys

try:
    from setuptools import setup, Extension
    from setuptools.command.build_ext import build_ext as _build_ext
    use_setuptools = True

    class build_ext(_build_ext):
        def finalize_options(self):
            _build_ext.finalize_options(self)
            # Prevent numpy from thinking it is still in its setup process:
            if sys.version_info[0] >= 3:
                import builtins
                if hasattr(builtins, '__NUMPY_SETUP__'):
                    del builtins.__NUMPY_SETUP__
                import importlib
                import numpy
                importlib.reload(numpy)

            else:
                import __builtin__
                if hasattr(__builtin__, '__NUMPY_SETUP__'):
                    del __builtin__.__NUMPY_SETUP__
                import imp
                import numpy
                imp.reload(numpy)
            self.include_dirs.append(numpy.get_include())
    print("setuptools is used.")
except ImportError:
    from distutils.core import setup, Extension
    use_setuptools = False
    print("distutils is used.")

    try:
        from numpy.distutils.misc_util import get_numpy_include_dirs
    except ImportError:
        print("numpy.distutils.misc_util cannot be imported. Please install "
              "numpy first before installing spglib...")
        sys.exit(1)

# Workaround Python issue 21121
import sysconfig
config_var = sysconfig.get_config_var("CFLAGS")
if (config_var is not None and
    "-Werror=declaration-after-statement" in config_var):
    os.environ['CFLAGS'] = config_var.replace(
        "-Werror=declaration-after-statement", "")

sources = ['arithmetic.c',
           'cell.c',
           'delaunay.c',
           'debug.c',
           'determination.c',
           'hall_symbol.c',
           'kgrid.c',
           'kpoint.c',
           'mathfunc.c',
           'niggli.c',
           'overlap.c',
           'pointgroup.c',
           'primitive.c',
           'refinement.c',
           'sitesym_database.c',
           'site_symmetry.c',
           'spacegroup.c',
           'spin.c',
           'spg_database.c',
           'spglib.c',
           'symmetry.c']

if os.path.exists('src'):
    source_dir = "src"
else:
    source_dir = "../src"

include_dirs = [source_dir, ]
if not use_setuptools:
    include_dirs += get_numpy_include_dirs()

for i, s in enumerate(sources):
    sources[i] = "%s/%s" % (source_dir, s)

extra_compile_args = []
extra_link_args = []
define_macros = []

## Uncomment to activate OpenMP support for gcc
# extra_compile_args += ['-fopenmp']
# extra_link_args += ['-lgomp']

## For debugging
# define_macros = [('SPGWARNING', None),
#                  ('SPGDEBUG', None)]

extension = Extension('spglib._spglib',
                      include_dirs=include_dirs,
                      sources=['_spglib.c'] + sources,
                      extra_compile_args=extra_compile_args,
                      extra_link_args=extra_link_args,
                      define_macros=define_macros)

version_nums = [None, None, None]
with open("%s/version.h" % source_dir) as w:
    for line in w:
        for i, chars in enumerate(("MAJOR", "MINOR", "MICRO")):
            if chars in line:
                version_nums[i] = int(line.split()[2])

# To deploy to pypi by travis-CI
nanoversion = 0
if os.path.isfile("__nanoversion__.txt"):
    with open('__nanoversion__.txt') as nv:
        try:
            for line in nv:
                nanoversion = int(line.strip())
                break
        except ValueError:
            nanoversion = 0
version_nums.append(nanoversion)

if None in version_nums:
    print("Failed to get version number in setup.py.")
    raise

version = ".".join(["%d" % n for n in version_nums[:3]])
if len(version_nums) > 3:
    version += "-%d" % version_nums[3]
if use_setuptools:
    setup(name='spglib',
          version=version,
          cmdclass={'build_ext': build_ext},
          setup_requires=['numpy', 'setuptools>=18.0'],
          license='BSD-3-Clause',
          description='This is the spglib module.',
          long_description=open('README.rst', 'rb').read().decode('utf-8'),
          long_description_content_type='text/x-rst',
          author='Atsushi Togo',
          author_email='atz.togo@gmail.com',
          url='http://atztogo.github.io/spglib/',
          packages=['spglib'],
          install_requires=['numpy'],
          provides=['spglib'],
          platforms=['all'],
          ext_modules=[extension],
          test_suite='nose.collector',
          tests_require=['nose'])
else:
    setup(name='spglib',
          version=version,
          license='BSD-3-Clause',
          description='This is the spglib module.',
          long_description=open('README.rst', 'rb').read().decode('utf-8'),
          long_description_content_type='text/x-rst',
          author='Atsushi Togo',
          author_email='atz.togo@gmail.com',
          url='http://atztogo.github.io/spglib/',
          packages=['spglib'],
          requires=['numpy'],
          provides=['spglib'],
          platforms=['all'],
          ext_modules=[extension],
          test_suite='nose.collector',
          tests_require=['nose'])