(module: SampleCodeModule)
| 32 | |
| 33 | |
| 34 | def load_sample_code_for_module(module: SampleCodeModule): |
| 35 | result = [] |
| 36 | assistant_directory_path = f"{resource_dir}/resources/code_templates/{module.value}" |
| 37 | language_directory_paths = {} |
| 38 | |
| 39 | for entry in os.listdir(assistant_directory_path): |
| 40 | full_path = os.path.join(assistant_directory_path, entry) |
| 41 | if os.path.isdir(full_path): # Check if it's a directory |
| 42 | language_directory_paths[trim_prefix(entry)] = full_path |
| 43 | |
| 44 | for language in language_directory_paths: |
| 45 | parts = [] |
| 46 | language_folder_path = language_directory_paths[language] |
| 47 | |
| 48 | for entry in os.listdir(language_folder_path): |
| 49 | directory_path = os.path.join(language_folder_path, entry) |
| 50 | part_name = trim_prefix(entry) |
| 51 | templates = [] |
| 52 | |
| 53 | for entry2 in os.scandir(directory_path): |
| 54 | content = load_code_template(entry2.path) |
| 55 | templates.append( |
| 56 | { |
| 57 | "template_name": reformat_string_to_headline(trim_prefix(entry2.name.replace(".md", ""))), |
| 58 | "content": content, |
| 59 | "variables": find_dollar_enclosed_substrings(content), |
| 60 | } |
| 61 | ) |
| 62 | |
| 63 | parts.append( |
| 64 | { |
| 65 | "part_name": reformat_string_to_headline(part_name), |
| 66 | "templates": templates, |
| 67 | } |
| 68 | ) |
| 69 | |
| 70 | result.append({"language_name": reformat_string_to_headline(language), "parts": parts}) |
| 71 | |
| 72 | return result |
| 73 | |
| 74 | |
| 75 | def load_code_template(code_template_path: str): |
no test coverage detected