File: setup.py

package info (click to toggle)
llvmlite 0.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,736 kB
  • sloc: python: 12,771; cpp: 3,146; sh: 185; makefile: 183
file content (214 lines) | stat: -rw-r--r-- 6,914 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
try:
    from setuptools import setup, Extension
    # Required for compatibility with pip (issue #177)
    from setuptools.command.install import install
except ImportError:
    from distutils.core import setup, Extension
    from distutils.command.install import install


try:
    from wheel.bdist_wheel import bdist_wheel
except ImportError:
    bdist_wheel = None

from distutils.command.build import build
from distutils.command.build_ext import build_ext
from distutils.command.clean import clean
from distutils import log
from distutils.dir_util import remove_tree
from distutils.spawn import spawn
import os
import sys


min_python_version = (3, 10)


def _version_info_str(int_tuple):
    return ".".join(map(str, int_tuple))


def _guard_py_ver():
    current_python_version = sys.version_info[:3]
    min_py = _version_info_str(min_python_version)
    cur_py = _version_info_str(current_python_version)

    if not min_python_version <= current_python_version:
        msg = ('Cannot install on Python version {}; only versions >={} '
               'are supported.')
        raise RuntimeError(msg.format(cur_py, min_py))


_guard_py_ver()


import versioneer

versioneer.VCS = 'git'
versioneer.versionfile_source = 'llvmlite/_version.py'
versioneer.versionfile_build = 'llvmlite/_version.py'
versioneer.tag_prefix = 'v' # tags are like v1.2.0
versioneer.parentdir_prefix = 'llvmlite-' # dirname like 'myproject-1.2.0'


here_dir = os.path.dirname(os.path.abspath(__file__))

cmdclass = versioneer.get_cmdclass()
build = cmdclass.get('build', build)
build_ext = cmdclass.get('build_ext', build_ext)


def build_library_files(dry_run):
    cmd = [sys.executable, os.path.join(here_dir, 'ffi', 'build.py')]
    # Turn on -fPIC for building on Linux, BSD, OS X, and GNU platforms
    plt = sys.platform
    if 'linux' in plt or 'bsd' in plt or 'darwin' in plt or 'gnu' in plt:
        os.environ['CXXFLAGS'] = os.environ.get('CXXFLAGS', '') + ' -fPIC'
    spawn(cmd, dry_run=dry_run)


class LlvmliteBuild(build):

    def finalize_options(self):
        build.finalize_options(self)
        # The build isn't platform-independent
        if self.build_lib == self.build_purelib:
            self.build_lib = self.build_platlib

    def get_sub_commands(self):
        # Force "build_ext" invocation.
        commands = build.get_sub_commands(self)
        for c in commands:
            if c == 'build_ext':
                return commands
        return ['build_ext'] + commands


class LlvmliteBuildExt(build_ext):

    def run(self):
        build_ext.run(self)
        build_library_files(self.dry_run)
        # HACK: this makes sure the library file (which is large) is only
        # included in binary builds, not source builds.
        from llvmlite.utils import get_library_files
        self.distribution.package_data = {
            "llvmlite.binding": get_library_files(),
        }


class LlvmliteInstall(install):
    # Ensure install see the libllvmlite shared library
    # This seems to only be necessary on OSX.
    def run(self):
        from llvmlite.utils import get_library_files
        self.distribution.package_data = {
            "llvmlite.binding": get_library_files(),
        }
        install.run(self)

    def finalize_options(self):
        install.finalize_options(self)
        # Force use of "platlib" dir for auditwheel to recognize this
        # is a non-pure build
        self.install_libbase = self.install_platlib
        self.install_lib = self.install_platlib


class LlvmliteClean(clean):
    """Custom clean command to tidy up the project root."""
    def run(self):
        clean.run(self)
        path = os.path.join(here_dir, 'llvmlite.egg-info')
        if os.path.isdir(path):
            remove_tree(path, dry_run=self.dry_run)
        if not self.dry_run:
            self._rm_walk()

    def _rm_walk(self):
        for path, dirs, files in os.walk(here_dir):
            if any(p.startswith('.') for p in path.split(os.path.sep)):
                # Skip hidden directories like the git folder right away
                continue
            if path.endswith('__pycache__'):
                remove_tree(path, dry_run=self.dry_run)
            else:
                for fname in files:
                    if (fname.endswith('.pyc') or fname.endswith('.so')
                            or fname.endswith('.o')):
                        fpath = os.path.join(path, fname)
                        os.remove(fpath)
                        log.info("removing '%s'", fpath)


if bdist_wheel:
    class LLvmliteBDistWheel(bdist_wheel):
        def run(self):
            # Ensure the binding file exist when running wheel build
            from llvmlite.utils import get_library_files
            build_library_files(self.dry_run)
            self.distribution.package_data.update({
                "llvmlite.binding": get_library_files(),
            })
            # Run wheel build command
            bdist_wheel.run(self)

        def finalize_options(self):
            bdist_wheel.finalize_options(self)
            # The build isn't platform-independent
            self.root_is_pure = False


cmdclass.update({'build': LlvmliteBuild,
                 'build_ext': LlvmliteBuildExt,
                 'install': LlvmliteInstall,
                 'clean': LlvmliteClean,
                 })

if bdist_wheel:
    cmdclass.update({'bdist_wheel': LLvmliteBDistWheel})

# A stub C-extension to make bdist_wheel build an arch dependent build
ext_stub = Extension(name="llvmlite.binding._stub",
                     sources=["llvmlite/binding/_stub.c"])


packages = ['llvmlite',
            'llvmlite.binding',
            'llvmlite.ir',
            'llvmlite.tests',
            ]


with open('README.rst') as f:
    long_description = f.read()


setup(name='llvmlite',
      description="lightweight wrapper around basic LLVM functionality",
      version=versioneer.get_version(),
      classifiers=[
          "Development Status :: 4 - Beta",
          "Intended Audience :: Developers",
          "Operating System :: OS Independent",
          "Programming Language :: Python",
          "Programming Language :: Python :: 3",
           "Programming Language :: Python :: 3.10",
          "Programming Language :: Python :: 3.11",
          "Programming Language :: Python :: 3.12",
          "Programming Language :: Python :: 3.13",
          "Topic :: Software Development :: Code Generators",
          "Topic :: Software Development :: Compilers",
      ],
      # Include the separately-compiled shared library
      url="http://llvmlite.readthedocs.io",
      project_urls={
          "Source": "https://github.com/numba/llvmlite",
      },
      packages=packages,
      license="BSD",
      cmdclass=cmdclass,
      long_description=long_description,
      python_requires=">={}".format(_version_info_str(min_python_version)),
      )