|
61 | 61 | "https://github.com/adafruit/circuitpython/issues/1582"
|
62 | 62 | )
|
63 | 63 | ERROR_MISMATCHED_READTHEDOCS = "Mismatched readthedocs.yaml"
|
| 64 | +ERROR_MISMATCHED_PRE_COMMIT_CONFIG = "Mismatched versions in .pre-commit-config.yaml" |
64 | 65 | ERROR_MISSING_DESCRIPTION = "Missing repository description"
|
65 | 66 | ERROR_MISSING_EXAMPLE_FILES = "Missing .py files in examples folder"
|
66 | 67 | ERROR_MISSING_EXAMPLE_FOLDER = "Missing examples folder"
|
@@ -209,6 +210,7 @@ def __init__(
|
209 | 210 | self.bundle_submodules = bundle_submodules
|
210 | 211 | self.latest_pylint = pkg_version_parse(latest_pylint)
|
211 | 212 | self._rtd_yaml_base = None
|
| 213 | + self._pcc_versions = {} |
212 | 214 | self.output_file_data = []
|
213 | 215 | self.validate_contents_quiet = kw_args.get("validate_contents_quiet", False)
|
214 | 216 | self.has_pyproject_toml_disabled = set()
|
@@ -241,6 +243,33 @@ def rtd_yml_base(self):
|
241 | 243 |
|
242 | 244 | return self._rtd_yaml_base
|
243 | 245 |
|
| 246 | + @property |
| 247 | + def pcc_versions(self): |
| 248 | + """The parsed YAML from `.pre-commit-config.yaml` in cookiecutter. |
| 249 | + Used to verify that a library's `.pre-commit-config.yaml` matches this. |
| 250 | + """ |
| 251 | + if not self._pcc_versions: |
| 252 | + pcc_yml_dl_url = ( |
| 253 | + "https://raw.githubusercontent.com/adafruit/cookiecutter-adafruit-" |
| 254 | + "circuitpython/main/%7B%7B%20cookiecutter.__dirname%20%7D%7D/.pre-" |
| 255 | + "commit-config.yaml" |
| 256 | + ) |
| 257 | + pcc_yml = requests.get(pcc_yml_dl_url) |
| 258 | + if pcc_yml.ok: |
| 259 | + try: |
| 260 | + pcc_yaml_base = yaml.safe_load(pcc_yml.text) |
| 261 | + except yaml.YAMLError: |
| 262 | + print("Error parsing cookiecutter .pre-commit-config.yaml.") |
| 263 | + pcc_yaml_base = "" |
| 264 | + else: |
| 265 | + print("Error retrieving cookiecutter .pre-commit-config.yaml") |
| 266 | + pcc_yaml_base = "" |
| 267 | + |
| 268 | + for i in pcc_yaml_base["repos"]: |
| 269 | + self._pcc_versions[i["repo"]] = i["rev"] |
| 270 | + |
| 271 | + return self._pcc_versions |
| 272 | + |
244 | 273 | @staticmethod
|
245 | 274 | def get_token_methods():
|
246 | 275 | """Return a list of method names that require authentication"""
|
@@ -705,8 +734,25 @@ def validate_contents(self, repo):
|
705 | 734 | errors.append(ERROR_MISSING_READTHEDOCS)
|
706 | 735 |
|
707 | 736 | if ".pre-commit-config.yaml" in files:
|
708 |
| - file_info = content_list[files.index(".pre-commit-config.yaml")] |
709 |
| - errors.extend(self._validate_pre_commit_config_yaml(file_info)) |
| 737 | + if len(self._pcc_versions) or self.pcc_versions != "": |
| 738 | + filename = ".pre-commit-config.yaml" |
| 739 | + file_info = content_list[files.index(filename)] |
| 740 | + pcc_contents = requests.get(file_info["download_url"]) |
| 741 | + if pcc_contents.ok: |
| 742 | + try: |
| 743 | + pcc_yml = yaml.safe_load(pcc_contents.text) |
| 744 | + pcc_versions = {} |
| 745 | + for i in pcc_yml["repos"]: |
| 746 | + pcc_versions[i["repo"]] = i["rev"] |
| 747 | + if self._pcc_versions != pcc_versions: |
| 748 | + errors.append(ERROR_MISMATCHED_PRE_COMMIT_CONFIG) |
| 749 | + except yaml.YAMLError: |
| 750 | + self.output_file_data.append( |
| 751 | + "Error parsing {} .pre-commit-config.yaml.".format( |
| 752 | + repo["name"] |
| 753 | + ) |
| 754 | + ) |
| 755 | + errors.append(ERROR_OUTPUT_HANDLER) |
710 | 756 | else:
|
711 | 757 | errors.append(ERROR_MISSING_PRE_COMMIT_CONFIG)
|
712 | 758 |
|
|
0 commit comments