mdxcanvas 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. mdxcanvas-0.0.0/LICENSE +21 -0
  2. mdxcanvas-0.0.0/PKG-INFO +27 -0
  3. mdxcanvas-0.0.0/mdxcanvas/VERSION +1 -0
  4. mdxcanvas-0.0.0/mdxcanvas/__init__.py +3 -0
  5. mdxcanvas-0.0.0/mdxcanvas/deploy/__init__.py +0 -0
  6. mdxcanvas-0.0.0/mdxcanvas/deploy/algorithms.py +143 -0
  7. mdxcanvas-0.0.0/mdxcanvas/deploy/announcement.py +25 -0
  8. mdxcanvas-0.0.0/mdxcanvas/deploy/assignment.py +38 -0
  9. mdxcanvas-0.0.0/mdxcanvas/deploy/canvas_deploy.py +462 -0
  10. mdxcanvas-0.0.0/mdxcanvas/deploy/checksums.py +131 -0
  11. mdxcanvas-0.0.0/mdxcanvas/deploy/course_settings.py +24 -0
  12. mdxcanvas-0.0.0/mdxcanvas/deploy/file.py +54 -0
  13. mdxcanvas-0.0.0/mdxcanvas/deploy/group.py +23 -0
  14. mdxcanvas-0.0.0/mdxcanvas/deploy/migration.py +98 -0
  15. mdxcanvas-0.0.0/mdxcanvas/deploy/module.py +51 -0
  16. mdxcanvas-0.0.0/mdxcanvas/deploy/override.py +49 -0
  17. mdxcanvas-0.0.0/mdxcanvas/deploy/page.py +33 -0
  18. mdxcanvas-0.0.0/mdxcanvas/deploy/quiz.py +154 -0
  19. mdxcanvas-0.0.0/mdxcanvas/deploy/syllabus.py +16 -0
  20. mdxcanvas-0.0.0/mdxcanvas/deploy/util.py +29 -0
  21. mdxcanvas-0.0.0/mdxcanvas/deploy/zip.py +128 -0
  22. mdxcanvas-0.0.0/mdxcanvas/deployment_report.py +57 -0
  23. mdxcanvas-0.0.0/mdxcanvas/erasecanvas/__init__.py +0 -0
  24. mdxcanvas-0.0.0/mdxcanvas/erasecanvas/main.py +132 -0
  25. mdxcanvas-0.0.0/mdxcanvas/error_helpers.py +66 -0
  26. mdxcanvas-0.0.0/mdxcanvas/extensions.py +97 -0
  27. mdxcanvas-0.0.0/mdxcanvas/main.py +234 -0
  28. mdxcanvas-0.0.0/mdxcanvas/our_logging.py +26 -0
  29. mdxcanvas-0.0.0/mdxcanvas/processing_context.py +31 -0
  30. mdxcanvas-0.0.0/mdxcanvas/resources.py +138 -0
  31. mdxcanvas-0.0.0/mdxcanvas/text_processing/__init__.py +0 -0
  32. mdxcanvas-0.0.0/mdxcanvas/text_processing/github-light.css +88 -0
  33. mdxcanvas-0.0.0/mdxcanvas/text_processing/inline_math.py +36 -0
  34. mdxcanvas-0.0.0/mdxcanvas/text_processing/jinja_processing.py +104 -0
  35. mdxcanvas-0.0.0/mdxcanvas/text_processing/markdown_processing.py +158 -0
  36. mdxcanvas-0.0.0/mdxcanvas/util.py +28 -0
  37. mdxcanvas-0.0.0/mdxcanvas/xml_processing/__init__.py +0 -0
  38. mdxcanvas-0.0.0/mdxcanvas/xml_processing/announcement_tags.py +48 -0
  39. mdxcanvas-0.0.0/mdxcanvas/xml_processing/assignment_tags.py +75 -0
  40. mdxcanvas-0.0.0/mdxcanvas/xml_processing/attributes.py +155 -0
  41. mdxcanvas-0.0.0/mdxcanvas/xml_processing/group_tags.py +98 -0
  42. mdxcanvas-0.0.0/mdxcanvas/xml_processing/inline_styling.py +55 -0
  43. mdxcanvas-0.0.0/mdxcanvas/xml_processing/module_tags.py +171 -0
  44. mdxcanvas-0.0.0/mdxcanvas/xml_processing/override_parsing.py +58 -0
  45. mdxcanvas-0.0.0/mdxcanvas/xml_processing/page_tags.py +39 -0
  46. mdxcanvas-0.0.0/mdxcanvas/xml_processing/quiz_questions.py +483 -0
  47. mdxcanvas-0.0.0/mdxcanvas/xml_processing/quiz_tags.py +141 -0
  48. mdxcanvas-0.0.0/mdxcanvas/xml_processing/syllabus_tags.py +19 -0
  49. mdxcanvas-0.0.0/mdxcanvas/xml_processing/tag_preprocessors.py +331 -0
  50. mdxcanvas-0.0.0/mdxcanvas/xml_processing/xml_processing.py +86 -0
  51. mdxcanvas-0.0.0/pyproject.toml +39 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Bean Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.1
