Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ If you are not submitting contributions on behalf of an organisation please use
| yaswant | Yaswant Pradhan | Met Office |
| hiker | Joerg Henrichs | Bureau of Meteorology, Australia |
| t00sa | Sam Clarke-Green | Met Office |
| james-bruten-mo | James Bruten | Met Office

---

Expand Down
53 changes: 25 additions & 28 deletions Documentation/fab/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@

from fab import __version__ as fab_version

sys.path.insert(0, os.path.abspath('../../../source'))
sys.path.insert(0, os.path.abspath("../../../source"))


# -- Project information -----------------------------------------------------

project = 'Fab'
copyright = '2025 Met Office. All rights reserved.'
author = 'Fab Team'
project = "Fab"
copyright = "2025 Met Office. All rights reserved."
author = "Fab Team"

# The full version, including alpha/beta/rc tags
release = fab_version

# The version up to the minor patch, for distinguishing multi-version docs
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.graphviz',
'sphinx.ext.intersphinx',
'sphinx.ext.autosectionlabel',
'sphinxcontrib.rsvgconverter',
'sphinx_autodoc_typehints',
'sphinx_copybutton',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.graphviz",
"sphinx.ext.intersphinx",
"sphinx.ext.autosectionlabel",
"sphinxcontrib.rsvgconverter",
"sphinx_autodoc_typehints",
"sphinx_copybutton",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -57,28 +57,25 @@

# -- Autodoc -----------------------------------------------------------------

autodoc_default_options = {
'members': True,
'show-inheritane': True
}
autodoc_default_options = {"members": True, "show-inheritane": True}

autoclass_content = 'both'
autoclass_content = "both"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'pydata_sphinx_theme'
html_theme = "pydata_sphinx_theme"

html_last_updated_fmt = '%Y-%m-%d %H:%M'
html_last_updated_fmt = "%Y-%m-%d %H:%M"
html_theme_options = {
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/MetOffice/fab",
"icon": "fa-brands fa-github"
"icon": "fa-brands fa-github",
}
],
"footer_start": ["crown-copyright"],
Expand All @@ -92,31 +89,31 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# Don't sort module contents alphabetically, we want to order them in a helpful way for the user to read.
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"


# Join the class and constructor docstrings.
autoclass_content = 'both'
autoclass_content = "both"

#
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

# create linkable targets from section headings
autosectionlabel_prefix_document = True


# include default values in argument descriptions
typehints_defaults = 'braces-after'
typehints_defaults = "braces-after"

# linkcheck builder
linkcheck_allow_redirects = True # Allow redirects to pass
linkcheck_ignore = [
"https://metoffice.sharepoint.com", # Ignore SharePoint links
r'.*\.py$', # Ignores URLs ending with .py
r".*\.py$", # Ignores URLs ending with .py
]
linkcheck_timeout = 2
linkcheck_allow_unauthorized = True # Allow unauthorized links to pass
1 change: 1 addition & 0 deletions Documentation/fabengine/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#
("py:class", "ListProxy"),
("py:class", "DictProxy"),
("py:class", "ValueProxy"),
("py:class", "Queue"),
("py:class", "multiprocessing.Process"),
("py:class", "multiprocessing.context.Process"),
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ version = {attr = "fab.__version__"}
[tool.setuptools.packages.find]
where = [ "source" ]

[tool.setuptools.package-data]
"fabengine.data" = ["*.yaml"]

