Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Merged
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
17 changes: 12 additions & 5 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ jobs:
with:
github_token: ${{ github.token }}
paths_ignore: '["**.po", "**.json"]'

linting:
name: All file linting
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: pre-commit/action@v2.0.0
- uses: actions/checkout@v6.0.2
with:
fetch-depth: 0

- uses: astral-sh/setup-uv@v8.2.0
with:
python-version: 3.9
enable-cache: true

- name: Run prek
run: uvx prek run --all-files
44 changes: 18 additions & 26 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
Expand All @@ -14,23 +6,23 @@ on:

jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6.0.2
with:
ref: ${{ github.event.release.tag_name }}
fetch-depth: 0

runs-on: ubuntu-22.04
- name: Set up uv
uses: astral-sh/setup-uv@v8.2.0
with:
python-version: 3.9
enable-cache: true

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Build distributions
run: uv build

- name: Build and publish
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: uv publish
59 changes: 28 additions & 31 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,35 @@ jobs:
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
paths: '["**.py", "requirements*.txt", ".github/workflows/python.yml"]'
paths: '["**.py", "pyproject.toml", "uv.lock", ".github/workflows/python.yml"]'

unit_test:
name: Python unit tests
needs: pre_job
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -r requirements-test.txt
- name: cache Python env
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: py3.9-${{ hashFiles('requirements*.txt') }}
- name: Install and enable kolibri_sync_extras plugin
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
env:
KOLIBRI_HOME: .kolibri
run: |
pip install .
kolibri plugin enable kolibri_sync_extras_plugin
- name: Run tests
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -O -m pytest --reuse-db
- uses: actions/checkout@v6.0.2
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
with:
fetch-depth: 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

praise: fetch-depth: 0 is the critical detail here — setuptools-scm traverses the full git history to find the nearest version tag. Omitting it would cause every CI build to produce version 0.0.0 rather than the real tag-derived version.


- name: Set up uv
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: astral-sh/setup-uv@v8.2.0
with:
python-version: 3.9
enable-cache: true

- name: Sync dependencies
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: uv sync --locked --no-dev --group test

- name: Install and enable kolibri_sync_extras plugin
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
env:
KOLIBRI_HOME: .kolibri
run: uv run kolibri plugin enable kolibri_sync_extras_plugin

- name: Run tests
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: uv run python -O -m pytest --reuse-db
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Pipfile

# lock files
*.lock
!uv.lock

# node
node_modules
Expand Down
39 changes: 23 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.16
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: flake8
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
- id: end-of-file-fixer
exclude: '^.+?\.json$'
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.3.3
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.11.6
hooks:
- id: reorder-python-imports
language_version: python3.9
- id: uv-lock
- repo: https://github.com/google/yamlfmt
rev: v0.21.0
hooks:
- id: yamlfmt
- repo: https://github.com/rhysd/actionlint
rev: v1.7.11
hooks:
- id: actionlint
3 changes: 3 additions & 0 deletions .yamlfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
formatter:
retain_line_breaks: true
eof_newline: true
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ clean-build:
rm -fr *.egg-info
rm -fr .eggs
rm -fr .cache
rm -fr .ruff_cache

clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +

dist: clean
python setup.py sdist
python setup.py bdist_wheel --universal
uv build