2
+ Name: mdxcanvas
3
+ Version: 0.0.0
4
+ Summary: A Canvas LMS API wrapper for maintaining content in markdown
5
+ License: MIT
6
+ Author: Gordon Bean
7
+ Author-email: gbean@cs.byu.edu
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: CanvasAPI (>=3.2.0,<4.0.0)
16
+ Requires-Dist: Jinja2 (>=3.1.2,<4.0.0)
17
+ Requires-Dist: Markdown (>=3.1.1,<4.0.0)
18
+ Requires-Dist: MarkupSafe (>=2.0.1,<3.0.0)
19
+ Requires-Dist: Pygments (>=2.17.2,<3.0.0)
20
+ Requires-Dist: beautifulsoup4 (>=4.13.4,<5.0.0)
21
+ Requires-Dist: cssutils (>=2.11.1,<3.0.0)
22
+ Requires-Dist: markdowndata (>=0.1.0,<0.2.0)
23
+ Requires-Dist: pymdown-extensions (>=10.16.1,<11.0.0)
24
+ Requires-Dist: pytest (>=8.4.0,<9.0.0)
25
+ Requires-Dist: pytz (>=2025.2,<2026.0)
26
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
27
+ Requires-Dist: strictyaml (>=1.7.3,<2.0.0)
@@ -0,0 +1 @@
1
+ 0.6.12
@@ -0,0 +1,3 @@
1
+ from pathlib import Path
2
+
3
+ __version__ = (Path(__file__).resolve().parent/"VERSION").read_text().strip()
File without changes
@@ -0,0 +1,143 @@
1
+ from collections import deque
2
+
3
+ from ..our_logging import get_logger
4
+
5
+ logger = get_logger()
6
+
7
+
8
+ def tarjan_scc(graph: dict[tuple[str, str], list[tuple[str, str]]]) -> list[list[tuple[str, str]]]:
9
+ """Find strongly connected components (cycles) using Tarjan's algorithm."""
10
+ index_counter = [0]
11
+ stack = []
12
+ lowlink = {}
13
+ index = {}
14
+ on_stack = set()
15
+ sccs = []
16
+
17
+ def strongconnect(node):
18
+ index[node] = index_counter[0]
19
+ lowlink[node] = index_counter[0]
20
+ index_counter[0] += 1
21
+ stack.append(node)
22
+ on_stack.add(node)
23
+
24
+ for successor in graph.get(node, []):
25
+ if successor not in index:
26
+ strongconnect(successor)
27
+ lowlink[node] = min(lowlink[node], lowlink[successor])
28
+ elif successor in on_stack:
29
+ lowlink[node] = min(lowlink[node], index[successor])
30
+
31
+ if lowlink[node] == index[node]:
32
+ scc = []
33
+ while True:
34
+ w = stack.pop()
35
+ on_stack.remove(w)
36
+ scc.append(w)
37
+ if w == node:
38
+ break
39
+ sccs.append(scc)
40
+
41
+ for node in graph.keys():
42
+ if node not in index:
43
+ strongconnect(node)
44
+
45
+ return sccs
46
+
47
+
48
+ def kahns_topological_sort(graph: dict[tuple[str, str], list[tuple[str, str]]]) -> list[tuple[str, str]]:
49
+ """Topological sort using Kahn's algorithm (dependencies first)."""
50
+ in_degree = {node: 0 for node in graph}
51
+ for deps in graph.values():
52
+ for dep in deps:
53
+ if dep in graph:
54
+ in_degree[dep] += 1
55
+
56
+ queue = deque([node for node, degree in in_degree.items() if degree == 0])
57
+ result = []
58
+
59
+ while queue:
60
+ node = queue.popleft()
61
+ result.append(node)
62
+
63
+ for dep in graph.get(node, []):
64
+ if dep in in_degree:
65
+ in_degree[dep] -= 1
66
+ if in_degree[dep] == 0:
67
+ queue.append(dep)
68
+
69
+ if len(result) != len(graph):
70
+ raise ValueError("Internal error: acyclic graph still has cycles")
71
+
72
+ return result[::-1]
73
+
74
+
75
+ def linearize_dependencies(
76
+ graph: dict[tuple[str, str], list[tuple[str, str]]],
77
+ shell_deployers: list[str]
78
+ ) -> list[tuple[tuple[str, str], bool]]:
79
+ """
80
+ Linearize dependencies with cycle breaking via shell deployments.
81
+ Example: A→B→C→A returns [((page, C),True), ((page, B), False), ((page, A), False), ((page, C), False)]
82
+
83
+ Note: Only certain resource types support shell deployments (assignment, page, quiz).
84
+ Other types (syllabus, file, etc.) have deterministic IDs and don't need shell deployments.
85
+ """
86
+
87
+ sccs = tarjan_scc(graph)
88
+
89
+ cycle_breakers = set()
90
+ scc_map = {}
91
+
92
+ for scc in sccs:
93
+ if len(scc) > 1:
94
+ # All nodes in an SCC that are depended upon by other nodes in the SCC
95
+ # need to be cycle breakers (deployed as shells first)
96
+ for node in scc:
97
+ scc_map[node] = scc
98
+ # Check if any other node in the SCC depends on this node
99
+ # and that this node supports shell deployment
100
+ if node[0] in shell_deployers:
101
+ for other_node in scc:
102
+ if other_node != node and node in graph.get(other_node, []):
103
+ cycle_breakers.add(node)
104
+ break
105
+
106
+ for node, deps in graph.items():
107
+ # Self-loops only need cycle breaking if the type supports shell deployment
108
+ if node in deps and node[0] in shell_deployers:
109
+ cycle_breakers.add(node)
110
+
111
+ acyclic_graph = {}
112
+ for node, deps in graph.items():
113
+ if node in scc_map:
114
+ # Remove all edges within the same SCC to break cycles
115
+ acyclic_graph[node] = [d for d in deps if d not in scc_map[node]]
116
+ elif node in cycle_breakers:
117
+ # Self-loop case
118
+ acyclic_graph[node] = [d for d in deps if d != node]
119
+ else:
120
+ acyclic_graph[node] = deps
121
+
122
+ topo_order = kahns_topological_sort(acyclic_graph)
123
+
124
+ # Shell deployments for cycle breakers must happen FIRST (before everything else)
125
+ # so that other resources can reference them. Then the full deployment happens
126
+ # in the natural topological order.
127
+ result = [(node, True) for node in topo_order if node in cycle_breakers]
128
+ result.extend((node, False) for node in topo_order)
129
+
130
+ return result
131
+
132
+
133
+ if __name__ == '__main__':
134
+ dependency_dict = {
135
+ 'A': ['B'],
136
+ 'B': ['C', 'D'],
137
+ 'C': [],
138
+ 'D': ['C']
139
+ }
140
+
141
+ # expect C, D, B, A
142
+ order = linearize_dependencies(dependency_dict)
143
+ print(order)
@@ -0,0 +1,25 @@
1
+ from canvasapi.course import Course
2
+
3
+ from ..resources import AnnouncementInfo
4
+
5
+
6
+ def deploy_announcement(course: Course, announcement_info: dict) -> tuple[AnnouncementInfo, None]:
7
+ announcement_id = announcement_info["canvas_id"]
8
+
9
+ if announcement_id:
10
+ canvas_announcement = course.get_discussion_topic(announcement_id)
11
+ canvas_announcement.update(**announcement_info)
12
+
13
+ else:
14
+ canvas_announcement = course.create_discussion_topic(**announcement_info)
15
+
16
+ announcement_object_info: AnnouncementInfo = {
17
+ 'id': canvas_announcement.id,
18
+ 'title': canvas_announcement.title,
19
+ 'uri': f'/courses/{course.id}/discussion_topics/{canvas_announcement.id}',
20
+
21
+ # Following fields have been observed to be missing in some cases
22
+ 'url': canvas_announcement.html_url if hasattr(canvas_announcement, 'html_url') else None
23
+ }
24
+
25
+ return announcement_object_info, None
@@ -0,0 +1,38 @@
1
+ from canvasapi.course import Course
2
+
3
+ from .util import update_group_name_to_id
4
+ from ..resources import AssignmentInfo
5
+
6
+
7
+ def deploy_assignment(course: Course, assignment_info: dict) -> tuple[AssignmentInfo, None]:
8
+ assignment_id = assignment_info["canvas_id"]
9
+
10
+ update_group_name_to_id(course, assignment_info)
11
+
12
+ # TODO - update group_category (name) to group_category_id
13
+ # Is this necessary to support?
14
+
15
+ if assignment_id:
16
+ canvas_assignment = course.get_assignment(assignment_id)
17
+ canvas_assignment.edit(assignment=assignment_info)
18
+ else:
19
+ canvas_assignment = course.create_assignment(assignment=assignment_info)
20
+
21
+ assignment_object_info: AssignmentInfo = {
22
+ 'id': canvas_assignment.id,
23
+ 'title': canvas_assignment.name,
24
+ 'uri': f'/courses/{course.id}/assignments/{canvas_assignment.id}',
25
+
26
+ # Following fields have been observed to be missing in some cases
27
+ 'url': canvas_assignment.html_url if hasattr(canvas_assignment, 'html_url') else None
28
+ }
29
+
30
+ return assignment_object_info, None
31
+
32
+
33
+ def deploy_shell_assignment(course: Course, assignment_info: dict) -> tuple[AssignmentInfo, None]:
34
+ shell_assignment_info = assignment_info.copy()
35
+ shell_assignment_info[
36
+ 'description'] = "<p>This is a shell assignment created to break a dependency cycle. The full content will be deployed later.</p>"
37
+
38
+ return deploy_assignment(course, shell_assignment_info)