Skip to content

Commit 8c9a10c

Browse files
committed
verify .readthedocs.yml with parsed yaml vs. the file's sha
1 parent 61c7e4c commit 8c9a10c

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

adabot/lib/circuitpython_library_validators.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pylint import lint
3434
from pylint.reporters import JSONReporter
3535
from sh.contrib import git
36+
import yaml
3637

3738
from adabot import github_requests as github
3839
from adabot import pypi_requests as pypi
@@ -187,11 +188,45 @@ def __init__(self, validators, bundle_submodules, latest_pylint, keep_repos=Fals
187188
self.validators = validators
188189
self.bundle_submodules = bundle_submodules
189190
self.latest_pylint = pkg_version_parse(latest_pylint)
191+
self._rtd_yaml_base = None
190192
self.output_file_data = []
191193
self.validate_contents_quiet = kw_args.get("validate_contents_quiet", False)
192194
self.has_setup_py_disabled = set()
193195
self.keep_repos = keep_repos
194196

197+
198+
@property
199+
def rtd_yml_base(self):
200+
""" The parsed YAML from `.readthedocs.yml` in the cookiecutter-adafruit-circuitpython repo.
201+
Used to verify that a library's `.readthedocs.yml` matches this version.
202+
"""
203+
if self._rtd_yaml_base is None:
204+
rtd_yml_dl_url = (
205+
"https://raw.githubusercontent.com/adafruit/cookiecutter-adafruit-"
206+
"circuitpython/master/%7B%25%20if%20cookiecutter.library_prefix"
207+
"%20%25%7D%7B%7B%20cookiecutter.library_prefix%20%7C%20capitalize"
208+
"%20%7D%7D_%7B%25%20endif%20%25%7DCircuitPython_%7B%7B%20cookiecutter"
209+
".library_name%7D%7D/%7B%25%20if%20cookiecutter.sphinx_docs%20in"
210+
"%20%5B'y'%2C%20'yes'%5D%20%25%7D.readthedocs.yml%7B%25%20endif"
211+
"%20%25%7D"
212+
)
213+
rtd_yml = requests.get(rtd_yml_dl_url)
214+
if rtd_yml.ok:
215+
try:
216+
self._rtd_yaml_base = yaml.safe_load(rtd_yml.text)
217+
except yaml.YAMLError:
218+
print(
219+
"Error parsing cookiecutter .readthedocs.yml."
220+
)
221+
self._rtd_yaml_base = ""
222+
else:
223+
print(
224+
"Error retrieving cookiecutter .readthedocs.yml"
225+
)
226+
self._rtd_yaml_base = ""
227+
228+
return self._rtd_yaml_base
229+
195230
def run_repo_validation(self, repo):
196231
"""Run all the current validation functions on the provided repository and
197232
return their results as a list of string errors.
@@ -652,13 +687,22 @@ def validate_contents(self, repo):
652687
errors.append(ERROR_UNABLE_PULL_REPO_CONTENTS)
653688

654689
if "readthedocs.yml" in files or ".readthedocs.yml" in files:
655-
fn = "readthedocs.yml"
656-
if ".readthedocs.yml" in files:
657-
fn = ".readthedocs.yml"
658-
file_info = content_list[files.index(fn)]
659-
if (file_info["sha"] != "f4243ad548bc5e4431f2d3c5d486f6c9c863888b" and
660-
file_info["sha"] != "78a4671650248f4382e6eb72dab71c2d86824ca2"):
661-
errors.append(ERROR_MISMATCHED_READTHEDOCS)
690+
if self.rtd_yml_base != "":
691+
fn = "readthedocs.yml"
692+
if ".readthedocs.yml" in files:
693+
fn = ".readthedocs.yml"
694+
file_info = content_list[files.index(fn)]
695+
rtd_contents = requests.get(file_info["download_url"])
696+
if rtd_contents.ok:
697+
try:
698+
rtd_yml = yaml.safe_load(rtd_contents.text)
699+
if rtd_yml != self.rtd_yml_base:
700+
errors.append(ERROR_MISMATCHED_READTHEDOCS)
701+
except yaml.YAMLError:
702+
self.output_file_data.append(
703+
"Error parsing {} .readthedocs.yml.".format(repo["name"])
704+
)
705+
errors.append(ERROR_OUTPUT_HANDLER)
662706
else:
663707
errors.append(ERROR_MISSING_READTHEDOCS)
664708

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ chardet==3.0.4
33
idna==2.6
44
packaging==20.3
55
pylint
6+
pyyaml==5.4.1
67
redis==2.10.6
78
requests==2.20.0
89
sh==1.12.14

0 commit comments

Comments
 (0)