[tool.tox]
env_list = [
{product = [ [ "3.12", "3.13", "3.14", "3.15" ], [ "coverage" ] ]},
Expand Down Expand Up @@ -155,3 +158,6 @@ deps = [
]
description = "run type check on code base"

[[tool.mypy.overrides]]
module = ["yaml.*"]
ignore_missing_imports = true
3 changes: 3 additions & 0 deletions source/fabengine/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def full(self) -> Path:
"""
return self._root / self._branch

def __str__(self) -> str:
return str(self.full)


class Prerequisite(ABC):
"""
Expand Down
75 changes: 59 additions & 16 deletions source/fabengine/actions/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def _normalise_source(source: Path) -> Generator[str, None, None]:
# we are in a comment, so look for the end of the comment
match = AnalyseC._END_COMMENT_PATTERN.match(line)
if match:
# found end of comment, switch back to seeking mode and check if there is any code after the comment ends
# found end of comment, switch back to seeking mode and check if
# there is any code after the comment ends
mode = AnalyseC.AnalysisMode.SEEKING
after_comment = match.group(1).strip()
if after_comment:
Expand All @@ -92,7 +93,8 @@ def _normalise_source(source: Path) -> Generator[str, None, None]:
# we are seeking, so look for the start of a comment
match = AnalyseC._BEGIN_COMMENT_PATTERN.match(line)
if match:
# found start of comment, switch to in_comment mode and check if there is any code before the comment starts
# found start of comment, switch to in_comment mode and check if
# there is any code before the comment starts
mode = AnalyseC.AnalysisMode.IN_COMMENT
before_comment = match.group(1).strip()
if before_comment:
Expand Down Expand Up @@ -137,7 +139,8 @@ def perform(self) -> list[Action]:
"""
Perform analyses.

:return: Every source file must be return a CompileC action, and those with a main program must also return a LinkC action.
:return: Every source file must return a CompileC action, and those with a main
program must also return a LinkC action.
"""

logger = make_logger("system")
Expand All @@ -153,7 +156,8 @@ def perform(self) -> list[Action]:
for normalised_line in self._normalise_source(
self._database.artefact_store.get_artefact(self._source)
):
# (comments and blank lines have already been removed, so we can just search for includes and main programs without worrying about comment syntax)
# (comments and blank lines have already been removed, so we can just search
# for includes and main programs without worrying about comment syntax)

match = self._MAIN_PATTERN.match(normalised_line)
if match:
Expand All @@ -164,7 +168,8 @@ def perform(self) -> list[Action]:

match = self._INCLUDE_PATTERN.match(normalised_line)
if match:
# found an include, so add a prerequisite for the included file (so long as it isn't a self-include)
# found an include, so add a prerequisite for the included file
# (so long as it isn't a self-include)
included_file = match.group(1)
included_file_basename = included_file.rpartition(".")[0]
if included_file_basename != source_basename:
Expand Down Expand Up @@ -195,8 +200,6 @@ class CompileC(SubprocessAction):
Compiles C source to object file.
"""

_COMPILER = "gcc"

def __init__(
self,
source: Path,
Expand All @@ -211,12 +214,50 @@ def __init__(
self._source = source
self._prerequisites = set(prerequisites)
self._database = database
self._compiler = database.configuration["cc"]

if not self._compiler:
raise RuntimeError(
"Attempting to compile c code but the c compiler hasn't been defined."
)

arguments = []
destination = self._source.with_suffix(".o")
arguments.extend(["-c", str(self._source), "-o", str(destination)])
arguments = [self._database.configuration["c_data"]["compile_only"]]

common_flags = self._database.configuration["c_compile_flags_common"]
openmp = self._database.configuration["openmp"]

for override_path, values in self._database.configuration[
"c_overrides"
].items():
if self._source.is_relative_to(override_path):
profile_args = values.get("compile_flags", common_flags)
openmp = values.get("openmp", openmp)
break
else:
profile_args = common_flags
for arg in profile_args:
arguments.append(arg) # noqa: PERF402

if openmp:
arguments.append(self._database.configuration["c_data"]["openmp"])

# We don't have a separate pre-process step for c code, so these are included
# here instead
arguments.extend(self._database.configuration["c_pp_flags"])
for name, value in self._database.configuration["c_pp_definitions"].items():
arguments.append(f"-D{name}={value}")

arguments.extend(
[
self._database.artefact_store.get_artefact(self._source).real_filename,
self._database.configuration["c_data"]["output_path"],
self._database.artefact_store.get_artefact(
self._source.with_suffix(".o")
).real_filename,
]
)

exe = Path(self._COMPILER)
exe = Path(self._database.configuration["cc"])
super().__init__(exe, arguments)

def __str__(self) -> str:
Expand All @@ -229,7 +270,8 @@ def prerequisites(self) -> Iterable[Prerequisite]:
Unlike Fortran, C does not have an explicit module system.
Instead, dependencies are determined by the presence of "#include" directives.
Header files will already have been imported as part of the ImportC Action.
And, the compiler automatically handles these dependencies so no explicit prerequisite rules are needed.
And, the compiler automatically handles these dependencies so no explicit
prerequisite rules are needed, other than the loading of the compile module.
"""
prereqs: list[Prerequisite] = []
return prereqs
Expand All @@ -253,8 +295,6 @@ class LinkC(SubprocessAction):
Uses C compiler to link object into executable.
"""

_LINKER = "gcc"

def __init__(
self,
source: Path,
Expand All @@ -281,11 +321,14 @@ def __init__(
prerequisite.filename.real_filename
for prerequisite in sorted(self._prerequisites)
],
"-o",
self._database.configuration["c_data"]["output_path"],
self._exe_file,
]

exe = Path(self._LINKER)
if self._database.configuration["c_link_openmp"]:
arguments.append(self._database.configuration["c_data"]["openmp"])

exe = Path(self._database.configuration["cc"])
super().__init__(exe, arguments)

def __str__(self) -> str:
Expand Down
Loading
Loading