|
1 | | -# -*- coding: utf-8 -*- |
2 | 1 | # Copyright (C) 2009-2025, Luis Pedro Coelho <luis@luispedro.org> |
3 | | -# vim: set ts=4 sts=4 sw=4 expandtab smartindent: |
4 | | -# |
5 | | -# Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | | -# of this software and associated documentation files (the "Software"), to deal |
7 | | -# in the Software without restriction, including without limitation the rights |
8 | | -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9 | | -# copies of the Software, and to permit persons to whom the Software is |
10 | | -# furnished to do so, subject to the following conditions: |
11 | | -# |
12 | | -# The above copyright notice and this permission notice shall be included in |
13 | | -# all copies or substantial portions of the Software. |
14 | | -# |
15 | | -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | | -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | | -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18 | | -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | | -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 | | -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | | -# THE SOFTWARE. |
22 | | - |
23 | | -from __future__ import division |
24 | | -try: |
25 | | - import setuptools |
26 | | -except ImportError: |
27 | | - print(''' |
28 | | -setuptools not found. |
29 | | -
|
30 | | -On linux, the package is often called python-setuptools''') |
31 | | - from sys import exit |
32 | | - exit(1) |
| 2 | + |
33 | 3 | import os |
| 4 | + |
| 5 | +from setuptools import Extension, setup |
| 6 | +from setuptools.command.build_ext import build_ext |
| 7 | + |
34 | 8 | try: |
35 | 9 | import numpy |
36 | 10 | except ImportError as e: |
37 | | - print(''' |
| 11 | + print( |
| 12 | + """ |
38 | 13 | Could not import numpy ({}). |
39 | 14 |
|
40 | 15 | It is possible that building will fail. |
41 | | - '''.format(e)) |
42 | | - class FakeNumpy(object): |
43 | | - def get_include(self): |
44 | | - return [] |
45 | | - numpy = FakeNumpy() |
46 | | - |
| 16 | + """.format(e) |
| 17 | + ) |
47 | 18 |
|
48 | | -from distutils.command.build_ext import build_ext |
| 19 | + class FakeNumpy: |
| 20 | + @staticmethod |
| 21 | + def get_include(): |
| 22 | + return [] |
49 | 23 |
|
50 | | -exec(compile(open('mahotas/mahotas_version.py').read(), |
51 | | - 'mahotas/mahotas_version.py', 'exec')) |
| 24 | + numpy = FakeNumpy() |
52 | 25 |
|
53 | | -long_description = open('README.md', encoding='utf-8').read() |
54 | 26 |
|
55 | 27 | undef_macros = [] |
56 | 28 | define_macros = [] |
57 | | -if os.environ.get('DEBUG'): |
58 | | - undef_macros = ['NDEBUG'] |
59 | | - if os.environ.get('DEBUG') == '2': |
60 | | - define_macros = [('_GLIBCXX_DEBUG','1')] |
| 29 | +if os.environ.get("DEBUG"): |
| 30 | + undef_macros = ["NDEBUG"] |
| 31 | + if os.environ.get("DEBUG") == "2": |
| 32 | + define_macros = [("_GLIBCXX_DEBUG", "1")] |
61 | 33 |
|
62 | | -define_macros.append(('NPY_NO_DEPRECATED_API','NPY_1_7_API_VERSION')) |
63 | | -define_macros.append(('PY_ARRAY_UNIQUE_SYMBOL','Mahotas_PyArray_API_Symbol')) |
| 34 | +define_macros.append(("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")) |
| 35 | +define_macros.append(("PY_ARRAY_UNIQUE_SYMBOL", "Mahotas_PyArray_API_Symbol")) |
64 | 36 |
|
65 | 37 | extensions = { |
66 | | - 'mahotas._bbox': ['mahotas/_bbox.cpp'], |
67 | | - 'mahotas._center_of_mass': ['mahotas/_center_of_mass.cpp'], |
68 | | - 'mahotas._convex': ['mahotas/_convex.cpp'], |
69 | | - 'mahotas._convolve': ['mahotas/_convolve.cpp', 'mahotas/_filters.cpp'], |
70 | | - 'mahotas._distance': ['mahotas/_distance.cpp'], |
71 | | - 'mahotas._histogram': ['mahotas/_histogram.cpp'], |
72 | | - 'mahotas._interpolate': ['mahotas/_interpolate.cpp', 'mahotas/_filters.cpp'], |
73 | | - 'mahotas._labeled': ['mahotas/_labeled.cpp', 'mahotas/_filters.cpp'], |
74 | | - 'mahotas._morph': ['mahotas/_morph.cpp', 'mahotas/_filters.cpp'], |
75 | | - 'mahotas._thin': ['mahotas/_thin.cpp'], |
76 | | - |
77 | | - 'mahotas.features._lbp': ['mahotas/features/_lbp.cpp'], |
78 | | - 'mahotas.features._surf': ['mahotas/features/_surf.cpp'], |
79 | | - 'mahotas.features._texture': ['mahotas/features/_texture.cpp', 'mahotas/_filters.cpp'], |
80 | | - 'mahotas.features._zernike': ['mahotas/features/_zernike.cpp'], |
| 38 | + "mahotas._bbox": ["mahotas/_bbox.cpp"], |
| 39 | + "mahotas._center_of_mass": ["mahotas/_center_of_mass.cpp"], |
| 40 | + "mahotas._convex": ["mahotas/_convex.cpp"], |
| 41 | + "mahotas._convolve": ["mahotas/_convolve.cpp", "mahotas/_filters.cpp"], |
| 42 | + "mahotas._distance": ["mahotas/_distance.cpp"], |
| 43 | + "mahotas._histogram": ["mahotas/_histogram.cpp"], |
| 44 | + "mahotas._interpolate": ["mahotas/_interpolate.cpp", "mahotas/_filters.cpp"], |
| 45 | + "mahotas._labeled": ["mahotas/_labeled.cpp", "mahotas/_filters.cpp"], |
| 46 | + "mahotas._morph": ["mahotas/_morph.cpp", "mahotas/_filters.cpp"], |
| 47 | + "mahotas._thin": ["mahotas/_thin.cpp"], |
| 48 | + "mahotas.features._lbp": ["mahotas/features/_lbp.cpp"], |
| 49 | + "mahotas.features._surf": ["mahotas/features/_surf.cpp"], |
| 50 | + "mahotas.features._texture": [ |
| 51 | + "mahotas/features/_texture.cpp", |
| 52 | + "mahotas/_filters.cpp", |
| 53 | + ], |
| 54 | + "mahotas.features._zernike": ["mahotas/features/_zernike.cpp"], |
81 | 55 | } |
82 | 56 |
|
83 | 57 | ext_modules = [ |
84 | | - setuptools.Extension(key, sources=sources, undef_macros=undef_macros, define_macros=define_macros, include_dirs=[numpy.get_include()]) |
85 | | - for key,sources in extensions.items()] |
86 | | - |
87 | | -packages = setuptools.find_packages() |
88 | | - |
89 | | -package_dir = { |
90 | | - 'mahotas.tests': 'mahotas/tests', |
91 | | - 'mahotas.demos': 'mahotas/demos', |
92 | | - } |
93 | | -package_data = { |
94 | | - 'mahotas.tests': ['data/*'], |
95 | | - 'mahotas.demos': ['data/*'], |
96 | | - } |
97 | | - |
98 | | -install_requires = open('requirements.txt').read().strip().split('\n') |
99 | | - |
100 | | -tests_require = open('tests-requirements.txt').read().strip().split('\n') |
101 | | -if "freeimage" in tests_require: |
102 | | - tests_require.pop(tests_require.index("freeimage")) |
| 58 | + Extension( |
| 59 | + key, |
| 60 | + sources=sources, |
| 61 | + undef_macros=undef_macros, |
| 62 | + define_macros=define_macros, |
| 63 | + include_dirs=[numpy.get_include()], |
| 64 | + ) |
| 65 | + for key, sources in extensions.items() |
| 66 | +] |
103 | 67 |
|
104 | | -copt={ |
105 | | - 'msvc': ['/EHsc'], |
106 | | - 'intelw': ['/EHsc'] |
| 68 | +copt = { |
| 69 | + "msvc": ["/EHsc"], |
| 70 | + "intelw": ["/EHsc"], |
107 | 71 | } |
108 | 72 |
|
| 73 | + |
109 | 74 | class build_ext_subclass(build_ext): |
110 | 75 | def build_extensions(self): |
111 | | - c = self.compiler.compiler_type |
112 | | - if c in copt: |
113 | | - for e in self.extensions: |
114 | | - e.extra_compile_args = copt[c] |
115 | | - build_ext.build_extensions(self) |
116 | | - |
117 | | -classifiers = [ |
118 | | -'Development Status :: 5 - Production/Stable', |
119 | | -'Intended Audience :: Developers', |
120 | | -'Intended Audience :: Science/Research', |
121 | | -'Topic :: Scientific/Engineering :: Image Recognition', |
122 | | -'Topic :: Software Development :: Libraries', |
123 | | -'Programming Language :: Python', |
124 | | -'Programming Language :: Python :: 3', |
125 | | -'Programming Language :: Python :: 3.7', |
126 | | -'Programming Language :: Python :: 3.8', |
127 | | -'Programming Language :: Python :: 3.9', |
128 | | -'Programming Language :: Python :: 3.10', |
129 | | -'Programming Language :: Python :: 3.11', |
130 | | -'Programming Language :: Python :: 3.12', |
131 | | -'Programming Language :: Python :: 3.13', |
132 | | -'Programming Language :: C++', |
133 | | -'Operating System :: OS Independent', |
134 | | -'License :: OSI Approved :: MIT License', |
135 | | -] |
| 76 | + compiler_type = self.compiler.compiler_type |
| 77 | + if compiler_type in copt: |
| 78 | + for extension in self.extensions: |
| 79 | + extension.extra_compile_args = copt[compiler_type] |
| 80 | + super().build_extensions() |
| 81 | + |
136 | 82 |
|
137 | | -setuptools.setup(name = 'mahotas', |
138 | | - version = __version__, |
139 | | - description = 'Mahotas: Computer Vision Library', |
140 | | - long_description = long_description, |
141 | | - long_description_content_type = 'text/markdown', |
142 | | - author = 'Luis Pedro Coelho', |
143 | | - author_email = 'luis@luispedro.org', |
144 | | - license = 'MIT', |
145 | | - python_requires = '>=3.7', |
146 | | - platforms = ['Any'], |
147 | | - classifiers = classifiers, |
148 | | - url = 'https://luispedro.org/software/mahotas', |
149 | | - packages = packages, |
150 | | - ext_modules = ext_modules, |
151 | | - package_dir = package_dir, |
152 | | - package_data = package_data, |
153 | | - entry_points={ |
154 | | - 'console_scripts': [ |
155 | | - 'mahotas-features = mahotas.features_cli:main', |
156 | | - ], |
157 | | - }, |
158 | | - install_requires = install_requires, |
159 | | - tests_require = tests_require, |
160 | | - cmdclass = {'build_ext': build_ext_subclass}, |
161 | | - extras_require = { |
162 | | - "tests": tests_require, |
163 | | - }, |
164 | | - ) |
| 83 | +setup( |
| 84 | + ext_modules=ext_modules, |
| 85 | + cmdclass={"build_ext": build_ext_subclass}, |
| 86 | +) |
0 commit comments