Skip to content

Improved profiling modes - #601

Open
Joerg Henrichs (hiker) wants to merge 8 commits into
mainfrom
599_improved_profiling_modes
Open

Joerg Henrichs (hiker) wants to merge 8 commits into
mainfrom
599_improved_profiling_modes

Conversation

@hiker

Copy link
Copy Markdown
Collaborator

Closes #599.
It simplifies the definition of compilation profiles.

I added two commits for very minor cleanup of some tests (improved an error message, removed left-over debug print, and handled a warning, so pytest now reports all tests as green).

I have tested this with skeleton, lfric_atm, jules, um so far, and will verify that everything else is updated to use this new feature as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things.

Comment thread source/fab/tools/profile_flags.py Outdated
Comment thread source/fab/tools/profile_flags.py
Comment thread source/fab/tools/profile_flags.py
Comment thread source/fab/tools/profile_flags.py Outdated
@hiker

Copy link
Copy Markdown
Collaborator Author

Ready for next review.

@hiker Joerg Henrichs (hiker) added the Ready for review Indicating that a PR is ready to be reviewed. label Aug 31, 2026
@hiker

Copy link
Copy Markdown
Collaborator Author

Looks like I forgot to re-request the review, sorry.

Note that there is a certain interaction with #603/#604 (python 3.14). Using class variables as done in this PR will not work with python 3.14 (unless it is switched to using fork, which is what #604 does). I.e. if in the future you want to switch back to the default fork behaviour, this code will actually fail. Possible solutions:

  1. when implementing the new subprocess handling, we explicitly distribute ProfileFlags._inherit_from to the subprocesses, or:
  2. We change the implementation to use instance attributes. This then needs to make sure that if profiling modes are added, all already existing instances are updated. To do this, the following patch keeps track of all instances, and will update all of them if a profile_mode is added. Admittedly quite hacky, but it can be portably implemented now, and won't break if python 3.14 subprocess handling is switched back in the future:
diff --git a/source/fab/tools/profile_flags.py b/source/fab/tools/profile_flags.py
index 07c3a2f..d8eb307 100644
--- a/source/fab/tools/profile_flags.py
+++ b/source/fab/tools/profile_flags.py
@@ -53,10 +53,13 @@ class ProfileFlags:
     # avoid having to handle "" as special case, it is added here
     # as an always available dummy profile.
     _inherit_from: dict[str, str] = {"": ""}
+    all_instances = []
 
     def __init__(self,
                  flags: Optional[Union[AbstractFlags, str, list[str]]] = None,
                  profile: str = "") -> None:
+        self._inherit_from = ProfileFlags._inherit_from.copy()
+        ProfileFlags.all_instances.append(self)
         # Stores the flags for each profile mode. The key is the (lower case)
         # name of the profile mode, and it contains a list of flags.
         # Initialise the dict with the default (empty) profile
@@ -93,6 +96,9 @@ class ProfileFlags:
         else:
             cls._inherit_from[name] = ""
 
+        for instance in ProfileFlags.all_instances:
+            instance._inherit_from = ProfileFlags._inherit_from.copy()
+
     def get_flags(self,
                   config: Optional["BuildConfig"] = None,
                   file_path: Optional[Path] = None) -> list[str]:
@@ -139,7 +145,7 @@ class ProfileFlags:
         else:
             profile = profile.lower()
 
-        if profile and profile not in ProfileFlags._inherit_from:
+        if profile and profile not in self._inherit_from:
             raise KeyError(f"Profile '{profile}' is not defined")
 
         # First add any flags that we inherit. This will recursively call

I am happy to add this patch here (or add anything better, it is quite hacky)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks ready for trunk, pending the arrival of #604

@MatthewHambley Matthew Hambley (MatthewHambley) changed the title 599 improved profiling modes Improved profiling modes Sep 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Indicating that a PR is ready to be reviewed.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Improvements to defining profiling modes

2 participants