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

ADR for Public Python API Conventions #186

Merged
merged 2 commits into from
May 6, 2024

Conversation

ormsbee
Copy link
Contributor

@ormsbee ormsbee commented Apr 29, 2024

This proposes refactoring our apps and introducing two major new conventions at the same time:

  1. Apps in openedx_learning.core would now be in openedx_learning.apps.authoring, setting a pattern for grouping apps together into larger package groups.
  2. A new openedx_learning.api.authoring module would be created to aggregate API modules from apps in openedx_learning.apps.authoring.

I originally wrote this up as a part of the major refactoring in #184, but separated out here so that we can discuss it in its own space.

@ormsbee
Copy link
Contributor Author

ormsbee commented Apr 29, 2024

@kdmccormick, @bradenmacdonald: Please review the ADR here.

@ormsbee
Copy link
Contributor Author

ormsbee commented Apr 29, 2024

I'm going to hold this ADR open for at least a week, (so until May 6th), to give anyone in the wider community a chance to comment on it.

Edit: Advertised here: https://discuss.openedx.org/t/adr-on-python-public-api-conventions-in-learning-core/12872

App ``api`` modules should not import directly from apps outside their package.
For example, ``openedx_learning.apps.personalization.api`` should import authoring API functions from ``openedx_learning.api.authoring``, **not** directly from something like ``openedx_learning.apps.authoring.components.api``. This will help to limit the impact of refactoring app package internal changes, as well as exposing shortcomings in the existing public APIs.

Public API modules may implement their own functions.
Copy link
Member

Choose a reason for hiding this comment

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

I like this. Not only for convenience but also as a way to address the natural evolution of the API. Do you think this might replace versioning by creating shims and deprecating functions with good documentation and timelines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it will replace versioning altogether, but I definitely plan to use compatibility shims more liberally here than we have in for Django apps historically, and to make deprecations happen at the level of individual functions with deprecation warnings.

Copy link
Member

@felipemontoya felipemontoya left a comment

Choose a reason for hiding this comment

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

I like this proposal. Left a question, but mostly curious about it. Nothing blocking

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Sounds good. It would be nice to update the import linter in edx-platform to make sure that people are following this.

@ormsbee
Copy link
Contributor Author

ormsbee commented Apr 29, 2024

I like this proposal. Left a question, but mostly curious about it. Nothing blocking

@felipemontoya: Thank you for looking at it so quickly!


This relies on the individual apps to properly set ``__all__`` to the list of functions that they are willing to publicly support.

App ``api`` modules within a package of apps still import from each other.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth having a convention of _api to indicate more local APIs that are meant to be used internal to the project but is not reliable outside of the openedx-learning project? It seems cumbersom but also could help reduce the surface area of API that we have to guarantee to parties that build on top of openedx-learning.

Copy link
Contributor Author

@ormsbee ormsbee May 1, 2024

Choose a reason for hiding this comment

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

That's an interesting idea. I guess it partly depends on where the maintenance boundaries end up being. This arrangement makes more sense to me if a single group of people is responsible for the broad package of authoring apps, as opposed to multiple teams working on separate groups of apps in authoring (which is... probable...?). I admit that part of my resistance to this idea might just be aesthetic–it feels weird to me that the components app would import from a private module of publishing (openedx_learning.apps.publishing._api).

I'm hoping that between documentation and importlinter rules in edx-platform, it'll be clear that consumers should only import from modules in the openedx_learning.api package. But I'm definitely open to revisiting this if it turns out to be a source of confusion.

@ormsbee
Copy link
Contributor Author

ormsbee commented May 1, 2024

Updated ADR to record feedback from @bradenmacdonald and @feanil.

Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

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

I'd love to see the import linting rules for this in edx-platform as close to merging this as possible.

@ormsbee
Copy link
Contributor Author

ormsbee commented May 1, 2024

I'd love to see the import linting rules for this in edx-platform as close to merging this as possible.

I'll include it as part of the refactoring PR necessary on the edx-platform side to switch over.

@ormsbee ormsbee merged commit b04edcb into openedx:main May 6, 2024
12 checks passed
@ormsbee ormsbee deleted the python-api-conventions-adr branch May 6, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants