Shallow structure to make storing subset-specific parameters cleaner.
| 58 | |
| 59 | |
| 60 | class SubsetParams(): |
| 61 | """ |
| 62 | Shallow structure to make storing subset-specific parameters cleaner. |
| 63 | """ |
| 64 | def __init__(self, target_function, upstream_depth, downstream_depth): |
| 65 | self.target_function = target_function |
| 66 | self.upstream_depth = upstream_depth |
| 67 | self.downstream_depth = downstream_depth |
| 68 | |
| 69 | @staticmethod |
| 70 | def generate(target_function, upstream_depth, downstream_depth): |
| 71 | """ |
| 72 | :param target_function str: |
| 73 | :param upstream_depth int: |
| 74 | :param downstream_depth int: |
| 75 | :rtype: SubsetParams|Nonetype |
| 76 | """ |
| 77 | if upstream_depth and not target_function: |
| 78 | raise AssertionError("--upstream-depth requires --target-function") |
| 79 | |
| 80 | if downstream_depth and not target_function: |
| 81 | raise AssertionError("--downstream-depth requires --target-function") |
| 82 | |
| 83 | if not target_function: |
| 84 | return None |
| 85 | |
| 86 | if not (upstream_depth or downstream_depth): |
| 87 | raise AssertionError("--target-function requires --upstream-depth or --downstream-depth") |
| 88 | |
| 89 | if upstream_depth < 0: |
| 90 | raise AssertionError("--upstream-depth must be >= 0. Exclude argument for complete depth.") |
| 91 | |
| 92 | if downstream_depth < 0: |
| 93 | raise AssertionError("--downstream-depth must be >= 0. Exclude argument for complete depth.") |
| 94 | |
| 95 | return SubsetParams(target_function, upstream_depth, downstream_depth) |
| 96 | |
| 97 | |
| 98 |