Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: Python CI
name: CI

on:
push:
branches: [main]
branches: [main, master]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why both branches?

pull_request:
branches:
- "**"

jobs:
run_tests:
name: tests
python:
name: python tests
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: python
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -39,5 +42,46 @@ jobs:
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
flags: python
fail_ci_if_error: false

javascript:
name: javascript tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: javascript
strategy:
matrix:
node-version: ["18", "20"]
steps:
- uses: actions/checkout@v6
- name: setup node
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: javascript/package-lock.json

- name: Install Dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Typecheck
run: npm run typecheck

- name: Run Tests
run: npm run test:coverage

- name: Build
run: npm run build

- name: Run coverage
if: matrix.node-version == '20'
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: javascript
fail_ci_if_error: false
37 changes: 37 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish package to npm

on:
release:
types: [published]

jobs:
push:
runs-on: ubuntu-latest
defaults:
run:
working-directory: javascript

steps:
- name: Checkout
uses: actions/checkout@v6
- name: setup node
uses: actions/setup-node@v5
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
cache: npm
cache-dependency-path: javascript/package-lock.json

- name: Install Dependencies
run: npm ci

- name: Validate
run: npm run validate

- name: Build package
run: npm run build

- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ jobs:
python-version: 3.12

- name: Install pip
working-directory: python
run: pip install -r requirements/pip.txt

- name: Build package
working-directory: python
run: python setup.py sdist bdist_wheel

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
packages-dir: python/dist
19 changes: 13 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ output/*.html
output/*/index.html

# Sphinx
docs/_build
docs/modules.rst
docs/openedx_sdk.rst
docs/openedx_sdk.*.rst
python/docs/_build
python/docs/modules.rst
python/docs/openedx_sdk.rst
python/docs/openedx_sdk.*.rst

# Private requirements
requirements/private.in
requirements/private.txt
python/requirements/private.in
python/requirements/private.txt

# PII check report output
pii_report/

# JavaScript
node_modules/
javascript/dist/
javascript/coverage/
*.tsbuildinfo
.npm
6 changes: 3 additions & 3 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
configuration: python/docs/conf.py
fail_on_warning: true

# Set the version of python needed to build these docs.
Expand All @@ -18,10 +18,10 @@ build:

python:
install:
- requirements: requirements/doc.txt
- requirements: python/requirements/doc.txt

# This will pip install this repo into the python environment
# if you are using this in a repo that is not pip installable
# then you should remove the following two lines.
- method: pip
path: .
path: python
91 changes: 22 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,83 +1,36 @@
.PHONY: clean clean_tox compile_translations coverage diff_cover docs \
dummy_translations extract_translations fake_translations help \
quality requirements selfcheck test test-all upgrade validate
.PHONY: help upgrade requirements quality test test-python test-js lint build clean

.DEFAULT_GOAL := help

# For opening files in a browser. Use like: $(BROWSER)relative/path/to/file.html
BROWSER := python -m webbrowser file://$(CURDIR)/

help: ## display this help message
@echo "Please use \`make <target>' where <target> is one of"
@awk -F ':.*?## ' '/^[a-zA-Z]/ && NF==2 {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

