-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Add a config for openedx-events annotations #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d99bb11
feat: Add a config for openedx-events annotations
bmtcril 541f1f7
feat: Add a config for openedx-events annotations
bmtcril f4fbc71
fix: Formatting of event annotation output
bmtcril 06124ea
chore: Bump version to 1.7.0
bmtcril da3fe3b
docs: Fix copied comment to match reality
bmtcril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
code_annotations/contrib/config/openedx_events_annotations.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # This code-annotations configuration file supports openedx-events | ||
|
|
||
| source_path: ./ | ||
| report_path: reports | ||
| safelist_path: .annotation_safe_list.yml | ||
| coverage_target: 100.0 | ||
| annotations: | ||
| feature_toggle: | ||
| # See annotation format documentation: https://edx-toggles.readthedocs.io/en/latest/how_to/documenting_new_feature_toggles.html | ||
| - ".. event_type:": | ||
| - ".. event_name:": | ||
| - ".. event_description:": | ||
| - ".. event_data:": | ||
| - ".. event_key_field:": | ||
| extensions: | ||
| python: | ||
| - py | ||
| rst_template: doc.rst.j2 |
144 changes: 144 additions & 0 deletions
144
code_annotations/contrib/sphinx/extensions/openedx_events.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| """ | ||
| Sphinx extension for viewing openedx events annotations. | ||
| """ | ||
| import os | ||
|
|
||
| from docutils import nodes | ||
| from sphinx.util.docutils import SphinxDirective | ||
|
|
||
| from code_annotations.contrib.config import OPENEDX_EVENTS_ANNOTATIONS_CONFIG_PATH | ||
|
|
||
| from .base import find_annotations | ||
|
|
||
|
|
||
| def find_events(source_path): | ||
| """ | ||
| Find the feature toggles as defined in the configuration file. | ||
|
|
||
| Return: | ||
| toggles (dict): feature toggles indexed by name. | ||
| """ | ||
| return find_annotations( | ||
| source_path, OPENEDX_EVENTS_ANNOTATIONS_CONFIG_PATH, ".. event_type:" | ||
| ) | ||
|
|
||
|
|
||
| class OpenedxEvents(SphinxDirective): | ||
| """ | ||
| Sphinx directive to list the events in a single documentation page. | ||
|
|
||
| Use this directive as follows:: | ||
|
|
||
| .. openedxevents:: | ||
|
|
||
| This directive supports the following configuration parameters: | ||
|
|
||
| - ``openedxevents_source_path``: absolute path to the repository file tree. E.g: | ||
|
|
||
| openedxevents_source_path = os.path.join(os.path.dirname(__file__), "..", "..") | ||
|
|
||
| - ``openedxevents_repo_url``: Github repository where the code is hosted. E.g: | ||
|
|
||
| openedxevents_repo_url = "https://github.com/openedx/myrepo" | ||
|
|
||
| - ``openedxevents_repo_version``: current version of the git repository. E.g: | ||
|
|
||
| import git | ||
| try: | ||
| repo = git.Repo(search_parent_directories=True) | ||
| openedxevents_repo_version = repo.head.object.hexsha | ||
| except git.InvalidGitRepositoryError: | ||
| openedxevents_repo_version = "main" | ||
| """ | ||
|
|
||
| required_arguments = 0 | ||
| optional_arguments = 0 | ||
| option_spec = {} | ||
|
|
||
| def run(self): | ||
| """ | ||
| Public interface of the Directive class. | ||
|
|
||
| Return: | ||
| nodes (list): nodes to be appended to the resulting document. | ||
| """ | ||
| return list(self.iter_nodes()) | ||
|
|
||
| def iter_nodes(self): | ||
| """ | ||
| Iterate on the docutils nodes generated by this directive. | ||
| """ | ||
| events = find_events(self.env.config.openedxevents_source_path) | ||
|
|
||
| current_domain = "" | ||
| domain_header = None | ||
| current_subject = "" | ||
| subject_header = None | ||
|
|
||
| for event_type in sorted(events): | ||
| domain = event_type.split(".")[2] | ||
| subject = event_type.split(".")[3] | ||
| if domain != current_domain: | ||
| if domain_header: | ||
| yield domain_header | ||
|
|
||
| current_domain = domain | ||
| domain_header = nodes.section("", ids=[f"openedxevent-domain-{domain}"]) | ||
| domain_header += nodes.title(text=f"Architectural subdomain: {domain}") | ||
| if subject != current_subject: | ||
| current_subject = subject | ||
| subject_header = nodes.section("", ids=[f"openedxevent-subject" | ||
| f"-{subject}"]) | ||
| subject_header += nodes.title(text=f"Subject: {subject}") | ||
| domain_header += subject_header | ||
|
|
||
| event = events[event_type] | ||
| event_name = event[".. event_name:"] | ||
| event_name_literal = nodes.literal(text=event_name) | ||
| event_data = event[".. event_data:"] | ||
| event_data_literal = nodes.literal(text=event_data) | ||
| event_key_field = event.get(".. event_key_field:", "") | ||
| event_key_literal = nodes.literal(text=event_key_field) | ||
| event_description = event[".. event_description:"] | ||
|
|
||
| event_section = nodes.section("", ids=[f"openedxevent-{event_type}"]) | ||
| event_section += nodes.title(text=event_type, ids=[f"title-{event_type}"]) | ||
| event_section += nodes.paragraph(text=f"Description:" | ||
bmtcril marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| f"{event_description}") | ||
| event_section += nodes.paragraph(" ", "Signal name:", event_name_literal) | ||
bmtcril marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if event_key_field: | ||
| event_section += nodes.paragraph( | ||
| " ", | ||
| "Event key field: ", | ||
| event_key_literal | ||
| ) | ||
| event_section += nodes.paragraph(" ", "Event data:", event_data_literal) | ||
bmtcril marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| event_section += nodes.paragraph( | ||
| text=f"Defined at: {event['filename']} (line" | ||
| f" {event['line_number']})" | ||
| ) | ||
|
|
||
| subject_header += event_section | ||
|
|
||
| if domain_header: | ||
| yield domain_header | ||
|
|
||
|
|
||
| def setup(app): | ||
| """ | ||
| Declare the Sphinx extension. | ||
| """ | ||
| app.add_config_value( | ||
| "openedxevents_source_path", | ||
| os.path.abspath(".."), | ||
| "env", | ||
| ) | ||
| app.add_config_value("openedxevents_repo_url", "", "env") | ||
| app.add_config_value("openedxevents_repo_version", "main", "env") | ||
| app.add_directive("openedxevents", OpenedxEvents) | ||
|
|
||
| return { | ||
| "version": "0.1", | ||
| "parallel_read_safe": True, | ||
| "parallel_write_safe": True, | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.