This document explains how to add checks to edx-repo-health.
To get a better understanding of how check functions work, read the Check Functions doc.
- Define what information you are gathering
- Review existing checks for reuse or extension
- Write your check(s).
- Document you check(s).
- write code to get your info
- Add info to all_results dictionary
- Document the key(s) added to all_results dictionary
Some guidelines:
- keep your check function body as small as possible
- as a standard, only add one key per check to all_results dict
- use pytest fixtures to implement lines of code used by multiple checks
- often, multiple checks need info from same file, so we've implemented file read as a fixture
- if you are creating a new module for your checks, define a module_dict_key at top of file
- add info to "all_results" by::
- all_results[module_dict_key]["info_key"]=result
To make it easier to programmatically handle each check/info, we use Decorators to add docs on each key defined by your checks:
- the decorators are imported from pytest-repo-health
- if your check adds more than one key to "all_results dictionary"
- use "@health_metadata" decorator
- if the function(check) is only adding one key to "all_results" dictionary
- write your documentation on the key in check doc string
- declare the key using "@add_key_to_metadata" decorator
In the example below, the decorator add_key_to_metadata assumes the doc string is the info about the key "upgrade":
@add_key_to_metadata((module_dict_key, "upgrade")) def check_has_upgrade(makefile, all_results): """ upgrade: makefile target that upgrades our dependencies to newer released versions """ code ... all_results[module_dict_key]["upgrade"]=True
Installing this repo (with make requirements
) will also install the
pytest-repo-health tools. See the pytest-repo-health repo for details on
using pytest to run the checks.