clean: ## remove generated byte code, coverage reports, and build artifacts
find . -name '__pycache__' -exec rm -rf {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
coverage erase
rm -fr build/
rm -fr dist/
rm -fr *.egg-info

clean_tox: ## clear tox requirements cache
rm -fr .tox

coverage: clean ## generate and view HTML coverage report
pytest --cov-report html
$(BROWSER)htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
tox -e docs
$(BROWSER)docs/_build/html/index.html

# Define PIP_COMPILE_OPTS=-v to get more information during make upgrade.
PIP_COMPILE = pip-compile --upgrade $(PIP_COMPILE_OPTS)
@awk -F ':.*?## ' '/^[a-zA-Z]/ && NF==2 {printf "\033[36m %-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -r requirements/pip-tools.txt
# Make sure to compile files after any other files they include!
$(PIP_COMPILE) --allow-unsafe --rebuild -o requirements/pip.txt requirements/pip.in
$(PIP_COMPILE) --allow-unsafe -o requirements/pip-tools.txt requirements/pip-tools.in
pip install -r requirements/pip-tools.txt
$(PIP_COMPILE) --allow-unsafe -o requirements/base.txt requirements/base.in
$(PIP_COMPILE) --allow-unsafe -o requirements/test.txt requirements/test.in
$(PIP_COMPILE) --allow-unsafe -o requirements/doc.txt requirements/doc.in
$(PIP_COMPILE) --allow-unsafe -o requirements/quality.txt requirements/quality.in
$(PIP_COMPILE) --allow-unsafe -o requirements/ci.txt requirements/ci.in
$(PIP_COMPILE) --allow-unsafe -o requirements/dev.txt requirements/dev.in
upgrade: ## update python requirements pins
$(MAKE) -C python upgrade

quality: ## check coding style with pycodestyle and pylint
touch tests/__init__.py
pylint openedx_sdk tests test_utils *.py
rm tests/__init__.py
pycodestyle openedx_sdk tests *.py
pydocstyle openedx_sdk tests *.py
isort --check-only --diff tests test_utils openedx_sdk *.py test_settings.py
python setup.py bdist_wheel
twine check dist/*
make selfcheck
requirements: ## install dev requirements for both packages
$(MAKE) -C python requirements
cd javascript && npm install

piptools: ## install pinned version of pip-compile and pip-sync
pip install -r requirements/pip.txt
pip install -r requirements/pip-tools.txt
quality: ## run linters for both packages
$(MAKE) -C python quality
cd javascript && npm run lint

requirements: clean_tox piptools ## install development environment requirements
pip-sync requirements/dev.txt requirements/private.*
test-python: ## run python tests
$(MAKE) -C python test

test: clean ## run tests in the current virtualenv
pytest
test-js: ## run javascript tests
cd javascript && npm run test

diff_cover: test ## find diff lines that need test coverage
diff-cover coverage.xml
test: test-python test-js ## run all tests

test-all: quality ## run tests on every supported Python/Django combination
tox
tox -e docs
lint: quality ## alias for quality

validate: quality test ## run tests and quality checks
build: ## build both distributables
cd python && python setup.py sdist bdist_wheel
cd javascript && npm run build

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
clean: ## remove build artifacts from both packages
$(MAKE) -C python clean
cd javascript && npm run clean
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# openedx-sdk

Client SDKs for the standardized Open edX REST APIs.

This repository holds one SDK per language. Each package is self contained and
versioned independently.

| Directory | Package | Description |
| --- | --- | --- |
| [`python/`](./python) | `openedx-sdk` (PyPI) | Python SDK, for server to server use. Authenticates with an OAuth2 client credentials grant and manages JWTs itself. |
| [`javascript/`](./javascript) | `@openedx/openedx-sdk` (npm) | JavaScript/TypeScript SDK, aimed at MFEs. Reuses the caller's authenticated HTTP client instead of handling credentials. |

Both SDKs expose the same resource shape, grouped by area and then version:

```
client.home.v3.courses()
client.home.v4.courses(...)
```

## Covered APIs

| Area | Version | Endpoint |
| --- | --- | --- |
| Studio home | v3 | `GET /api/contentstore/v3/home/` |
| Studio home | v3 | `GET /api/contentstore/v3/home/courses/` |
| Studio home | v3 | `GET /api/contentstore/v3/home/libraries/` |
| Studio home | v4 | `GET /api/contentstore/v4/home/courses/` |

## Getting started

- Python: see [`python/README.rst`](./python/README.rst)
- JavaScript: see [`javascript/README.md`](./javascript/README.md)

## License

AGPL 3.0. See [LICENSE.txt](./LICENSE.txt).
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ coverage:
enabled: yes
target: 100%

flags:
python:
paths:
- python/
carryforward: true
javascript:
paths:
- javascript/
carryforward: true

comment: false
3 changes: 3 additions & 0 deletions javascript/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
coverage
node_modules
21 changes: 21 additions & 0 deletions javascript/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"env": {
"node": true,
"es2022": true
},
"ignorePatterns": ["dist", "coverage", "node_modules"],
"overrides": [
{
"files": ["src/__tests__/**/*.ts"],
"env": { "jest": true }
}
]
}
Loading