Coverage for /home/ubuntu/rolling-pin/python/rolling_pin/conform_config.py: 100%
31 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-13 19:35 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-13 19:35 +0000
1from typing import Dict, List # noqa: F401
3from pathlib import Path
5from schematics import Model
6from schematics.exceptions import ValidationError
7from schematics.types import ListType, ModelType, StringType
9Rules = List[Dict[str, str]]
10# ------------------------------------------------------------------------------
13def is_dir(dirpath):
14 # type: (str) -> None
15 '''
16 Validates whether a given dirpath exists.
18 Args:
19 dirpath (str): Directory path.
21 Raises:
22 ValidationError: If dirpath is not a directory or does not exist.
23 '''
24 if not Path(dirpath).is_dir():
25 msg = f'{dirpath} is not a directory or does not exist.'
26 raise ValidationError(msg)
29class ConformConfig(Model):
30 '''
31 A class for validating configurations supplied to ConformETL.
33 Attributes:
34 source_rules (Rules): A list of rules for parsing directories.
35 Default: [].
36 rename_rules (Rules): A list of rules for renaming source filepath
37 to target filepaths. Default: [].
38 group_rules (Rules): A list of rules for grouping files.
39 Default: [].
40 line_rules (Rules): A list of rules for peforming line copies and
41 substitutions on files belonging to a given group. Default: [].
42 '''
43 class SourceRule(Model):
44 path = StringType(required=True, validators=[is_dir]) # type: StringType
45 include = StringType(required=False, serialize_when_none=False) # type: StringType
46 exclude = StringType(required=False, serialize_when_none=False) # type: StringType
48 class RenameRule(Model):
49 regex = StringType(required=True) # type: StringType
50 replace = StringType(required=True) # type: StringType
52 class GroupRule(Model):
53 name = StringType(required=True) # type: StringType
54 regex = StringType(required=True) # type: StringType
56 class LineRule(Model):
57 group = StringType(required=True) # type: StringType
58 include = StringType(required=False, serialize_when_none=False) # type: StringType
59 exclude = StringType(required=False, serialize_when_none=False) # type: StringType
60 regex = StringType(required=False) # type: StringType
61 replace = StringType(required=False) # type: StringType
63 source_rules = ListType(ModelType(SourceRule), required=True) # type: ListType
64 rename_rules = ListType(ModelType(RenameRule), required=False) # type: ListType
65 group_rules = ListType(ModelType(GroupRule), required=False) # type: ListType
66 line_rules = ListType(ModelType(LineRule), required=False) # type: ListType