Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fa73241
Add Fortran build stuff
znicholls Aug 14, 2025
4d4de64
Up to installing using meson-python
znicholls Aug 14, 2025
4f716ca
Added missing files and adjusted meson.build
mzecc Aug 14, 2025
c981ffc
Clean up a bit and check tests
znicholls Aug 14, 2025
bd5954e
Add pre-commit config for local stuff
znicholls Aug 14, 2025
2675d2d
Update make test command
znicholls Aug 14, 2025
b4d6122
Add pint to dev environment
znicholls Aug 14, 2025
0b84d95
Clean up pyproject.toml
znicholls Aug 14, 2025
dc0b733
Try adding no-sync flag
znicholls Aug 14, 2025
fe24386
Add no-editable flag when installing
znicholls Aug 14, 2025
10ecbe3
Add attrs as a requirement
znicholls Aug 14, 2025
5ad67f8
Add some hacky diagnostic
znicholls Aug 14, 2025
ed0b4ab
Try something else for installing
znicholls Aug 14, 2025
fb5bf3d
Try more diagnostics
znicholls Aug 14, 2025
924eae7
Different diagnostics
znicholls Aug 14, 2025
c8f8a4e
More diagnostics
znicholls Aug 14, 2025
fcda786
Identify dependence of coverage on order of test imports
znicholls Aug 14, 2025
4840c80
Try tricking code coverage
znicholls Aug 14, 2025
36498a0
Try tricking code coverage another way
znicholls Aug 14, 2025
a96b1ff
Turn off code coverage mostly for now
znicholls Aug 14, 2025
6c9701b
Add numpy dependency
znicholls Aug 14, 2025
aa2db41
Add __vesion__ to package namespace
znicholls Aug 14, 2025
8ec7db4
Add type hints that work with python 3.9
znicholls Aug 14, 2025
3077ae4
Update mypy and add --no-sync throughout ci.yaml
znicholls Aug 14, 2025
79f1953
Add no sync throughout GHA
znicholls Aug 14, 2025
948cd9a
Fix build
znicholls Aug 14, 2025
ca0d5f3
CHANGELOG
znicholls Aug 14, 2025
94f991e
Update URL checks
znicholls Aug 14, 2025
cb11326
Ignore rtd from URL checks too
znicholls Aug 14, 2025
e94fc3d
Avoid writing docs for extension module
znicholls Aug 14, 2025
4476045
Try updating RtD build
znicholls Aug 14, 2025
107a66f
Add explicit pip dependency for RtD
znicholls Aug 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .fprettify.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent=4
whitespace=4
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ runs:
shell: bash
if: ${{ (inputs.run-uv-install == 'true') }}
run: |
uv sync ${{ inputs.uv-dependency-install-flags }}
uv sync --no-editable ${{ inputs.uv-dependency-install-flags }}
2 changes: 1 addition & 1 deletion .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
echo "Bumping to version $NEW_VERSION"

# Build CHANGELOG
uv run towncrier build --yes --version v$NEW_VERSION
uv run --no-sync towncrier build --yes --version v$NEW_VERSION

# Commit, tag and push
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uv-dependency-install-flags: "--all-extras --group dev"
- name: mypy
run: |
MYPYPATH=stubs uv run mypy src
MYPYPATH=stubs uv run --no-sync mypy src

docs:
if: ${{ !github.event.pull_request.draft }}
Expand All @@ -41,16 +41,16 @@ jobs:
uv-dependency-install-flags: "--all-extras --group docs"
- name: docs
run: |
uv run mkdocs build --strict
uv run --no-sync mkdocs build --strict
- uses: ./.github/actions/setup
with:
python-version: "3.11"
uv-dependency-install-flags: "--all-extras --group docs --group dev"
- name: docs-with-changelog
run: |
# Check CHANGELOG will build too
uv run towncrier build --yes
uv run mkdocs build --strict
uv run --no-sync towncrier build --yes
uv run --no-sync mkdocs build --strict
# Just in case, undo the staged changes
git restore --staged . && git restore .

Expand All @@ -65,7 +65,9 @@ jobs:
with:
# Exclude local links
# and the template link in pyproject.toml
args: "--exclude 'file://' --exclude '^https://github\\.com/openscm/example-fgen-basic/pull/\\{issue\\}$' ."
# Don't check for conda-forge while we haven't released there
# Don't check https://www.readthedocs.org/ as it hits rate limits
args: "--exclude 'file://' --exclude '^https://github\\.com/openscm/example-fgen-basic/pull/\\{issue\\}$' --exclude '^https://github.com/conda-forge/example-fgen-basic-feedstock$' --exclude '^https://www.readthedocs.org/$' ."

tests:
strategy:
Expand Down Expand Up @@ -97,8 +99,10 @@ jobs:
uv-dependency-install-flags: "--all-extras --group tests"
- name: Run tests
run: |
uv run pytest -r a -v src tests --doctest-modules --cov=src --cov-report=term-missing --cov-report=xml
uv run coverage report

