Skip to content

Single source of truth #4249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ jobs:
path: firedrake-repo
ref: ${{ inputs.source_ref }}

- name: Install system dependencies
- name: Install Python
run: |
apt-get update
apt-get -y install python3 python3-venv

- name: Validate single source of truth
run: ./firedrake-repo/scripts/check-config

- name: Install system dependencies
run: |
apt-get -y install \
$(python3 ./firedrake-repo/scripts/firedrake-configure --arch ${{ matrix.arch }} --show-system-packages)
: # Dependencies needed to run the test suite
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ dependencies = [
"h5py>3.12.1",
"libsupermesh",
"loopy>2024.1",
# NOTE: If changing the PETSc/SLEPc version then firedrake-configure also needs
# changing (as well as other references to petsc4py and slepc4py here)
"petsc4py==3.23.0",
"numpy",
"packaging",
Expand Down
111 changes: 111 additions & 0 deletions scripts/check-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python3

"""Script that makes sure that hardcoded version numbers are consistent.

It reads in Firedrake's 'config.ini' file and makes sure that everywhere a
version number is hardcoded that it matches the expected value. This allows
for single-source-of-truth of hardcoded values (via CI).

"""

import pathlib
import re
from collections.abc import Mapping


REPO_ROOT = pathlib.Path(__file__).parent.parent


class InvalidConfigurationException(Exception):
pass


def main():
check_firedrake_version()
check_min_python_version()
check_petsc_version()
check_petsc_version_spec()


def check_firedrake_version():
firedrake_version = check_file_contains_pattern(
REPO_ROOT / "pyproject.toml",
f"version = \"(.*)\""
)
check_file_contains_pattern(
REPO_ROOT / "docs/source/install.rst",
f"https://raw.githubusercontent.com/firedrakeproject/firedrake/refs/tags/{firedrake_version}/scripts/firedrake-configure"
)


def check_min_python_version() -> None:
min_python_version = check_file_contains_pattern(
REPO_ROOT / "pyproject.toml",
f"requires-python = \">=(.*)\""
)
check_file_contains_pattern(
REPO_ROOT / "docs/source/install.rst",
f"Python \\({min_python_version} or greater\\)"
)


def check_petsc_version() -> None:
petsc_version = check_file_contains_pattern(
REPO_ROOT / "scripts/firedrake-configure",
f"SUPPORTED_PETSC_VERSION = \"v(.*)\"",
)
check_file_contains_pattern(
REPO_ROOT / "pyproject.toml",
f"petsc4py=={petsc_version}",
2,
)
check_file_contains_pattern(
REPO_ROOT / "pyproject.toml",
f"slepc4py=={petsc_version}",
3,
)


def check_petsc_version_spec() -> None:
# TODO when https://github.com/firedrakeproject/firedrake/pull/4194 is merged
pass


def check_file_contains_pattern(
filename: pathlib.Path | str,
pattern: str,
num_expected_matches: int = 1,
) -> str:
"""Check that the regex pattern exists in the file.

Parameters
----------
filename :
The filename.
pattern :
The regular expression pattern to look for.
num_expected_matches :
The number of expected matches.

Returns
-------
str :
The matched value. This follows the semantics of `re.findall`.

"""
with open(filename) as f:
text = f.read()
matches = re.findall(pattern, text)
if len(matches) != num_expected_matches:
raise InvalidConfigurationException(
f"Expected to find {num_expected_matches} matches for '{pattern}' in "
f"{filename} but found {len(matches)}"
)

# all the matches should be the same so just return one of them
match, = set(matches)
return match


if __name__ == "__main__":
main()
2 changes: 0 additions & 2 deletions scripts/firedrake-configure
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ ARCH_DEFAULT = FiredrakeArch.DEFAULT
ARCH_COMPLEX = FiredrakeArch.COMPLEX


# NOTE: When updating this variable corresponding changes must be made inside
# pyproject.toml
SUPPORTED_PETSC_VERSION = "v3.23.0"


Expand Down