44# Will likely fail on Windows, but Makefiles are in general not Windows
55# compatible so we're not too worried
66TEMP_FILE := $(shell mktemp)
7+ # Directory in which to build the Fortran when using a standalone build
8+ BUILD_DIR := build
9+ # Coverage directory - needed to trick code cov to look in the right place
10+ COV_DIR := $(shell uv run --no-sync python -c 'from pathlib import Path; import example_fgen_basic; print(Path(example_fgen_basic.__file__) .parent)')
711
812# A helper script to get short descriptions of each target in the Makefile
913define PRINT_HELP_PYSCRIPT
@@ -24,8 +28,8 @@ help: ## print short description of each target
2428
2529.PHONY : checks
2630checks : # # run all the linting checks of the codebase
27- @echo " === pre-commit ===" ; uv run pre-commit run --all-files || echo " --- pre-commit failed ---" >&2 ; \
28- echo " === mypy ===" ; MYPYPATH=stubs uv run mypy src || echo " --- mypy failed ---" >&2 ; \
31+ @echo " === pre-commit ===" ; uv run --no-sync pre-commit run --all-files || echo " --- pre-commit failed ---" >&2 ; \
32+ echo " === mypy ===" ; MYPYPATH=stubs uv run --no-sync mypy src || echo " --- mypy failed ---" >&2 ; \
2933 echo " ======"
3034
3135.PHONY : ruff-fixes
@@ -37,8 +41,17 @@ ruff-fixes: ## fix the code using ruff
3741 uv run ruff format src tests scripts docs
3842
3943.PHONY : test
40- test : # # run the tests
41- uv run pytest src tests -r a -v --doctest-modules --doctest-report ndiff --cov=src
44+ test : # # run the tests (re-installs the package every time so you might want to run by hand if you're certain that step isn't needed)
45+ # Note: passing `src` to pytest causes the `src` directory to be imported
46+ # if the package has not already been installed.
47+ # This is a problem, as the package is not importable from `src` by itself because the extension module is not available.
48+ # As a result, you have to pass `pytest tests src` rather than `pytest src tests`
49+ # to ensure that the package is imported from the venv and not `src`.
50+ # The issue with this is that code coverage then doesn't work,
51+ # because it is looking for lines in `src` to be run,
52+ # but they're not because lines in `.venv` are run instead.
53+ # We don't have a solution to this yet.
54+ uv run --no-editable --reinstall-package example-fgen-basic pytest -r a -v tests src --doctest-modules --doctest-report ndiff --cov=$(COV_DIR )
4255
4356# Note on code coverage and testing:
4457# You must specify cov=src.
@@ -55,15 +68,15 @@ test: ## run the tests
5568
5669.PHONY : docs
5770docs : # # build the docs
58- uv run mkdocs build
71+ uv run --no-sync mkdocs build
5972
6073.PHONY : docs-strict
6174docs-strict : # # build the docs strictly (e.g. raise an error on warnings, this most closely mirrors what we do in the CI)
62- uv run mkdocs build --strict
75+ uv run --no-sync mkdocs build --strict
6376
6477.PHONY : docs-serve
6578docs-serve : # # serve the docs locally
66- uv run mkdocs serve
79+ uv run --no-sync mkdocs serve
6780
6881.PHONY : changelog-draft
6982changelog-draft : # # compile a draft of the next changelog
@@ -79,5 +92,30 @@ licence-check: ## Check that licences of the dependencies are suitable
7992
8093.PHONY : virtual-environment
8194virtual-environment : # # update virtual environment, create a new one if it doesn't already exist
82- uv sync --all-extras --group all-dev
83- uv run pre-commit install
95+ uv sync --no-editable --all-extras --group all-dev
96+ uv run --no-sync pre-commit install
97+
98+ .PHONY : format-fortran
99+ format-fortran : # # format the Fortran files
100+ uv run fprettify -r src -c .fprettify.rc
101+
102+ $(BUILD_DIR ) : # setup the standlone Fortran build directory
103+ uv run meson setup $(BUILD_DIR )
104+
105+ .PHONY : build-fortran
106+ build-fortran : | $(BUILD_DIR ) # # build/compile the Fortran (including the extension module)
107+ uv run meson compile -C build -v
108+
109+ .PHONY : test-fortran
110+ test-fortran : build-fortran # # run the Fortran tests
111+ uv run meson test -C build -v
112+
113+ .PHONY : install-fortran
114+ install-fortran : build-fortran # # install the Fortran (including the extension module)
115+ uv run meson install -C build -v
116+ # # Can also do this to see where things go without making a mess
117+ # uv run meson install -C build --destdir ../install-example
118+
119+ .PHONY : clean
120+ clean : # # clean all build artefacts
121+ rm -rf $(BUILD_DIR )
0 commit comments