release: dist
echo "Ensure that you have built the frontend files using Kolibri"
echo "Uploading dist/* to PyPi, using twine"
twine upload -s dist/*
echo "Uploading dist/* to PyPI using uv"
uv publish
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ BACKGROUND_FINALIZATION_STAGES = "deserializing,cleanup"
## Development
### Getting started
```bash
$ pip install -r requirements-dev.txt
$ pre-commit install
$ KOLIBRI_HOME="$(pwd)/.kolibri" kolibri plugin enable kolibri_sync_extras_plugin
$ uv sync
$ uvx prek install
$ KOLIBRI_HOME="$(pwd)/.kolibri" uv run kolibri plugin enable kolibri_sync_extras_plugin
```

## Testing
### Getting started
```bash
$ pip install -r requirements.txt -r requirements-test.txt
$ KOLIBRI_HOME="$(pwd)/.kolibri" kolibri plugin enable kolibri_sync_extras_plugin
$ uv sync --group test
$ KOLIBRI_HOME="$(pwd)/.kolibri" uv run kolibri plugin enable kolibri_sync_extras_plugin
```

### Running them
Expand Down
8 changes: 7 additions & 1 deletion kolibri_sync_extras_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
__version__ = "0.2.2"
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version

try:
__version__ = version("kolibri-sync-extras-plugin")
except PackageNotFoundError:
__version__ = "0.0.0"
8 changes: 2 additions & 6 deletions kolibri_sync_extras_plugin/kolibri_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def get_initialize_operations(self):
Import and cache the operation here to avoid import ordering issues with dependencies
:rtype: list[kolibri_sync_extras_plugin.sync.operations.BackgroundInitializeJobOperation]
"""
from kolibri_sync_extras_plugin.sync.operations import (
BackgroundInitializeJobOperation,
)
from kolibri_sync_extras_plugin.sync.operations import BackgroundInitializeJobOperation

if self._initialize_operations is None:
self._initialize_operations = [BackgroundInitializeJobOperation()]
Expand All @@ -30,9 +28,7 @@ def get_finalize_operations(self):
Import and cache the operation here to avoid import ordering issues with dependencies
:rtype: list[kolibri_sync_extras_plugin.sync.operations.BackgroundFinalizeJobOperation]
"""
from kolibri_sync_extras_plugin.sync.operations import (
BackgroundFinalizeJobOperation,
)
from kolibri_sync_extras_plugin.sync.operations import BackgroundFinalizeJobOperation

if self._finalize_operations is None:
self._finalize_operations = [BackgroundFinalizeJobOperation()]
Expand Down
23 changes: 7 additions & 16 deletions kolibri_sync_extras_plugin/management/commands/sync_proceed_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from kolibri_sync_extras_plugin.sync.context import BackgroundSessionContext


logger = logging.getLogger(__name__)


Expand All @@ -24,15 +23,13 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("--id", type=str, action="store")
parser.add_argument("--target-stage", type=str, action="store")
parser.add_argument(
"--capabilities", type=lambda caps: caps.split(","), action="store"
)
parser.add_argument("--capabilities", type=lambda caps: caps.split(","), action="store")

def handle(self, *args, **options):

transfer_session = TransferSession.objects.defer(
"client_fsic", "server_fsic"
).get(pk=options.pop("id"))
transfer_session = TransferSession.objects.defer("client_fsic", "server_fsic").get(
pk=options.pop("id")
)
target_stage = options.pop("target_stage")
capabilities = options.pop("capabilities")

Expand All @@ -47,19 +44,15 @@ def handle(self, *args, **options):
# retry in case of transaction rollback errors from transaction isolation
while status not in transfer_statuses.FINISHED_STATES and tries < MAX_RETRIES:
if tries > 0:
logger.info(
"Retrying {} to {}".format(transfer_session.pk, target_stage)
)
logger.info("Retrying {} to {}".format(transfer_session.pk, target_stage))
status = session_controller.proceed_to(
target_stage=target_stage,
context=context,
)
tries += 1

logger.info(
"Proceeded {} to {} with status '{}'".format(
transfer_session.pk, target_stage, status
)
"Proceeded {} to {} with status '{}'".format(transfer_session.pk, target_stage, status)
)

if status != transfer_statuses.COMPLETED:
Expand All @@ -76,6 +69,4 @@ def handle(self, *args, **options):
)
else:
# this should really never happen
raise RuntimeError(
"Unexpected failure finalizing {}".format(transfer_session.pk)
)
raise RuntimeError("Unexpected failure finalizing {}".format(transfer_session.pk))
9 changes: 2 additions & 7 deletions kolibri_sync_extras_plugin/sync/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from kolibri_sync_extras_plugin.tasks import get_job_id
from kolibri_sync_extras_plugin.tasks import set_job_id


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -114,12 +113,8 @@ def handle(self, context):
self._assert(ASYNC_OPERATIONS in context.capabilities)
current_stage = transfer_stages.stage(context.stage)
# the initialization stage itself cannot be processed in the background
self._assert(
current_stage > transfer_stages.stage(transfer_stages.INITIALIZING)
)
self._assert(
current_stage < transfer_stages.stage(transfer_stages.TRANSFERRING)
)
self._assert(current_stage > transfer_stages.stage(transfer_stages.INITIALIZING))
self._assert(current_stage < transfer_stages.stage(transfer_stages.TRANSFERRING))

job_state = self._get_or_queue_job(context, context.stage)

Expand Down
Loading
Loading