[go: up one dir, main page]

File: setup.py

package info (click to toggle)
sep 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,472 kB
  • sloc: ansic: 5,051; python: 906; makefile: 259
file content (75 lines) | stat: -rwxr-xr-x 2,170 bytes parent folder | download | duplicates (2)
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
"""Setup file to build the C library."""

import os
import re
import sys
from glob import glob

from setuptools import Extension, setup
from setuptools_scm import ScmVersion, get_version
from setuptools_scm.version import guess_next_version


def _new_version_scheme(version: ScmVersion) -> str:

    return version.format_next_version(guess_next_version, "{guessed}-dev{distance}")


def _new_local_scheme(version: ScmVersion) -> str:

    return version.format_choice("", "-{node}")


c_version_string = get_version(
    version_scheme=_new_version_scheme,
    local_scheme=_new_local_scheme,
)

# from setuptools import setup
from setuptools.dist import Distribution

# Detect if setup.py is being run with an argument that doesn't require
# building anything. (egg info, help commands, etc)
options = Distribution.display_option_names + ["help-commands", "help"]
is_non_build = (
    any("--" + opt in sys.argv for opt in options)
    or len(sys.argv) == 1
    or sys.argv[1] in ("egg_info", "clean", "help")
)

# Get the path where the lib was built (to link with the proper libsep library)
sep_lib_path = os.environ.get('SEP_LIB_PATH', '')

# extension module(s): only add if we actually need to build, because we need
# to import numpy and cython to build, and we'd rather non-build commands
# work when those dependencies are not installed.
if is_non_build:
    extensions = None
else:
    import numpy
    from Cython.Build import cythonize

    sourcefiles = ["sep.pyx"]
    headerfiles = glob(os.path.join("src", "*.h"))
    include_dirs = [numpy.get_include(), "src"]
    extensions = [
        Extension(
            "sep",
            sourcefiles,
            include_dirs=include_dirs,
            libraries=["sep"],
            library_dirs=[sep_lib_path],
            depends=headerfiles,
            define_macros=[
                ("_USE_MATH_DEFINES", "1"),
                ("NPY_NO_DEPRECATED_API", "NPY_2_0_API_VERSION"),
            ],
            extra_compile_args=['-DSEP_VERSION_STRING="' + c_version_string + '"'],
        )
    ]
    extensions = cythonize(
        extensions,
        language_level=3,
    )

setup(ext_modules=extensions)