Return True or False depending on whether the given version satisfies the gitlab constraint For example: >>> assert gitlab_constraints_satisfied("[7.0.0,7.0.11),[7.2.0,7.2.4)", "7.2.1") == True >>> assert gitlab_constraints_satisfied("[7.0.0,7.0.11),[7.2.0,7.2.4)", "8.2.1") == False
(gitlab_constraint, version)
| 128 | |
| 129 | |
| 130 | def gitlab_constraints_satisfied(gitlab_constraint, version): |
| 131 | """ |
| 132 | Return True or False depending on whether the given version satisfies the gitlab constraint |
| 133 | For example: |
| 134 | >>> assert gitlab_constraints_satisfied("[7.0.0,7.0.11),[7.2.0,7.2.4)", "7.2.1") == True |
| 135 | >>> assert gitlab_constraints_satisfied("[7.0.0,7.0.11),[7.2.0,7.2.4)", "8.2.1") == False |
| 136 | >>> assert gitlab_constraints_satisfied( ">=4.0,<4.3||>=5.0,<5.2", "5.4") == False |
| 137 | >>> assert gitlab_constraints_satisfied( ">=0.19.0 <0.30.0", "0.24") == True |
| 138 | >>> assert gitlab_constraints_satisfied( ">=1.5,<1.5.2", "2.2") == False |
| 139 | """ |
| 140 | |
| 141 | gitlab_constraints = gitlab_constraint.strip() |
| 142 | if gitlab_constraints.startswith(("[", "(")): |
| 143 | # transform "[7.0.0,7.0.11),[7.2.0,7.2.4)" -> [ "[7.0.0,7.0.11)", "[7.2.0,7.2.4)" ] |
| 144 | splitted = gitlab_constraints.split(",") |
| 145 | constraints = [f"{a},{b}" for a, b in zip(splitted[::2], splitted[1::2])] |
| 146 | delimiter = "," |
| 147 | |
| 148 | else: |
| 149 | # transform ">=4.0,<4.3||>=5.0,<5.2" -> [ ">=4.0,<4.3", ">=5.0,<5.2" ] |
| 150 | # transform ">=0.19.0 <0.30.0" -> [ ">=0.19.0 <0.30.0" ] |
| 151 | # transform ">=1.5,<1.5.2" -> [ ">=1.5,<1.5.2" ] |
| 152 | delimiter = "," if "," in gitlab_constraints else " " |
| 153 | constraints = gitlab_constraints.split("||") |
| 154 | |
| 155 | for constraint in constraints: |
| 156 | is_constraint_satisfied = True |
| 157 | for subconstraint in constraint.strip().split(delimiter): |
| 158 | if not subconstraint: |
| 159 | continue |
| 160 | gitlab_comparator, gitlab_version = parse_constraint(subconstraint.strip()) |
| 161 | if not gitlab_version: |
| 162 | continue |
| 163 | if not compare( |
| 164 | GenericVersion(version), gitlab_comparator, GenericVersion(gitlab_version) |
| 165 | ): |
| 166 | is_constraint_satisfied = False |
| 167 | break |
| 168 | |
| 169 | if is_constraint_satisfied: |
| 170 | return True |
| 171 | return False |
| 172 | |
| 173 | |
| 174 | def get_item(entity: Union[dict, list], *attributes): |
no test coverage detected