Skip to content
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

feat: [FC-0074] add inline code annotation linter for Open edX Events #478

Merged
merged 10 commits into from
Jan 22, 2025

Conversation

mariajgrimaldi
Copy link
Member

@mariajgrimaldi mariajgrimaldi commented Jan 10, 2025

Description:

This PR adds a linter for events code-annotations to find missing required fields like: name, type, data and description for Open edX Events. If any of these fields are missing, then a quality error is raised.

You can see it working in this PR: openedx/openedx-events#448 by running pylint openedx_events/learning/signals.py:

image

This linter aims to enforce the standard of in-line code annotations for developers to follow when documenting events definitions in the openedx-events (and others) repositories.

I'm open to moving this directly into the openedx-events repo if needed, considering that the linter is kind of specific to that repository.

Merge checklist:

  • All reviewers approved
  • CI build is green
  • If adding new checks, followed how_tos/0001-adding-new-checks.rst
  • Changelog record added (if needed)
  • Documentation updated (not only docstrings) (if needed)
  • Commits are squashed

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 10, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Jan 10, 2025

Thanks for the pull request, @mariajgrimaldi!

This repository is currently maintained by @openedx/axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mariajgrimaldi mariajgrimaldi changed the title Mjg/events code annotations feat: add inline code annotation linter for Open edX Events Jan 10, 2025
@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review January 10, 2025 15:31
@mariajgrimaldi mariajgrimaldi changed the title feat: add inline code annotation linter for Open edX Events feat: [FC-0074] add inline code annotation linter for Open edX Events Jan 10, 2025
@mariajgrimaldi mariajgrimaldi added the FC Relates to an Axim Funded Contribution project label Jan 10, 2025
@sarina
Copy link
Contributor

sarina commented Jan 13, 2025

This looks good to me, but I don't know this repo well (and am not a CC on it) so I can't provide an approving review.

@mariajgrimaldi
Copy link
Member Author

mariajgrimaldi commented Jan 14, 2025

Thank you, @sarina. I'll tag @openedx/axim-engineering as the owners according to the catalog-info.yaml and the bot comment above.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_module_annotated_event_names = set()
self.current_module_annotation_group_line_numbers = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current use of self.current_module_annotation_group_line_numbers for tracking annotation lines looks functional but may be brittle if annotations are not perfectly aligned with the corresponding events so this reliance on order may lead to false positives or negatives in certain scenarios.

I think we could consider using a mapping from line numbers to event names (something like self.current_module_annotations = {line_number: event_name}) to directly associate each annotation with its corresponding event, this could make the logic more robust and reduce potential issues caused by misalignment or unexpected ordering

Copy link
Member Author

@mariajgrimaldi mariajgrimaldi Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! This implementation was inspired by the toggle annotations checker, here: https://github.com/openedx/edx-lint/blob/master/edx_lint/pylint/annotations_check.py#L329-L519 and then modified to fit the events inline code-annotations.

As far as I understand, annotations are visited in check_annotation_group using the ASTWalker, which visits annotation groups (starting with # ..) for each module. It finds the line where the annotation group starts, saves it in a queue-like list and saves an identifier, in this case, the event name for the annotation. Then is_annotation_missing is called for each OpenEdxPublicSignal instantiation (called call node). Since they are also visited using the same ASTWalker, the nodes are traversed in the same order, so the annotation groups should match the call node:

# .. event_type: org.openedx.learning.auth.session.login.completed.v1 # <- ANNOTATION GROUP
# .. event_name: SESSION_LOGIN_COMPLETED
# .. event_key_field: user.pii.username
# .. event_description: emitted when the user's login process in the LMS is completed.
# .. event_data: UserData
SESSION_LOGIN_COMPLETED = OpenEdxPublicSignal( # <- CALL NODE
    event_type="org.openedx.learning.auth.session.login.completed.v1",
    data={
        "user": UserData,
    }
)

That's why I don't think we would have an issue with unexpected ordering since we're traversing the modules using the same strategy. Also, since we are using the line number queue of each annotation group as our stopping condition, then we'd need the dict to behave like a queue so is_annotation_missing stops when needed.

Those are the main reasons why I think changing the set and queue for a dict would add more overhead than leaving it as it is. Let me know if you disagree or have any other suggestions considering what I mentioned.

EDIT: maybe something like this could happen, where the event names are switched and the linter won't raise any issues. I'll try to invest some time into figuring out how to cover these cases, I'll let you know what I find!

Copy link
Member Author

@mariajgrimaldi mariajgrimaldi Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alec4r: I think I've addressed your concerns with these commits:

  • Use a dict to store types and other annotations to check against nodes later in _is_annotation_missing_or_incorrect, the current annotation group should match the event init arguments (since they're traversed in order) so the check is successful: d1adeda
  • Check that the event name matches the annotation group besides event type and data: dadaa92

Let me know what you think!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariajgrimaldi looks good for me.

@mariajgrimaldi
Copy link
Member Author

@sarina: who else do you think we should tag for a review?

@mariajgrimaldi mariajgrimaldi marked this pull request as draft January 15, 2025 19:16
@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review January 16, 2025 11:52
@mariajgrimaldi mariajgrimaldi requested a review from Alec4r January 16, 2025 11:52
Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sarina
Copy link
Contributor

sarina commented Jan 21, 2025

@bmtcril - if this is good to you, could you go ahead and merge? @mariajgrimaldi isn't a CC on this repo.

@mariajgrimaldi
Copy link
Member Author

Thank you all, @sarina @Alec4r @bmtcril!

@bmtcril bmtcril merged commit 44536e1 into openedx:master Jan 22, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants