Skip to content

Commit 659ede2

Browse files
authored
Merge pull request #149 from sommersoft/validate_pylint
Re-establish Pylint Version Checks
2 parents 41470ea + 1da66a7 commit 659ede2

File tree

1 file changed

+74
-23
lines changed

1 file changed

+74
-23
lines changed

adabot/lib/circuitpython_library_validators.py

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
ERROR_UNABLE_PULL_REPO_EXAMPLES = "Unable to pull repository examples files"
103103
ERROR_NOT_ON_PYPI = "Not listed on PyPi for CPython use"
104104
ERROR_PYLINT_VERSION_NOT_FIXED = "PyLint version not fixed"
105-
ERROR_PYLINT_VERSION_VERY_OUTDATED = "PyLint version very out of date"
106105
ERROR_PYLINT_VERSION_NOT_LATEST = "PyLint version not latest"
107106
ERROR_NEW_REPO_IN_WORK = "New repo(s) currently in work, and unreleased"
108107

@@ -156,7 +155,7 @@ class library_validator():
156155
def __init__(self, validators, bundle_submodules, latest_pylint, **kw_args):
157156
self.validators = validators
158157
self.bundle_submodules = bundle_submodules
159-
self.latest_pylint = latest_pylint
158+
self.latest_pylint = latest_pylint.replace(".", "")
160159
self.full_auth = None
161160
self.output_file_data = []
162161
self.github_token = kw_args.get("github_token", False)
@@ -372,41 +371,71 @@ def _validate_py_for_u_modules(self, repo, download_url):
372371

373372
return errors
374373

375-
def _validate_travis_yml(self, repo, travis_yml_file_info):
376-
"""DISABLED/NO LONGER CALLED: Check size and then check pypi compatibility.
374+
def _validate_actions_build_yml(self, repo, actions_build_info):
375+
"""Check the following configurations in the GitHub Actions
376+
build.yml file:
377+
- Pylint version is the latest release
377378
"""
378-
return []
379379

380-
download_url = travis_yml_file_info["download_url"]
380+
download_url = actions_build_info["download_url"]
381381
contents = requests.get(download_url, timeout=30)
382382
if not contents.ok:
383383
return [ERROR_PYFILE_DOWNLOAD_FAILED]
384384

385385
errors = []
386386

387-
lines = contents.text.split("\n")
388-
pypi_providers_lines = (
389-
[l for l in lines
390-
if re.match(r"[\s]*-[\s]*provider:[\s]*pypi[\s]*", l)]
387+
pylint_version = None
388+
re_pip_pattern = r"pip\sinstall.*"
389+
re_pylint_pattern = (
390+
r"pylint(?P<eval>(?:[<>~=]){0,2})(?P<major>\d*)(?P<minor>(?:\.\d){0,2})"
391391
)
392392

393-
if not pypi_providers_lines:
394-
errors.append(ERROR_MISSING_PYPIPROVIDER)
393+
pip_line = re.search(re_pip_pattern, contents.text)
394+
if not pip_line:
395+
return [ERROR_PYLINT_VERSION_NOT_FIXED]
396+
397+
pip_line = pip_line[0]
398+
399+
pylint_info = re.search(re_pylint_pattern, pip_line)
400+
if not pylint_info:
401+
return [ERROR_PYLINT_VERSION_NOT_FIXED]
402+
403+
if pylint_info.group("eval"):
404+
pylint_version = (
405+
f"{pylint_info.group('major')}"
406+
f"{pylint_info.group('minor').replace('.', '')}"
407+
)
408+
eval_func = pylint_info.group("eval")
409+
eval_len = len(pylint_version)
410+
411+
if "<" in eval_func:
412+
eval_str = (
413+
f"{self.latest_pylint[:eval_len]} "
414+
f"{eval_func} "
415+
f"{pylint_version}"
416+
)
417+
elif "~" not in eval_func:
418+
eval_str = (
419+
f"{pylint_version} "
420+
f"{eval_func} "
421+
f"{self.latest_pylint[:eval_len]}"
422+
)
423+
else:
424+
return [ERROR_PYLINT_VERSION_NOT_FIXED]
395425

396-
pylint_version = None
397-
for line in lines:
398-
if not line.strip().startswith("- pip install --force-reinstall pylint=="):
399-
continue
400-
pylint_version = line.split("=")[-1]
426+
else:
427+
pylint_version = self.latest_pylint
428+
eval_str = "True"
429+
430+
#print(
431+
# f"{repo['name']}: pylint_version: {pylint_version} latest: {self.latest_pylint}\n"
432+
# f"{pylint_info.groups()} eval_str: {eval_str}"
433+
#)
401434

402435
if not pylint_version:
403436
errors.append(ERROR_PYLINT_VERSION_NOT_FIXED)
404-
# disabling below for now, since we know all pylint versions are old
405-
# will re-enable once efforts are underway to update pylint
406-
#elif pylint_version.startswith("1."):
407-
# errors.append(ERROR_PYLINT_VERSION_VERY_OUTDATED)
408-
#elif pylint_version != self.latest_pylint:
409-
# errors.append(ERROR_PYLINT_VERSION_NOT_LATEST)
437+
elif not eval(eval_str):
438+
errors.append(ERROR_PYLINT_VERSION_NOT_LATEST)
410439

411440
return errors
412441

@@ -506,6 +535,28 @@ def validate_contents(self, repo):
506535

507536
if ".travis.yml" in files:
508537
errors.append(ERROR_NEEDS_ACTION_MIGRATION)
538+
elif ".github" in files:
539+
# grab '.github' entry, extract URL, build new URL to build.yml, retrieve and pass
540+
build_yml_url = ""
541+
actions_build_info = None
542+
543+
for item in content_list:
544+
if item.get("name") == ".github" and item.get("type") == "dir":
545+
build_yml_url = item["url"].split("?")[0]
546+
break
547+
548+
if build_yml_url:
549+
build_yml_url = build_yml_url + "/workflows/build.yml"
550+
response = github.get(build_yml_url)
551+
if response.ok:
552+
actions_build_info = response.json()
553+
554+
if actions_build_info:
555+
errors.extend(
556+
self._validate_actions_build_yml(repo, actions_build_info)
557+
)
558+
else:
559+
errors.append(ERROR_UNABLE_PULL_REPO_CONTENTS)
509560

510561
if "readthedocs.yml" in files or ".readthedocs.yml" in files:
511562
fn = "readthedocs.yml"

0 commit comments

Comments
 (0)