COV_DIR=`uv run --no-sync python -c 'from pathlib import Path; import example_fgen_basic; print(Path(example_fgen_basic.__file__).parent)'`
uv run --no-sync pytest -r a -v tests src --doctest-modules --doctest-report ndiff --cov=${COV_DIR} --cov-report=term-missing --cov-report=xml
uv run --no-sync coverage report
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v4.2.0
env:
Expand Down Expand Up @@ -220,15 +224,13 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
- uses: ./.github/actions/setup
with:
version: "0.8.8"
python-version: ${{ matrix.python-version }}
uv-dependency-install-flags: "--group dev"
- name: Build package
run: |
uv run python scripts/add-locked-targets-to-pyproject-toml.py
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
cat pyproject.toml
uv build
# Just in case, undo the changes to `pyproject.toml`
Expand Down Expand Up @@ -256,5 +258,5 @@ jobs:
run: |
TEMP_FILE=$(mktemp)
uv export --no-dev > $TEMP_FILE
uv run liccheck -r $TEMP_FILE -R licence-check.txt
uv run --no-sync liccheck -r $TEMP_FILE -R licence-check.txt
cat licence-check.txt
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Publish to PyPI
run: |
uv run python scripts/add-locked-targets-to-pyproject-toml.py
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
uv build
uv publish
# Just in case, undo the changes to `pyproject.toml`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Build package for PyPI
run: |
uv run python scripts/add-locked-targets-to-pyproject-toml.py
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
uv build
# Just in case, undo the changes to `pyproject.toml`
git restore --staged . && git restore .
Expand All @@ -43,7 +43,7 @@ jobs:
echo "## Changelog" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
uv add typer
uv run python scripts/changelog-to-release-template.py >> ".github/release_template.md"
uv run --no-sync python scripts/changelog-to-release-template.py >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
echo "## Changes" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
Expand Down
19 changes: 16 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# Local install dir
install-example

# Cloned dependencies
subprojects/test-drive

# Notebooks
*.ipynb

