API#
The primary way to use courseutils
is through the CLI as outlined through, but it can also be used as a Python library.
This API is also useful for extending the CLI. Many of these functions offer flexible processing of basic information that could be used to create additional CLI functionality beyond what is already implemented.
Warning
some functions are incomplete
Badges#
- cspt.badges.badges_by_type(approved_prs)#
parse list of approved PRs to filter for badges
- Parameters:
approved_prs (list) – list of titles or list of dicts with ‘title’ as a key
- Returns:
badges_by_type – dict with keys as badge types, keys as input type
- Return type:
dict
- cspt.badges.check_approved(pr, any=False)#
check a pr dictionary for approval by default only approvers count
- Parameters:
pr (dict)
--json (single pr info from gh pr list)
any (bool) – if True consider any approavl
- Returns:
approved – True if approved by an eligible approver
- Return type:
bool
- cspt.badges.generate_report(approved_prs, short=False)#
format approved prs into a report
- cspt.badges.is_title_gradeable(pr_title, errortype=False)#
this defines if a pr title is good, it contains exactly one badge type word and a well date if experience, review or practice, in ISO (YYYY-MM-DD, YYYY MM DD) or M/DD/YY, MM-DD-YY or M-DD-YY
- Parameters:
title (string) – title of pr
errortype (bool) – if true, return bool + message
- Returns:
good – true if good
- Return type:
bool
- cspt.badges.process_pr_json(json_output, numbered=False, titles_only=False, filter_list=['approved', 'good_title'], custom_field_parser={}, custom_filters={}, filter_mode='filter')#
process gh cli json
- Parameters:
json_output (filename) – dictionary generated from gh pr list -s all –json title,latestReviews and optionally additional fields
numbered (bool) – return with numbers as keys in dict
titles_only (bool) – return titles as list
custom_field_parser (dict) – dictionary with keys matching fields in the json result and values as functions to apply to each feild before use, overwrites defaults in field_parser
custom_filters (dict) – dictionary with keys as names, values that are boolean functions
filter_mode (string {'filter'}) – filter to keep only ones that pass each filer or ‘group’ to group prs by which filter they pass
- Returns:
filtered_prs – list or dict as per value above if a flag is used or dict that is like the input json
- Return type:
iterable
Task Tracking#
- cspt.tasktracking.calculate_badge_date(assignment_type, date_to_use=None)#
return the date of the most recent past class except if prepare, then the next upcoming class
- Parameters:
assignment_type (str) – one of prepare, review, or practice
date_to_use (srt) – a date to use in iso format or none to use current day
- cspt.tasktracking.date_label(badge_date_str, today=None)#
- cspt.tasktracking.determine_issue_statuses(issue_json, as_of_date=None)#
- cspt.tasktracking.fetch_to_checklist(date, assignment_type='prepare')#
get assignment text and change numbered items to a checklist
- Parameters:
date (string) – YYYY-MM-DD formatted strings of the date to get
assignment_type
Notes#
- cspt.notes.init_activity_files(base_path, date_in)#
create blanks and link
- cspt.notes.link_activities()#
Append activities via include to a file for all lessons
FIXME… incomplete/possibly broken
- cspt.notes.process_export(export, date_in)#
Prep#
- cspt.prep.load_lesson(file_path, sep='---')#
load a lesson file
- cspt.prep.parse_soln_file(filename, strip=True)#
strip solutions from activity file and echo result
parameter#
file: path
- cspt.prep.swap_separators(file_string)#
Lesson Objects#
- class cspt.lesson.Lesson(text, debug=False)#
- create_ac_file(ac_type, file_out, base_site_path)#
extract activity instructions from lesson plan and write to file
- Parameters:
ac_type (str) – prepare, practice, or review
base_site_path (str or path) – site path
file_out (str) – file nam to sace the file
- filter_blocks(label, values)#
filter blocks for ones that have value for the label
- Parameters:
label (string) – label that is one the of keys in block metadata
value (string) – value to filter for
- get_codeblocks()#
produce hint sheet that is only the code blocks with an identifier
- get_handout()#
produce a handout that serves as an outline for students to follow along
- get_prismia()#
get prismia version
- print_bad()#
format bad blocks for debugging
- save(file_out)#
write out lesson to file_out
- Parameters:
file_out (string or file buffer) – where to write file
- valid()#
check if any errors
- class cspt.lesson.Block(text)#
- add_label(label, value)#
add an additional key value pair, label:value to the labels for the block
- Parameters:
label (string) – key to add to label attribute of block
value (string or string-like) – value to store
- add_labels(label_dict)#
add an additional key value pair, label:value to the labels for the block
- Parameters:
label_dict (dict) – key, value pairs to add
- export()#
export back to srting
- get_handout()#
return handout version (only heading lines)
- get_prismia()#
return this block formatted for prisma, stripping admonitions and empty after filter
- get_site()#
return the version of this block for the site, or empty if not the right lesson part
- is_labeled(label, values)#
does this block have any of values in the label field
- Parameters:
label (string) – field to search for
values (string or list) – value(s) to check for.