-
Notifications
You must be signed in to change notification settings - Fork 184
[9.0] migrate getDIRACPlatform to DIRACCommon #8295
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
Merged
fstagni
merged 1 commit into
DIRACGrid:integration
from
chrisburr:common-getDIRACPlatform
Sep 5, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
dirac-common/src/DIRACCommon/ConfigurationSystem/Client/Helpers/Resources.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Platform utilities for DIRAC platform compatibility and management. | ||
|
|
||
| This module provides functions for working with DIRAC platforms and OS compatibility. | ||
| """ | ||
| import re | ||
|
|
||
| from DIRACCommon.Core.Utilities.ReturnValues import S_ERROR, S_OK, DReturnType | ||
|
|
||
|
|
||
| def getDIRACPlatform(osList: list[str], osCompatibilityDict: dict[str, set[str]]) -> DReturnType[list[str]]: | ||
| """Get standard DIRAC platform(s) compatible with the argument. | ||
|
|
||
| NB: The returned value is a list, ordered by numeric components in the platform. | ||
| In practice the "highest" version (which should be the most "desirable" one is returned first) | ||
|
|
||
| :param list osList: list of platforms defined by resource providers | ||
| :param dict osCompatibilityDict: dictionary with OS compatibility information | ||
| :return: a list of DIRAC platforms that can be specified in job descriptions | ||
| """ | ||
|
|
||
| if not osCompatibilityDict: | ||
| return S_ERROR("OS compatibility info not found") | ||
|
|
||
| # making an OS -> platforms dict | ||
| os2PlatformDict = dict() | ||
| for platform, osItems in osCompatibilityDict.items(): | ||
| for osItem in osItems: | ||
| os2PlatformDict.setdefault(osItem, set()).add(platform) | ||
|
|
||
| platforms = set() | ||
| for os in osList: | ||
| platforms |= os2PlatformDict.get(os, set()) | ||
|
|
||
| if not platforms: | ||
| return S_ERROR(f"No compatible DIRAC platform found for {','.join(osList)}") | ||
|
|
||
| return S_OK(sorted(platforms, key=_platformSortKey, reverse=True)) | ||
|
|
||
|
|
||
| def _platformSortKey(version: str) -> list[str]: | ||
| # Loosely based on distutils.version.LooseVersion | ||
| parts = [] | ||
| for part in re.split(r"(\d+|[a-z]+|\.| -)", version.lower()): | ||
| if not part or part == ".": | ||
| continue | ||
| if part[:1] in "0123456789": | ||
| part = part.zfill(8) | ||
| else: | ||
| while parts and parts[-1] == "00000000": | ||
| parts.pop() | ||
| parts.append(part) | ||
| return parts |
3 changes: 3 additions & 0 deletions
3
dirac-common/src/DIRACCommon/ConfigurationSystem/Client/Helpers/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem.Client.Helpers - Configuration system helper functions | ||
| """ |
3 changes: 3 additions & 0 deletions
3
dirac-common/src/DIRACCommon/ConfigurationSystem/Client/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem.Client - Configuration system client components | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem - Configuration system components | ||
| """ |
3 changes: 3 additions & 0 deletions
3
dirac-common/tests/ConfigurationSystem/Client/Helpers/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem.Client.Helpers tests | ||
| """ |
47 changes: 47 additions & 0 deletions
47
dirac-common/tests/ConfigurationSystem/Client/Helpers/test_Resources.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from itertools import zip_longest | ||
|
|
||
| import pytest | ||
|
|
||
| from DIRACCommon.ConfigurationSystem.Client.Helpers.Resources import getDIRACPlatform, _platformSortKey | ||
|
|
||
|
|
||
| MOCK_OS_COMPATIBILITY_DICT = { | ||
| "plat1": {"plat1", "OS1", "OS2", "OS3"}, | ||
| "plat2": {"plat2", "OS4", "OS5"}, | ||
| "plat3": {"plat3", "OS1", "OS4"}, | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "osCompatibilityDict, osList, expectedRes, expectedValue", | ||
| [ | ||
| ({}, ["plat"], False, None), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["plat"], False, None), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["OS1"], True, ["plat1", "plat3"]), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["OS2"], True, ["plat1"]), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["OS3"], True, ["plat1"]), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["OS4"], True, ["plat2", "plat3"]), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["OS5"], True, ["plat2"]), | ||
| (MOCK_OS_COMPATIBILITY_DICT, ["plat1"], True, ["plat1"]), | ||
| ], | ||
| ) | ||
| def test_getDIRACPlatform(osCompatibilityDict, osList, expectedRes, expectedValue): | ||
| res = getDIRACPlatform(osList, osCompatibilityDict) | ||
| assert res["OK"] is expectedRes, res | ||
| if expectedRes: | ||
| assert set(res["Value"]) == set(expectedValue), res["Value"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "string,expected", | ||
| [ | ||
| ("Darwin_arm64_12.4", ["darwin", "_", "arm", "64", "_", "12", "4"]), | ||
| ("Linux_x86_64_glibc-2.17", ["linux", "_", "x", "86", "_", "64", "_", "glibc", "-", "2", "17"]), | ||
| ("Linux_aarch64_glibc-2.28", ["linux", "_", "aarch", "64", "_", "glibc", "-", "2", "28"]), | ||
| ], | ||
| ) | ||
| def test_platformSortKey(string, expected): | ||
| actual = _platformSortKey(string) | ||
| for a, e in zip_longest(actual, expected): | ||
| # Numbers are padded with zeros so string comparison works | ||
| assert a.lstrip("0") == e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem.Client tests | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| DIRACCommon.ConfigurationSystem tests | ||
| """ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never suggested using
pixifor DIRAC (which does not have a pixi,toml), so I would just removepixi runfrom these instructions from next PR.