Skip to content

Commit d2d03f0

Browse files
Adjust file types to be a set, making the inclusion of 'group' types trivial (MetOffice#193)
* Adjust file types to be a set, making the inclusion of 'group' types trivial e.g. the CI group to run tests equivalent to the CI stage on a PR. * Changing allowable groups to be a dict. * Tiny Tweak to GROUP_FILE_TYPES, and extra checks * ruff formating applied. --------- Co-authored-by: Cameron Bateman <cameron.bateman@metoffice.gov.uk>
1 parent 958eef9 commit d2d03f0

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

script_umdp3_checker/umdp3_conformance.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
"""
2121

2222

23+
ALLOWABLE_FILE_TYPES = ["Fortran", "Python", "Generic"]
24+
GROUP_FILE_TYPES = {
25+
"CI": {"Fortran", "Python"},
26+
"ALL": set(ALLOWABLE_FILE_TYPES),
27+
}
28+
# TODO: Generic /probably/ needs renaming.
29+
30+
2331
@dataclass
2432
class CheckResult:
2533
"""
@@ -422,13 +430,10 @@ def process_arguments():
422430
"--file-types",
423431
type=str,
424432
nargs="+",
425-
choices=["Fortran", "Python", "Generic"],
433+
choices=ALLOWABLE_FILE_TYPES + list(GROUP_FILE_TYPES.keys()),
426434
default=["Fortran"],
427435
help="File types to check, comma-separated",
428436
)
429-
"""
430-
TODO : I /think/ the old version also checked '.h' files as Fortran.
431-
Not sure if that is still needed."""
432437
parser.add_argument(
433438
"-p", "--path", type=str, default="./", help="path to repository"
434439
)
@@ -466,6 +471,7 @@ def process_arguments():
466471
args = parser.parse_args()
467472
# Determine output verbosity level
468473
args.volume = 3 + args.verbose - args.quiet
474+
args.file_types = detangle_file_types(set(args.file_types))
469475
return args
470476

471477

@@ -529,6 +535,25 @@ def which_cms_is_it(path: str, print_volume: int = 3) -> CMSSystem:
529535
return cms
530536

531537

538+
def detangle_file_types(file_types: Set[str]) -> Set[str]:
539+
"""Process file type arguments to handle 'group' types."""
540+
the_whole_world = set(ALLOWABLE_FILE_TYPES)
541+
the_whole_world.update(list(GROUP_FILE_TYPES.keys()))
542+
for group, members in GROUP_FILE_TYPES.items():
543+
if group in file_types:
544+
file_types.remove(group)
545+
file_types.update(members)
546+
# A bit belt and braces, in case the contents of a group gets out of
547+
# sync with what's allowable...
548+
if file_types.difference(the_whole_world):
549+
raise ValueError(
550+
"Invalid file types specified: "
551+
+ f"{file_types.difference(the_whole_world)}"
552+
+ f' in group "{group}"'
553+
)
554+
return file_types
555+
556+
532557
def create_style_checkers(
533558
file_types: List[str], changed_files: List[Path], print_volume: int = 3
534559
) -> List[StyleChecker]:
@@ -537,6 +562,9 @@ def create_style_checkers(
537562
checkers = []
538563
if "Fortran" in file_types:
539564
file_extensions = {".f", ".for", ".f90", ".f95", ".f03", ".f08", ".F90"}
565+
"""
566+
TODO : I /think/ the old version also checked '.h' files as Fortran.
567+
Not sure if that is still needed."""
540568
fortran_diff_table = dispatch_tables.get_diff_dispatch_table_fortran()
541569
fortran_file_table = dispatch_tables.get_file_dispatch_table_fortran()
542570
generic_file_table = dispatch_tables.get_file_dispatch_table_all()

0 commit comments

Comments
 (0)