Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 1 | #from distutils.core import setup, Extension |
| 2 | from setuptools import setup, Extension,find_packages |
| 3 | from distutils.util import convert_path |
| 4 | import glob |
| 5 | import numpy |
| 6 | import sys |
| 7 | import os |
| 8 | import os.path |
| 9 | import re |
| 10 | import pathlib |
| 11 | |
| 12 | here = pathlib.Path(__file__).parent.resolve() |
| 13 | ROOT = here |
| 14 | ROOT="" |
| 15 | |
| 16 | includes = [os.path.join(ROOT,"Include"),os.path.join(ROOT,"PrivateInclude"),os.path.join("PythonWrapper","cmsisdsp_pkg","src")] |
| 17 | |
| 18 | if sys.platform == 'win32': |
| 19 | cflags = ["-DWIN","-DCMSISDSP","-DUNALIGNED_SUPPORT_DISABLE"] |
| 20 | else: |
| 21 | cflags = ["-Wno-attributes","-Wno-unused-function","-Wno-unused-variable","-Wno-implicit-function-declaration","-DCMSISDSP","-D__GNUC_PYTHON__"] |
| 22 | |
| 23 | transform = glob.glob(os.path.join(ROOT,"Source","TransformFunctions","*.c")) |
| 24 | |
| 25 | # Files are present when creating the source distribution |
| 26 | # but they are not copied to the source distribution |
| 27 | # When doing pip install those files are not prevent |
| 28 | # and it should not fail |
| 29 | try: |
| 30 | transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctions.c")) |
| 31 | transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctionsF16.c")) |
| 32 | except: |
| 33 | pass |
| 34 | |
| 35 | support = glob.glob(os.path.join(ROOT,"Source","SupportFunctions","*.c")) |
| 36 | |
| 37 | try: |
| 38 | support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctions.c")) |
| 39 | support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctionsF16.c")) |
| 40 | except: |
| 41 | pass |
| 42 | |
| 43 | fastmath = glob.glob(os.path.join(ROOT,"Source","FastMathFunctions","*.c")) |
| 44 | try: |
| 45 | fastmath.remove(os.path.join(ROOT,"Source","FastMathFunctions","FastMathFunctions.c")) |
| 46 | except: |
| 47 | pass |
| 48 | |
| 49 | filtering = glob.glob(os.path.join(ROOT,"Source","FilteringFunctions","*.c")) |
| 50 | try: |
| 51 | filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctions.c")) |
| 52 | filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctionsF16.c")) |
| 53 | except: |
| 54 | pass |
| 55 | |
| 56 | matrix = glob.glob(os.path.join(ROOT,"Source","MatrixFunctions","*.c")) |
| 57 | try: |
| 58 | matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctions.c")) |
| 59 | matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctionsF16.c")) |
| 60 | except: |
| 61 | pass |
| 62 | |
| 63 | statistics = glob.glob(os.path.join(ROOT,"Source","StatisticsFunctions","*.c")) |
| 64 | try: |
| 65 | statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctions.c")) |
| 66 | statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctionsF16.c")) |
| 67 | except: |
| 68 | pass |
| 69 | |
| 70 | complexf = glob.glob(os.path.join(ROOT,"Source","ComplexMathFunctions","*.c")) |
| 71 | try: |
| 72 | complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctions.c")) |
| 73 | complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctionsF16.c")) |
| 74 | except: |
| 75 | pass |
| 76 | |
| 77 | basic = glob.glob(os.path.join(ROOT,"Source","BasicMathFunctions","*.c")) |
| 78 | try: |
| 79 | basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctions.c")) |
| 80 | basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctionsF16.c")) |
| 81 | except: |
| 82 | pass |
| 83 | |
| 84 | controller = glob.glob(os.path.join(ROOT,"Source","ControllerFunctions","*.c")) |
| 85 | try: |
| 86 | controller.remove(os.path.join(ROOT,"Source","ControllerFunctions","ControllerFunctions.c")) |
| 87 | except: |
| 88 | pass |
| 89 | |
| 90 | common = glob.glob(os.path.join(ROOT,"Source","CommonTables","*.c")) |
| 91 | try: |
| 92 | common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTables.c")) |
| 93 | common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTablesF16.c")) |
| 94 | except: |
| 95 | pass |
| 96 | |
| 97 | interpolation = glob.glob(os.path.join(ROOT,"Source","InterpolationFunctions","*.c")) |
| 98 | try: |
| 99 | interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctions.c")) |
| 100 | interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctionsF16.c")) |
| 101 | except: |
| 102 | pass |
| 103 | |
| 104 | quaternion = glob.glob(os.path.join(ROOT,"Source","QuaternionMathFunctions","*.c")) |
| 105 | try: |
| 106 | quaternion.remove(os.path.join(ROOT,"Source","QuaternionMathFunctions","QuaternionMathFunctions.c")) |
| 107 | except: |
| 108 | pass |
| 109 | |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 110 | distance = glob.glob(os.path.join(ROOT,"Source","DistanceFunctions","*.c")) |
| 111 | try: |
| 112 | distance.remove(os.path.join(ROOT,"Source","DistanceFunctions","DistanceFunctions.c")) |
| 113 | except: |
| 114 | pass |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 115 | |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 116 | bayes = glob.glob(os.path.join(ROOT,"Source","BayesFunctions","*.c")) |
| 117 | try: |
| 118 | bayes.remove(os.path.join(ROOT,"Source","BayesFunctions","BayesFunctions.c")) |
| 119 | except: |
| 120 | pass |
| 121 | |
| 122 | svm = glob.glob(os.path.join(ROOT,"Source","SVMFunctions","*.c")) |
| 123 | try: |
| 124 | svm.remove(os.path.join(ROOT,"Source","SVMFunctions","SVMFunctions.c")) |
| 125 | except: |
| 126 | pass |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 127 | |
| 128 | # Add dependencies |
| 129 | transformMod = transform + common + basic + complexf + fastmath + matrix + statistics |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 130 | statisticsMod = statistics + common + fastmath + basic |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 131 | interpolationMod = interpolation + common |
| 132 | filteringMod = filtering + common + support + fastmath |
| 133 | controllerMod = controller + common |
| 134 | |
| 135 | matrixMod = matrix |
| 136 | supportMod = support |
| 137 | complexfMod = complexf + fastmath + common |
| 138 | basicMod = basic |
| 139 | quaternionMod = quaternion |
| 140 | fastmathMod = fastmath + common |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 141 | distanceMod = distance + common + basic + statistics + fastmath |
| 142 | bayesMod = bayes + fastmath + common + statistics + basic |
| 143 | svmMod = svm + fastmath + common |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 144 | |
| 145 | |
| 146 | filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c")) |
| 147 | matrixMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_matrix.c")) |
| 148 | supportMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_support.c")) |
| 149 | statisticsMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_statistics.c")) |
| 150 | complexfMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_complexf.c")) |
| 151 | basicMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_basic.c")) |
| 152 | controllerMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_controller.c")) |
| 153 | transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_transform.c")) |
| 154 | interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c")) |
| 155 | quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c")) |
| 156 | fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c")) |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 157 | distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c")) |
| 158 | bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c")) |
| 159 | svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c")) |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 160 | |
| 161 | |
| 162 | |
| 163 | |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 164 | missing=set([ |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 165 | ]) |
| 166 | |
| 167 | def notf16(number): |
| 168 | if re.search(r'f16',number): |
| 169 | return(False) |
| 170 | if re.search(r'F16',number): |
| 171 | return(False) |
| 172 | return(True) |
| 173 | |
| 174 | def isnotmissing(src): |
| 175 | name=os.path.splitext(os.path.basename(src))[0] |
| 176 | return(not (name in missing)) |
| 177 | |
| 178 | # If there are too many files, the linker command is failing on Windows. |
| 179 | # So f16 functions are removed since they are not currently available in the wrapper. |
| 180 | # A next version will have to structure this wrapper more cleanly so that the |
| 181 | # build can work even with more functions |
| 182 | |
| 183 | filtering = list(filter(isnotmissing,list(filter(notf16, filteringMod)))) |
| 184 | matrix = list(filter(isnotmissing,list(filter(notf16, matrixMod)))) |
| 185 | support = list(filter(isnotmissing,list(filter(notf16, supportMod)))) |
| 186 | statistics = list(filter(isnotmissing,list(filter(notf16, statisticsMod)))) |
| 187 | complexf = list(filter(isnotmissing,list(filter(notf16, complexfMod)))) |
| 188 | basic = list(filter(isnotmissing,list(filter(notf16, basicMod)))) |
| 189 | controller = list(filter(isnotmissing,list(filter(notf16, controllerMod)))) |
| 190 | transform = list(filter(isnotmissing,list(filter(notf16, transformMod)))) |
| 191 | interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod)))) |
| 192 | quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod)))) |
| 193 | fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod)))) |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 194 | distance = list(filter(isnotmissing,list(filter(notf16, distanceMod)))) |
| 195 | bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod)))) |
| 196 | svm = list(filter(isnotmissing,list(filter(notf16, svmMod)))) |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 197 | |
| 198 | #for l in filtering: |
| 199 | # print(os.path.basename(l)) |
| 200 | #quit() |
| 201 | |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 202 | def mkModule(name,srcs,funcDir,newCflags=[]): |
| 203 | localinc = os.path.join(ROOT,"Source",funcDir) |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 204 | return(Extension(name, |
| 205 | sources = (srcs |
| 206 | ) |
| 207 | , |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 208 | include_dirs = [localinc] + includes + [numpy.get_include()], |
| 209 | extra_compile_args = cflags + newCflags |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 210 | )) |
| 211 | |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 212 | flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES", |
| 213 | "-DARM_FAST_ALLOW_TABLES", |
| 214 | "-DARM_ALL_FAST_TABLES"] |
| 215 | |
| 216 | moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions",flagsForCommonWithoutFFT) |
| 217 | moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions") |
| 218 | moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions") |
| 219 | moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions",flagsForCommonWithoutFFT) |
| 220 | moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions") |
| 221 | moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions") |
| 222 | moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions",flagsForCommonWithoutFFT) |
| 223 | moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions") |
| 224 | moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions",flagsForCommonWithoutFFT) |
| 225 | moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions") |
| 226 | moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions",flagsForCommonWithoutFFT) |
| 227 | moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions",flagsForCommonWithoutFFT) |
| 228 | moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions",flagsForCommonWithoutFFT) |
| 229 | moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions",flagsForCommonWithoutFFT) |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | def build(): |
| 235 | if sys.version_info.major < 3: |
| 236 | print('setup.py: Error: This package only supports Python 3.', file=sys.stderr) |
| 237 | sys.exit(1) |
| 238 | |
| 239 | main_ns = {} |
| 240 | ver_path = convert_path(os.path.join("cmsisdsp","version.py")) |
| 241 | with open(ver_path) as ver_file: |
| 242 | exec(ver_file.read(), main_ns) |
| 243 | |
| 244 | setup (name = 'cmsisdsp', |
| 245 | version = main_ns['__version__'], |
| 246 | packages=["cmsisdsp","cmsisdsp.sdf","cmsisdsp.sdf.nodes","cmsisdsp.sdf.nodes.host","cmsisdsp.sdf.scheduler"], |
| 247 | description = 'CMSIS-DSP Python API', |
| 248 | long_description=open("PythonWrapper_README.md").read(), |
| 249 | long_description_content_type='text/markdown', |
| 250 | ext_modules = [moduleFiltering , |
| 251 | moduleMatrix, |
| 252 | moduleSupport, |
| 253 | moduleStatistics, |
| 254 | moduleComplexf, |
| 255 | moduleBasic, |
| 256 | moduleController, |
| 257 | moduleTransform, |
| 258 | moduleInterpolation, |
| 259 | moduleQuaternion, |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 260 | moduleFastmath, |
| 261 | moduleDistance, |
| 262 | moduleBayes, |
| 263 | moduleSVM |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 264 | ], |
| 265 | include_package_data=True, |
| 266 | author = 'Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.', |
| 267 | author_email = 'christophe.favergeon@arm.com', |
| 268 | url="https://arm-software.github.io/CMSIS_5/DSP/html/index.html", |
| 269 | python_requires='>=3.6', |
| 270 | license="License :: OSI Approved :: Apache Software License", |
| 271 | platforms=['any'], |
| 272 | classifiers=[ |
| 273 | "Programming Language :: Python :: 3", |
| 274 | "Programming Language :: Python :: Implementation :: CPython", |
| 275 | "Programming Language :: C", |
| 276 | "License :: OSI Approved :: Apache Software License", |
| 277 | "Operating System :: OS Independent", |
| 278 | "Development Status :: 4 - Beta", |
| 279 | "Topic :: Software Development :: Embedded Systems", |
| 280 | "Topic :: Scientific/Engineering :: Mathematics", |
| 281 | "Environment :: Console", |
| 282 | "Intended Audience :: Developers", |
| 283 | ], |
| 284 | keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths'], |
| 285 | install_requires=['numpy>=1.19', |
| 286 | 'networkx>=2.5', |
Christophe Favergeon | 7106010 | 2022-03-07 11:05:01 +0100 | [diff] [blame^] | 287 | 'jinja2>= 2.0, <3.0', |
| 288 | 'sympy>=1.6', |
| 289 | 'markupsafe<2.1' |
| 290 | ], |
Christophe Favergeon | c8a9c18 | 2022-02-25 09:48:43 +0100 | [diff] [blame] | 291 | project_urls={ # Optional |
| 292 | 'Bug Reports': 'https://github.com/ARM-software/CMSIS_5/issues', |
| 293 | 'Source': 'https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP', |
| 294 | } |
| 295 | ) |
| 296 | |
| 297 | |
| 298 | build() |