# Auto-generated docs and helper files
docs/api/*
!docs/api/.gitkeep

# pdm stuff
.pdm-python
docs/fgen/api/*
!docs/fgen/api/.gitkeep
docs/fgen-runtime/api/*
!docs/fgen-runtime/api/.gitkeep

# Databases
*.db

# Downloaded wheels
*.whl

# cmake
cmake-build-*

# Jupyter cache
.jupyter_cache

Expand Down
28 changes: 27 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ ci:
autoupdate_schedule: quarterly
autoupdate_branch: pre-commit-autoupdate
# Currently network access isn't supported in the pre-commit CI product.
skip: [uv-sync, uv-lock, uv-export]
skip: [
propagate-pyproject-metadata,
uv-sync,
uv-lock,
uv-export,
]

# See https://pre-commit.com/hooks.html for more hooks
repos:
Expand Down Expand Up @@ -63,3 +68,24 @@ repos:
args: ["-o", "requirements-only-tests-locked.txt", "--no-hashes", "--no-dev", "--no-emit-project", "--only-group", "tests"]
# # Not released yet
# - id: uv-sync
- repo: local
hooks:
- id: propagate-pyproject-metadata
name: propagate-pyproject-metadata
entry: uv run --no-sync python scripts/propogate-pyproject-metadata.py
files: |
(?x)^(
meson.build|
scripts/propogate-pyproject-metadata.py|
pyproject.toml
)$
language: system
require_serial: true
pass_filenames: false
- id: inject-srcs-into-meson-build
name: inject-srcs-into-meson-build
entry: uv run --no-sync python scripts/inject-srcs-into-meson-build.py
files: \.(py|f90|build)$
language: system
require_serial: true
pass_filenames: false
8 changes: 5 additions & 3 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
python: "mambaforge-22.9"
jobs:
post_install:
# RtD seems to be not happy with pdm installs,
# hence use pip directly instead.
- which python
- python -m pip install -r requirements-docs-locked.txt
- python -m pip list
pre_build:
Expand All @@ -22,3 +21,6 @@ build:
mkdocs:
configuration: mkdocs.yml
fail_on_warning: true

conda:
environment: environment-docs-conda-base.yml
56 changes: 47 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# Will likely fail on Windows, but Makefiles are in general not Windows
# compatible so we're not too worried
TEMP_FILE := $(shell mktemp)
# Directory in which to build the Fortran when using a standalone build
BUILD_DIR := build
# Coverage directory - needed to trick code cov to look in the right place
COV_DIR := $(shell uv run --no-sync python -c 'from pathlib import Path; import example_fgen_basic; print(Path(example_fgen_basic.__file__).parent)')

# A helper script to get short descriptions of each target in the Makefile
define PRINT_HELP_PYSCRIPT
Expand All @@ -24,8 +28,8 @@ help: ## print short description of each target

.PHONY: checks
checks: ## run all the linting checks of the codebase
@echo "=== pre-commit ==="; uv run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
echo "=== mypy ==="; MYPYPATH=stubs uv run mypy src || echo "--- mypy failed ---" >&2; \
@echo "=== pre-commit ==="; uv run --no-sync pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
echo "=== mypy ==="; MYPYPATH=stubs uv run --no-sync mypy src || echo "--- mypy failed ---" >&2; \
echo "======"

.PHONY: ruff-fixes
Expand All @@ -37,8 +41,17 @@ ruff-fixes: ## fix the code using ruff
uv run ruff format src tests scripts docs

.PHONY: test
test: ## run the tests
uv run pytest src tests -r a -v --doctest-modules --doctest-report ndiff --cov=src
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)
# Note: passing `src` to pytest causes the `src` directory to be imported
# if the package has not already been installed.
# This is a problem, as the package is not importable from `src` by itself because the extension module is not available.
# As a result, you have to pass `pytest tests src` rather than `pytest src tests`
# to ensure that the package is imported from the venv and not `src`.
# The issue with this is that code coverage then doesn't work,
# because it is looking for lines in `src` to be run,
# but they're not because lines in `.venv` are run instead.
# We don't have a solution to this yet.
uv run --no-editable --reinstall-package example-fgen-basic pytest -r a -v tests src --doctest-modules --doctest-report ndiff --cov=$(COV_DIR)

# Note on code coverage and testing:
# You must specify cov=src.
Expand All @@ -55,15 +68,15 @@ test: ## run the tests

.PHONY: docs
docs: ## build the docs
uv run mkdocs build
uv run --no-sync mkdocs build

.PHONY: docs-strict
docs-strict: ## build the docs strictly (e.g. raise an error on warnings, this most closely mirrors what we do in the CI)
uv run mkdocs build --strict
uv run --no-sync mkdocs build --strict

.PHONY: docs-serve
docs-serve: ## serve the docs locally
uv run mkdocs serve
uv run --no-sync mkdocs serve

.PHONY: changelog-draft
changelog-draft: ## compile a draft of the next changelog
Expand All @@ -79,5 +92,30 @@ licence-check: ## Check that licences of the dependencies are suitable

.PHONY: virtual-environment
virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
uv sync --all-extras --group all-dev
uv run pre-commit install
uv sync --no-editable --all-extras --group all-dev
uv run --no-sync pre-commit install

.PHONY: format-fortran
format-fortran: ## format the Fortran files
uv run fprettify -r src -c .fprettify.rc

$(BUILD_DIR): # setup the standlone Fortran build directory
uv run meson setup $(BUILD_DIR)

.PHONY: build-fortran
build-fortran: | $(BUILD_DIR) ## build/compile the Fortran (including the extension module)
uv run meson compile -C build -v

.PHONY: test-fortran
test-fortran: build-fortran ## run the Fortran tests
uv run meson test -C build -v

.PHONY: install-fortran
install-fortran: build-fortran ## install the Fortran (including the extension module)
uv run meson install -C build -v
# # Can also do this to see where things go without making a mess
# uv run meson install -C build --destdir ../install-example

.PHONY: clean
clean: ## clean all build artefacts
rm -rf $(BUILD_DIR)
1 change: 1 addition & 0 deletions changelog/2.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add basic functionality that wraps Fortran
50 changes: 50 additions & 0 deletions config/install-mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""
Originally copied from: https://github.com/toml-f/toml-f/blob/main/config/install-mod.py

Using the MIT License, copyright notice below
(from https://github.com/toml-f/toml-f/blob/main/LICENSE-MIT)

Copyright (c) 2019-2021 Sebastian Ehlert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
"""

from os import environ, listdir, makedirs
from os.path import exists, isdir, join
from shutil import copy
from sys import argv

build_dir = environ["MESON_BUILD_ROOT"]

if "MESON_INSTALL_DESTDIR_PREFIX" in environ:
install_dir = environ["MESON_INSTALL_DESTDIR_PREFIX"]

else:
install_dir = environ["MESON_INSTALL_PREFIX"]

include_dir = argv[1] if len(argv) > 1 else "include"
module_dir = join(install_dir, include_dir)

modules = []
for d in listdir(build_dir):
bd = join(build_dir, d)
if isdir(bd):
for f in listdir(bd):
if f.endswith(".mod"):
modules.append(join(bd, f))

if not exists(module_dir):
makedirs(module_dir)

for mod in modules:
print("Installing (from custom python script)", mod, "to", module_dir)
copy(mod, module_dir)
25 changes: 25 additions & 0 deletions config/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
os = host_machine.system()

if os == 'windows'
add_project_link_arguments(
'-Wl,--allow-multiple-definition',
language: 'fortran',
)
endif

fc = meson.get_compiler('fortran')
fc_id = fc.get_id()

if fc_id == 'gcc'
# from previous setup: "-g -O0 -Wall -fimplicit-none -fcheck=all,no-recursion
# -fbacktrace -Wno-unused-dummy-argument -Wno-unused-function"
add_project_arguments(
'-fbacktrace',
'-fcheck=all,no-recursion',
'-ffree-line-length-none',
'-fimplicit-none',
'-Wno-unused-dummy-argument',
'-Wno-unused-function',
language: 'fortran',
)
endif
Loading