Documentation
¶
Overview ¶
Package module reads an author's module and checks it as the module format says: its layout and the format version it names, each file by the YAML rules and against the schema of its part, and the format rules within each part, between parts and of the whole module — the tiers of the skill graph, the templates with every instance and solver, the leak check of the texts a learner sees before solving, and the page of a workbook. A breach names the ID of its rule and its place, and a warning of a report refuses nothing. The CLI's check and build call it, and module-registry from stage 4.
Check runs the solvers of a module's templates one on each CPU, with the caller's context, and CheckModule gives the numbers of their instances to the build of a package, so that each solver runs once.
Index ¶
- Constants
- func NewerFormat(v string) bool
- func PrimarySkills(task formatv0.Task) []formatv0.SkillID
- func ReadsFormat(v string) bool
- func SelectionOf(m formatv0.Manifest) formatv0.ManifestSelection
- func SkillTaskCounts(tasks map[formatv0.TaskID]formatv0.Task) map[formatv0.SkillID]int
- func Tiers(g formatv0.SkillGraph) (formatv0.SkillTiers, error)
- type Breach
- type Report
- type Warning
Examples ¶
Constants ¶
const ( RuleManifest = "module.manifest" RuleLayout = "module.layout" RuleFileIDs = "module.file-ids" RuleMedia = "module.media" RuleLicense = "module.license" RulePlainText = "module.plain-text" RuleFixedSet = "module.fixed-set" RuleExamples = "module.examples" RuleFormatVersion = "manifest.format-version" )
The rules of a module's folder and of its format version, as a breach names them in Rule.
const ( RuleTaskChoiceKey = "task.choice-key" RuleTaskChoiceOptions = "task.choice-options" RuleTaskFractionKey = "task.fraction-key" RuleTaskTrapValues = "task.trap-values" RuleTaskPredicateExpression = "task.predicate-expression" )
The rules of a task that the check of an answer slot sees itself.
const ( RuleTaskNoLeaks = "task.no-leaks" RuleLessonNoLeaks = "lesson.no-leaks" )
The IDs of the rules of the leak check on the texts of a module.
const ( RuleManifestDependencies = "manifest.dependencies" RuleManifestBands = "manifest.bands" RuleManifestRungTemplates = "manifest.rung-templates" RuleSkillGraphAcyclic = "skill-graph.acyclic" RuleSkillGraphKnownSkills = "skill-graph.known-skills" RuleSkillGraphRetiredIDs = "skill-graph.retired-ids" RuleSkillGraphOwnAnchors = "skill-graph.own-anchors" RuleTrapsKnownSkills = "traps.known-skills" RuleTaskKnownTraps = "task.known-traps" RuleTaskKnownTechniques = "task.known-techniques" )
The IDs of the rules of the manifest, the skill graph and the catalogs, named by the part a breach of each is reported in.
const ( RuleTaskKnownSkills = "task.known-skills" RuleTaskSkillRoles = "task.skill-roles" RuleTaskOwnAnchors = "task.own-anchors" RuleTaskKnownBand = "task.known-band" RuleTaskKnownPictures = "task.known-pictures" RuleTaskAgeCategories = "task.age-categories" RuleTaskZones = "task.zones" RuleTaskAssessability = "task.assessability" RuleLessonKnownSkills = "lesson.known-skills" RuleLessonKnownTasks = "lesson.known-tasks" RuleLessonTaskSkills = "lesson.task-skills" RuleLessonKnownPictures = "lesson.known-pictures" RuleLessonAreas = "lesson.areas" RuleLessonAgeCategories = "lesson.age-categories" RuleLessonOrder = "lesson.order" )
The IDs of the rules of a task and of a lesson that need no check kind, no leak check and no template.
const ( RuleTaskTemplateNames = template.RuleNames RuleTaskTemplateExpressions = template.RuleExpressions RuleTaskPlaceholders = template.RulePlaceholders RuleTaskTemplateInstances = template.RuleInstances RuleTaskTemplateSolver = template.RuleSolver RuleTaskInstances = "task.instances" )
The IDs of the rules of templates: those that a template breaks by itself, which package template reads, and task.instances, which holds each of its instances to the schema of a task.
const ( RuleTaskWorkbookPage = "task.workbook-page" RuleLessonExampleFills = "lesson.example-fills" RuleLessonWorkbookPage = "lesson.workbook-page" )
The IDs of the rules of a workbook's page and of a worked example on a workbook.
const FormatVersion = "0.5"
FormatVersion is the version of the module format that this library reads: the version of the schemas that internal/schema holds, a copy of those of spec.Format, and of the test vectors. While the format is v0, it is the one version the library reads.
Variables ¶
This section is empty.
Functions ¶
func NewerFormat ¶ added in v0.1.22
NewerFormat says whether v, a format version MAJOR.MINOR, is newer than FormatVersion: by its major number, then its minor, each by its value, so that 0.10 is newer than 0.9. A v that is no version MAJOR.MINOR is newer than none. The build of the module index reads a previous index by it.
func PrimarySkills ¶ added in v0.4.0
PrimarySkills gives the primary skills of a task's items — an item's own, or the task's for an item that names none —, in the order of the items and of their lists, each once: the skills that the page of a module shows on an example of it.
func ReadsFormat ¶
ReadsFormat says whether the library reads a module written in the format version v, as a manifest names it in module_format_version: while the format is v0, only FormatVersion.
func SelectionOf ¶ added in v0.4.0
func SelectionOf(m formatv0.Manifest) formatv0.ManifestSelection
SelectionOf gives how the platform gives the tasks of the module whose manifest is m: the selection it names, or adaptive when it names none.
func SkillTaskCounts ¶ added in v0.4.0
SkillTaskCounts gives how many of tasks train each skill, by its local ID: a task counts once for each of its PrimarySkills, and a template once, whatever the number of its instances. A skill that no task trains has no key. The page of a module shows these counts beside the skills.
func Tiers ¶ added in v0.1.12
func Tiers(g formatv0.SkillGraph) (formatv0.SkillTiers, error)
Tiers gives the tier of each skill of a skill graph: tier 1 for a skill with no prerequisite among the module's skills, and one tier above the highest of its prerequisites among them for every other, so that an anchor skill counts for none. The package holds them in its canonical view, as skill_tiers. A graph whose prerequisites name a skill that it does not have, or run in a cycle, has no tiers: it breaks skill-graph.known-skills or skill-graph.acyclic, and Tiers gives an error.
Types ¶
type Breach ¶
type Breach struct {
Rule string
// The keyword of JSON Schema 2020-12 that fails, such as required or pattern, when the breach is
// of the schema; its place is then Pointer, where the schema holding the keyword applies, as an
// example of the format names it.
Keyword string
// The file or folder from the module's folder, with / between names, as the folder lists them;
// "." for the module's folder itself, as fs.FS names it, and empty for the file that CheckFile
// checks, which has no path.
Path string
// The place in the file, line and column from 1: in a file of a part as yaml.Breach counts them,
// and in LICENSE and NOTICE with every line ended by LF alone. 0 when the breach is of the file
// as a whole or of a value in it.
Line, Column int
// The value in the file that breaks the rule, as a JSON Pointer in URI fragment form, such as
// #/module_format_version; empty when the breach is of no value.
Pointer string
Message string
}
A Breach is one reason a module is refused: a rule it breaks; or, when Rule is empty, a keyword of the schema of its part that a file fails, which Keyword names; or, when both are empty, a file of a part that is not YAML 1.2.2, which the format refuses without an ID.
type Report ¶
A Report is what the check of a module finds: every breach, in the order of their places — the path, then the line and column, then the value, member by member, with an element of an array by its index —, and at one place in the order of their rules and keywords, so that it does not depend on the order in which the folder lists its files. A report with no breach accepts the module. Its warnings, in the order of their places, refuse nothing: a module with warnings and no breach is accepted. Check gives them and CheckFile none, since a warning has no test vectors.
func Check ¶
Check reads the module whose folder is the root of fsys and checks it by the format version FormatVersion: its layout, each file of a part by the YAML rules and against the schema of its part, and the files that both accept by the rules of the parts. A manifest that names a version the library does not read gives a report of that breach alone, since the rest of the module is written by rules the library does not know. The error is for a folder or file that could not be read, and then there is no report.
The solvers of the module's templates run with ctx, one on each CPU that the process may use at once, runtime.GOMAXPROCS(0), and the report holds their breaches in the order of their places, as it holds every other. Once ctx is done the check stops, and its error is that of ctx.
Example ¶
report, err := Check(context.Background(), fstest.MapFS{
"Manifest.yaml": {Data: []byte(manifest)},
"LICENSE": {Data: []byte("The text of the license.\r\n")},
})
if err != nil {
panic(err)
}
fmt.Println(report)
Output: .: module.manifest: the folder holds no file manifest.yaml LICENSE:1:25: module.plain-text: holds a carriage return: every line ends with LF alone Manifest.yaml: module.layout: stands at no path of the layout of a module
func CheckFile ¶
CheckFile checks a file of a part on its own, as an example of the part and a test vector of a part's rule in a file are checked: by the YAML rules and against the schema of the part, and, when both accept it, by the rules within its part; a manifest first by the format version it names, which, when the library does not read it, is the report's only breach, as in Check. Its breaches have no path. part is the term of a part of the layout, such as manifest or task; any other is an error, and so is a file that the reader of YAML cannot read.
func CheckModule ¶ added in v0.1.25
CheckModule is Check, and gives besides the numbers of the instances of each template of a module that breaks no rule, by the local ID of its task, in the order of the template's counter with the results of its solver, as the canonical view holds them; none when the module has no template or is refused. The build of a package takes them, so that a solver runs once for the check and the package together.
type Warning ¶ added in v0.2.6
A Warning is what a text of the module asks of its author, though the format refuses nothing for it: a text of the whole module that holds a number — the manifest's tagline or a paragraph of its description, a rung template, a trap's advice, a technique, a solving step. A warning is no rule: it has no ID and no test vectors, and changes no report's verdict. Path is the file from the module's folder, with / between names, and Pointer the place of the text in it.