File: setup.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (150 lines) | stat: -rw-r--r-- 5,413 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
import platform
import sys
from glob import glob

from setuptools import (
    Extension,
    setup,
)
from setuptools.command.sdist import sdist


def main():
    metadata = {"scripts": glob("scripts/*.py"), "cmdclass": command_classes}

    if len(sys.argv) >= 2 and (
        "--help" in sys.argv[1:] or sys.argv[1] in ("--help-commands", "egg_info", "--version", "clean")
    ):
        # For these actions, NumPy is not required.
        #
        # They are required to succeed without Numpy for example when
        # pip is used to install when Numpy is not yet present in
        # the system.
        pass
    else:
        try:
            import numpy

            # Suppress numpy tests
            numpy.test = None
        except Exception as e:
            raise Exception(f"numpy must be installed to build: {e}")
        metadata["ext_modules"] = get_extension_modules(numpy_include=numpy.get_include())

    setup(**metadata)


# ---- Commands -------------------------------------------------------------

# Use build_ext from Cython if found
command_classes = {}
try:
    import Cython.Distutils

    command_classes["build_ext"] = Cython.Distutils.build_ext

    class build_ext_sdist(sdist):
        def run(self):
            # Make sure the compiled Cython files in the distribution are up-to-date
            self.run_command("build_ext")
            super().run()

    command_classes["sdist"] = build_ext_sdist
except ImportError:
    pass

# ---- Extension Modules ----------------------------------------------------

# # suppress C++ #warning, e.g., to silence NumPy deprecation warnings:
# from functools import partial
# _Extension = Extension
# Extension = partial(_Extension, extra_compile_args=["-Wno-cpp"])


def get_extension_modules(numpy_include=None):
    extensions = []
    # Bitsets
    extensions.append(
        Extension(
            "bx.bitset",
            ["lib/bx/bitset.pyx", "src/binBits.c", "src/kent/bits.c", "src/kent/common.c"],
            include_dirs=["src/kent", "src"],
        )
    )
    # Interval intersection
    extensions.append(Extension("bx.intervals.intersection", ["lib/bx/intervals/intersection.pyx"]))
    # Alignment object speedups
    extensions.append(Extension("bx.align._core", ["lib/bx/align/_core.pyx"]))
    # NIB reading speedups
    extensions.append(Extension("bx.seq._nib", ["lib/bx/seq/_nib.pyx"]))
    # 2bit reading speedups
    extensions.append(Extension("bx.seq._twobit", ["lib/bx/seq/_twobit.pyx"]))
    # Translation if character / integer strings
    extensions.append(Extension("bx._seqmapping", ["lib/bx/_seqmapping.pyx"]))
    # BGZF
    extensions.append(
        Extension(
            "bx.misc.bgzf",
            ["lib/bx/misc/bgzf.pyx", "src/samtools/bgzf.c"],
            include_dirs=["src/samtools"],
            libraries=["z"],
        )
    )

    # The following extensions won't (currently) compile on windows
    if platform.system() not in ("Microsoft", "Windows"):
        # Interval clustering
        extensions.append(
            Extension("bx.intervals.cluster", ["lib/bx/intervals/cluster.pyx", "src/cluster.c"], include_dirs=["src"])
        )
        # Position weight matrices
        extensions.append(
            Extension(
                "bx.pwm._position_weight_matrix",
                ["lib/bx/pwm/_position_weight_matrix.pyx", "src/pwm_utils.c"],
                include_dirs=["src"],
            )
        )

        extensions.append(Extension("bx.motif._pwm", ["lib/bx/motif/_pwm.pyx"], include_dirs=[numpy_include]))

        # Sparse arrays with summaries organized as trees on disk
        extensions.append(
            Extension("bx.arrays.array_tree", ["lib/bx/arrays/array_tree.pyx"], include_dirs=[numpy_include])
        )

        # Reading UCSC "big binary index" files
        extensions.append(Extension("bx.bbi.bpt_file", ["lib/bx/bbi/bpt_file.pyx"]))
        extensions.append(Extension("bx.bbi.cirtree_file", ["lib/bx/bbi/cirtree_file.pyx"]))
        extensions.append(Extension("bx.bbi.bbi_file", ["lib/bx/bbi/bbi_file.pyx"], include_dirs=[numpy_include]))
        extensions.append(Extension("bx.bbi.bigwig_file", ["lib/bx/bbi/bigwig_file.pyx"], include_dirs=[numpy_include]))
        extensions.append(Extension("bx.bbi.bigbed_file", ["lib/bx/bbi/bigbed_file.pyx"], include_dirs=[numpy_include]))

        # EPO and Chain arithmetics and IO speedups
        extensions.append(Extension("bx.align._epo", ["lib/bx/align/_epo.pyx"], include_dirs=[numpy_include]))

        # Reading UCSC bed and wiggle formats
        extensions.append(Extension("bx.arrays.bed", ["lib/bx/arrays/bed.pyx"]))
        extensions.append(Extension("bx.arrays.wiggle", ["lib/bx/arrays/wiggle.pyx"]))

        # CpG masking
        extensions.append(
            Extension("bx.align.sitemask._cpg", ["lib/bx/align/sitemask/_cpg.pyx", "lib/bx/align/sitemask/find_cpg.c"])
        )

        # Counting n-grams in integer strings
        extensions.append(Extension("bx.intseq.ngramcount", ["lib/bx/intseq/ngramcount.pyx"], include_dirs=["src"]))

        # Seekable access to bzip2 files
        extensions.append(
            Extension(
                "bx.misc._seekbzip2",
                ["lib/bx/misc/_seekbzip2.pyx", "src/bunzip/micro-bunzip.c"],
                include_dirs=["src/bunzip"],
            )
        )
    return extensions


if __name__ == "__main__":
    main()