Skip to content

Commit c2a9ac6

Browse files
committed
BLD Replace setup.py with meson-python build
1 parent fe581fe commit c2a9ac6

File tree

14 files changed

+324
-156
lines changed

14 files changed

+324
-156
lines changed

.github/workflows/test-python-package-with-conda.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ jobs:
171171
run: |
172172
micromamba install --file tests-requirements.txt --name mahotas_test_env
173173
micromamba install --name mahotas_test_env freeimage imread
174+
python -m pip install "meson-python>=0.17.1,<0.18" "meson>=1.2.3" ninja
174175
- name: Build
175176
shell: bash -l {0}
176177
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
wheelhouse
22
dist/
33
build/
4+
/.mesonpy-*
45
mahotas.egg-info/
56
*.pyc
67
*.so

MANIFEST.in

Lines changed: 0 additions & 16 deletions
This file was deleted.

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
PIP_EDITABLE = python -m pip install --editable . --no-deps --no-build-isolation
2+
13
debug: mahotas/*.cpp mahotas/*.h mahotas/*.hpp
2-
DEBUG=2 python setup.py build --build-lib=.
4+
$(PIP_EDITABLE) --config-settings=build-dir=build/debug --config-settings=setup-args=-Dbuildtype=debug --config-settings=setup-args=-Dglibcpp_debug=true
35

46
debug3: mahotas/*.cpp mahotas/*.h mahotas/*.hpp
5-
DEBUG=2 python3 setup.py build --build-lib=.
7+
python3 -m pip install --editable . --no-deps --no-build-isolation --config-settings=build-dir=build/debug --config-settings=setup-args=-Dbuildtype=debug --config-settings=setup-args=-Dglibcpp_debug=true
68

79
fast: mahotas/*.cpp mahotas/*.h mahotas/*.hpp
8-
python setup.py build --build-lib=.
10+
$(PIP_EDITABLE) --config-settings=build-dir=build/fast --config-settings=setup-args=-Dbuildtype=release
911

1012
install:
11-
python setup.py install
13+
python -m pip install .
1214

1315
fast3: mahotas/*.cpp mahotas/*.h mahotas/*.hpp
14-
python3 setup.py build --build-lib=.
16+
python3 -m pip install --editable . --no-deps --no-build-isolation --config-settings=build-dir=build/fast --config-settings=setup-args=-Dbuildtype=release
1517

1618
clean:
17-
rm -rf build mahotas/*.so mahotas/features/*.so
19+
rm -rf build dist .mesonpy-* mahotas/*.so mahotas/features/*.so
1820

1921
tests: debug
2022
pytest -v
2123

2224
docs:
2325
rm -rf build/docs
2426
cd docs && make html && cp -r build/html ../build/docs
25-
@echo python setup.py upload_docs
27+
@echo python -m build
2628

2729
.PHONY: clean docs tests fast debug install fast3 debug3
28-

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ If you want an editable install for development, use:
152152
pip install -e .[tests]
153153
```
154154

155+
The build is Meson-based. To rebuild the editable install in release or debug
156+
mode after the initial development install, use:
157+
158+
```bash
159+
make fast
160+
make debug
161+
```
162+
155163
If you run into issues, the manual has more [extensive documentation on
156164
mahotas
157165
installation](https://mahotas.readthedocs.io/en/latest/install.html),
@@ -184,30 +192,28 @@ You can access this information using the `mahotas.citation()` function.
184192
Development happens on github
185193
([https://github.com/luispedro/mahotas](https://github.com/luispedro/mahotas)).
186194

187-
You can set the `DEBUG` environment variable before compilation to get a
188-
debug version:
195+
The `Makefile` that is shipped with the source of mahotas can be useful
196+
too. `make debug` rebuilds the editable install with a Meson debug build and
197+
enables `_GLIBCXX_DEBUG`. `make fast` rebuilds it in release mode. `make tests`
198+
runs the test suite after a debug rebuild.
189199

190200
```bash
191-
export DEBUG=1
192201
make debug
193202
pytest -v
194203
```
195204

196-
You can set it to the value `2` to get extra checks:
205+
If you want the equivalent of the old `DEBUG=1` build without
206+
`_GLIBCXX_DEBUG`, invoke pip directly:
197207

198208
```bash
199-
export DEBUG=2
200-
make debug
201-
pytest -v
209+
python -m pip install -e . --no-deps --no-build-isolation \
210+
--config-settings=build-dir=build/debug \
211+
--config-settings=setup-args=-Dbuildtype=debug
202212
```
203213

204-
Be careful not to use this in production unless you are chasing a bug.
205-
Debug level 2 is very slow as it adds many runtime checks.
206-
207-
The `Makefile` that is shipped with the source of mahotas can be useful
208-
too. `make debug` will create a debug build. `make fast` will create a
209-
non-debug build (you need to `make clean` in between). `make tests` will
210-
run the test suite.
214+
Be careful not to use the debug build in production unless you are chasing a
215+
bug. The `_GLIBCXX_DEBUG` configuration used by `make debug` is very slow as it
216+
adds many runtime checks.
211217

212218
## Links & Contacts
213219

build-aux/meson-helper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import argparse
6+
from pathlib import Path
7+
import re
8+
9+
10+
ROOT = Path(__file__).resolve().parents[1]
11+
VERSION_FILE = ROOT / "mahotas" / "mahotas_version.py"
12+
13+
14+
def read_version() -> str:
15+
version_source = VERSION_FILE.read_text(encoding="utf-8")
16+
match = re.search(r"__version__\s*=\s*['\"]([^'\"]+)['\"]", version_source)
17+
if match is None:
18+
raise SystemExit(f"Could not parse version from {VERSION_FILE}")
19+
return match.group(1)
20+
21+
22+
def main() -> None:
23+
parser = argparse.ArgumentParser()
24+
parser.add_argument("action", choices=["numpy-include", "version"])
25+
args = parser.parse_args()
26+
27+
if args.action == "version":
28+
print(read_version())
29+
return
30+
31+
import numpy
32+
33+
print(numpy.get_include())
34+
35+
36+
if __name__ == "__main__":
37+
main()

docs/source/contributing.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,35 @@ Debug Mode
1919
----------
2020

2121
If you compile mahotas in debug mode, then it will run slower but perform a lot
22-
of runtime checks. This is controlled by the ``DEBUG`` environment variable.
22+
of runtime checks.
2323

2424
There are two levels:
2525

26-
1. ``DEBUG=1`` This turns on assertions. The code will run slower, but
26+
1. A Meson ``debug`` build turns on assertions. The code will run slower, but
2727
probably not noticeably slower, except for very large images.
28-
2. ``DEBUG=2`` This turns on the assertions and additionally uses the debug
29-
version of the C++ library (this only works if you are using GCC). Some of
30-
the internal code also picks up on the ``DEBUG=2`` and adds even more
31-
sanity checking. The result will be code that runs **much slower** as all
32-
operations done through iterators into standard containers are now checked
33-
(including many inner loop operations). However, it catches many errors.
28+
2. ``make debug`` uses a Meson ``debug`` build and additionally defines
29+
``_GLIBCXX_DEBUG``. This only has an effect with libstdc++, but when
30+
available it enables checked iterators in the C++ standard library. The
31+
result will be code that runs **much slower** as many iterator operations
32+
are now checked. However, it catches many errors.
3433

3534
The Makefile that comes with the source helps you::
3635

3736
make clean
3837
make debug
39-
make test
38+
make tests
4039

4140
will rebuild in debug mode and run all tests. When you are done testing, use
4241
the ``fast`` Make target to get the non-debug build::
4342

4443
make clean
4544
make fast
4645

47-
Using make will not change your environment. The ``DEBUG`` variable is set
48-
internally only.
46+
Using make will rebuild the editable install in your current Python
47+
environment with the requested configuration.
4948

5049
If you don't know about it, check out `ccache <https://ccache.samba.org/>`__
5150
which is a great tool if you are developing in compiled languages (this is not
5251
specific to mahotas or even Python). It will allow you to quickly perform
5352
``make clean; make debug`` and ``make clean; make fast`` so you never get your
5453
builds mixed up.
55-

docs/source/install.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ For development, install from a checkout with::
3131

3232
pip install -e .[tests]
3333

34-
You will need to have ``numpy`` and a ``C++`` compiler.
34+
This installs the test dependencies and the Meson build tools needed by the
35+
``Makefile`` rebuild targets. You will also need a ``C++`` compiler.
36+
37+
To rebuild the editable install after changes, use::
38+
39+
make fast
40+
make debug
3541

3642
Visual Studio
3743
~~~~~~~~~~~~~
3844

39-
For compiling from source in Visual Studio, use::
45+
On Windows, Meson will use Visual Studio automatically when you build from
46+
source. For a normal install, use::
47+
48+
python -m pip install .
49+
50+
For a debug-style editable install, use::
4051

41-
python setup.py build_ext -c msvc
42-
pip install .
52+
python -m pip install -e . --no-deps --no-build-isolation --config-settings=build-dir=build/debug --config-settings=setup-args=-Dbuildtype=debug
4353

4454

4555
Bleeding Edge (Development)

mahotas/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
all:
2-
cd .. && DEBUG=2 python setup.py build_ext --build-lib=. -U NDEBUG
2+
$(MAKE) -C .. debug

0 commit comments

Comments
 (0)