Skip to content

Conversation

@dwong2708
Copy link
Contributor

@dwong2708 dwong2708 commented Jul 4, 2025

Description

Fixes: #331

These changes are the first step toward implementing a dump/load format for libraries. This initial approach introduces a minimal lp_dump management command for Learning Core.

The contents of package.toml are shown below

image

Acceptance Criteria

App requirements:

  • Create an lp_dump command in a new openedx_learning.apps.authoring.backup_restore app.
  • Most application logic should be in an api.py module in that new app, which the management command would call.
  • Like all openedx_learning apps, the AppConfig should set the label to have an "oel_" prefix, i.e. "oel_backup_restore".
  • The new app should be added to our .importlinter file, as the second-lowest dependency layer (just above publishing).

In terms of the output of the lp_dump command itself:

  • It will take two mandatory arguments: (1) the key of the LearningPackage to dump, (2) the name of the output zip file.
  • The output zip file will have a single package.toml file in it.
  • We will need to add a lib to our requirements to write TOML, probably TOML Kit, since it can write comments and do ordering.
  • The contents of the package.toml will be most of the fields in LearningPackage: title, key, description, created, and updated. Don't add uuid yet, as we have to think through some of the implications more.
  • (Optional) If it's easy, adding a comment at the top of the package.toml file indicating the datetime of export would be helpful.

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

openedx-webhooks commented Jul 4, 2025

Thanks for the pull request, @dwong2708!

This repository is currently maintained by @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.

Details
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.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Jul 4, 2025
@dwong2708 dwong2708 force-pushed the dwong2708/lp_dump branch 3 times, most recently from df51e04 to df952d7 Compare July 4, 2025 21:33
@dwong2708 dwong2708 marked this pull request as ready for review July 4, 2025 21:41
@dwong2708 dwong2708 requested a review from ormsbee July 4, 2025 21:42
Copy link
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Thank you for taking a crack at this. I have some high level requests and minor wording suggestions.

from datetime import datetime
from typing import Any, Dict

from tomlkit import comment, document, dumps, nl, table
Copy link
Contributor

Choose a reason for hiding this comment

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

Since tomlkit is new, you'll need to add it to requirements/base.in and then compile the requirements using make compile-requirements in the top level directory. Please be sure to add comments in base.in explaining generally what this is used for.

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 thought it was already added, but it wasn’t. Just added it now — thanks!

from tomlkit.items import Table


class LpTomlFile():
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I asked for lp_dump because I thought "lp" would be easier to type from the command line, but when we're talking about class names, please expand it to "LearningPackage".
  2. In Java, the convention is to lowercase abbreviations after the initial captial, e.g. "Toml". In Python, the convention is to keep it all caps, e.g. TOMLDecodeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.stdout.write(self.style.SUCCESS(message))
except Exception as e: # pylint: disable=broad-exception-caught
message = f"Error on create the zip file {e}"
self.stdout.write(self.style.ERROR(message))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go to self.stderr, not self.stdout. But you can also just use logging and log.exception to put the stacktrace in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,46 @@
"""
Utilities for backup and restore app
Copy link
Contributor

Choose a reason for hiding this comment

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

Please try to avoid "utils" as a module name, as it's usually too generic to be a useful description. For instance, if this module is going to have a bunch of code related to TOML serialization, calling it toml.py would give a better indication of its purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Contstant for backup restore app
"""

TOML_PACKAGE_NAME = "package.toml"
Copy link
Contributor

Choose a reason for hiding this comment

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

For now, please just define this in the module that uses it, instead of making a new module for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dwong2708 dwong2708 force-pushed the dwong2708/lp_dump branch 2 times, most recently from f4e70f8 to 9191ec9 Compare July 7, 2025 19:28
@dwong2708 dwong2708 requested a review from ormsbee July 7, 2025 19:39
@dwong2708
Copy link
Contributor Author

Thank you for taking a crack at this. I have some high level requests and minor wording suggestions.

Thanks for taking the time to review! I've handled all the comments

@ormsbee
Copy link
Contributor

ormsbee commented Jul 8, 2025

(On my phone while traveling right now, so this is going to be terse, sorry.)

  • Please make the section in the output file read "learning_package" instead of "Learning package".
  • Title should only exist in that table, not also separately at the top level.

@dwong2708
Copy link
Contributor Author

dwong2708 commented Jul 8, 2025

(On my phone while traveling right now, so this is going to be terse, sorry.)

  • Please make the section in the output file read "learning_package" instead of "Learning package".
  • Title should only exist in that table, not also separately at the top level.

image

Done ✅

@dwong2708 dwong2708 force-pushed the dwong2708/lp_dump branch from 9191ec9 to 0cc1b64 Compare July 8, 2025 19:31
Copy link
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Two small notes for the future:

  1. Please don't squash your commits until the end of the review cycle. It makes it harder to see what things have changed.
  2. Your commit message should have a more details about why these changes were done.

I'll add the extra info in the commit message this time.

@ormsbee ormsbee merged commit a1dd9e5 into openedx:main Jul 8, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Contributions Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Create minimal lp_dump management command for Learning Core

3 participants