Skip to content

feat: modernize Python tooling to uv + pyproject.toml + semantic-release - #704

Merged
feanil merged 12 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/modernize-python-tooling
Oct 1, 2026
Merged

feanil merged 12 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/modernize-python-tooling

Conversation

@irfanuddinahmad

@irfanuddinahmad irfanuddinahmad commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Modernize openedx-core to uv + pyproject.toml (PEP 621/735) + python-semantic-release.

Part of openedx/public-engineering#506 (tracked in openedx/public-engineering#516).

  • Replace setup.py/setup.cfg with pyproject.toml (PEP 621 static metadata), version derived from git tags via setuptools-scm
  • Switch from pip-compile to uv with PEP 735 dependency groups; commit uv.lock
  • Update tox.ini to use tox-uv with uv-venv-lock-runner
  • Update CI to use astral-sh/setup-uv; SHA-pin all actions
  • Add python-semantic-release + release.yml, replacing the old token-based pypi-publish.yml with OIDC trusted publishing

Not included: src/ layout. This repo already uses src/openedx_{core,content,tagging,catalog} and src/openedx_django_lib, so Phase 0 of the org-wide migration (openedx/public-engineering#506's 2026-07-15 decision) required no changes here — MANIFEST.in, .coveragerc's (now [tool.coverage.run]) source, docs/conf.py's sys.path entries, and tox.ini already pointed at src/.

Removed

Deleted files: setup.py, setup.cfg, .coveragerc, .readthedocs.yml (legacy duplicate of .readthedocs.yaml), requirements/ (all .in/.txt files, constraints.txt, private.readme), .github/workflows/pypi-publish.yml (replaced by release.yml, OIDC instead of the PYPI_UPLOAD_TOKEN secret).

Removed Makefile targets:

Target Reason
compile-requirements pip-compile machinery, replaced by uv lock

upgrade and requirements targets were kept but rewritten to use uv (edx_lint write_uv_constraints + uv lock --upgrade, and uv sync --group dev, respectively) instead of pip-compile/pip-sync.

Versioning

Dynamic — setuptools-scm derives the build version from the latest git tag. Pre-flight check passed: latest git tag v1.1.0 matches the version currently live on PyPI (1.1.0), so the first automated release should compute the correct next version from conventional-commit history.

Testing Notes

Verified locally:

  • uv lock resolves cleanly (156 packages)
  • uv sync (base project, no groups) succeeds; editable install makes all five packages (openedx_core, openedx_content, openedx_tagging, openedx_django_lib, openedx_catalog) importable, with openedx_core.__version__ correctly resolving to 1.1.0 via importlib.metadata
  • python -m build + twine check dist/* both pass; inspected the built wheel and confirmed all five packages (with py.typed markers) are bundled correctly
  • mypy resolves the editable install correctly under this repo's existing src/ layout (ran ad hoc with a partial dependency set due to a local sandbox limitation below; it got past all import/plugin resolution and only flagged missing pytest/freezegun stubs from the deliberately-partial ad hoc install, not a resolution problem)
  • tox -l lists all envs correctly (py312-django52, quality, docs, pii_check, lint-imports) — tox.ini parses cleanly against the new [dependency-groups] names

Could not verify locally: uv sync --group dev (and test/quality/doc) fails to build in this sandbox because mysqlclient has no macOS wheel and needs local MySQL client headers unavailable here. This predates the migration (same coupling existed via the old requirements/test.in) and is expected to build fine on GitHub Actions' ubuntu-latest runners, which ship with MySQL client libraries preinstalled. Full test-suite / quality-check execution therefore relies on this PR's own CI run.

Code reviewer notes

  • PyPI OIDC trusted publisher needs configuring for openedx-core (tracked in the consolidated comment on Tbain/253 add tags count #506) before the first automated release can publish. OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN is already a standard org-level secret used by many other repos, so no action needed there.
  • Known, out-of-scope gap: .github/workflows/upgrade-python-requirements.yml calls openedx/.github's shared reusable workflow, which hardcodes add-paths: requirements. Now that requirements/ is deleted, that scheduled job will silently stop producing real dependency-upgrade PRs — same gap across every repo in this migration batch; needs a fix in openedx/.github itself, not here.
  • mysqlclient is bundled into the test-base dependency group (and therefore test/quality/doc/ci/dev transitively), matching the pre-migration coupling in requirements/test.in → quality.in/doc.in/dev.in. This is why the "Not included"/"Testing Notes" sections above call out the local verification gap.
  • [dependency-groups].ci is intentionally minimal (tox, tox-uv only, no include-group) — CI's own uv sync --group ci step only needs tox on PATH; tox installs each env's actual dependency group itself via uv-venv-lock-runner.

This PR was created with Claude Code.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jul 27, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @irfanuddinahmad!

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.

Comment thread .github/workflows/release.yml Resolved
Comment thread src/openedx_core/__init__.py Resolved
Comment thread .readthedocs.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
irfanuddinahmad added a commit to irfanuddinahmad/openedx-core that referenced this pull request Sep 2, 2026
Per explicit direction on PR openedx#704 review thread r3880106779: follow
sample-plugin's release.yml exactly, including this pin, superseding
the skill's prior guidance (reversed 2026-08-05) to leave this one
action on the floating @release/v1 tag. SHA verified against the
action repo's own tag history before use (dc37677b -> v1.14.2).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@irfanuddinahmad
irfanuddinahmad force-pushed the irfanuddinahmad/modernize-python-tooling branch 2 times, most recently from 9218fb4 to 0c6634e Compare September 3, 2026 11:42
Modernize openedx-core to uv + pyproject.toml (PEP 621/735) +
python-semantic-release.

Part of openedx/public-engineering#506 (tracked in
openedx/public-engineering#516).

- Replace setup.py/setup.cfg with pyproject.toml (PEP 621 static
  metadata), version derived from git tags via setuptools-scm.
- Switch from pip-compile to uv with PEP 735 dependency groups;
  commit uv.lock.
- Update tox.ini to use tox-uv with uv-venv-lock-runner.
- Update CI to use astral-sh/setup-uv; SHA-pin all actions.
- Add python-semantic-release + release.yml, replacing the old
  token-based pypi-publish.yml with OIDC trusted publishing.
- src/ layout not touched -- this repo already used it, so no change
  was needed here.
- Delete setup.py, setup.cfg, .coveragerc, requirements/ (all
  .in/.txt files, constraints.txt, private.readme),
  .github/workflows/pypi-publish.yml.

Addresses salman2013's PR review feedback:
- Keep the CI job name as tests, matching the pre-migration name
  (deferring the per-toxenv rename to avoid breaking
  required-status-check matching).
- __version__ falls back to "unknown" on PackageNotFoundError instead
  of leaving it unset, with the except branch marked
  pragma: no cover since the package is always installed in CI.
- Remove the legacy, unused .readthedocs.yml (superseded by
  .readthedocs.yaml).
- Drop an unintended fetch-depth: 0 on the checkout step -- a
  leftover side effect of removing the separate setup-python step,
  not a deliberate choice.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@irfanuddinahmad
irfanuddinahmad force-pushed the irfanuddinahmad/modernize-python-tooling branch from 0c6634e to ec638c2 Compare September 3, 2026 11:53
Comment thread src/openedx_core/__init__.py Resolved
Comment thread .annotation_safe_list.yml Resolved
Comment thread pyproject.toml Resolved
@salman2013

Copy link
Copy Markdown
Contributor

Conflicts need to be resolved.

irfanuddinahmad and others added 3 commits September 9, 2026 14:07
…ernize-python-tooling

# Conflicts:
#	requirements/base.txt
#	requirements/ci.txt
#	requirements/dev.txt
#	requirements/doc.txt
#	requirements/quality.txt
#	requirements/test.txt
irfanuddinahmad and others added 3 commits September 23, 2026 17:05
…mad/modernize-python-tooling

# Conflicts:
#	requirements/base.txt
#	requirements/ci.txt
#	requirements/dev.txt
#	requirements/doc.txt
#	requirements/pip-tools.txt
#	requirements/quality.txt
#	requirements/test.txt
#	src/openedx_core/__init__.py
…e job

Matches openedx/sample-plugin's current release.yml; the custom
OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN secret isn't needed.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread pyproject.toml Outdated
dependencies = [
"attrs",
"celery",
"Django>=5.2,<6.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1.4.0 published Django, edx-drf-extensions and edx-organizations with no bounds, because setup.py read requirements/base.in and dropped the -c constraints.txt line. This branch publishes Django<6.0,>=5.2, edx-drf-extensions>=10.7.0 and edx-organizations>=9.0.0, and those are the only three Requires-Dist changes in the wheel.

<6.0 is the one that matters. It was a constraint on this repo's own installs; in released metadata it blocks openedx-platform from resolving Django 6 until openedx-core cuts a release. I also can't find where 10.7.0 comes from, base.txt pinned edx-drf-extensions==10.9.0.

Restore the unbounded specifiers, or say what each bound is for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Restored unbounded Django/edx-drf-extensions/edx-organizations in published deps. The 10.7.0 floor didn't match any real release or historical pin — traced it to a stale snapshot from when the migration commit was authored. Django<6.0 stays in constraint-dependencies only.

Comment thread Makefile Outdated

coverage: clean ## generate and view HTML coverage report
pytest --cov-report html
uv run pytest --cov-report html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're dropping the uv run prefixes from Makefiles, so this goes back to pytest --cov-report html. The Makefile should assume the environment is already set up: activate the venv locally, put uv run in the workflow step in CI. openedx/public-engineering#506 (comment)

Same for the other uv run lines in this file, apart from the --with edx-lint one that upgrade needs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped uv run — bare pytest --cov-report html now.

Comment thread tox.ini
pycodestyle src tests test_utils manage.py test_settings.py mysql_test_settings.py
pydocstyle src # don't need to lint docs for tests & utils
isort --check-only --diff src tests test_utils setup.py manage.py test_settings.py mysql_test_settings.py
isort --check-only --diff src tests test_utils manage.py test_settings.py mysql_test_settings.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makefile:59 dropped lint-imports, so make quality doesn't run it locally any more. CI still covers it through the lint-imports.yml workflow, same as before.

Add it to [testenv:quality] rather than back to the Makefile. import-linter is already in the quality group through test-base, so it resolves there, and the CI matrix already runs tox -e quality. That makes lint-imports.yml redundant, so we can just drop that workflow in this PR.

Suggested change
isort --check-only --diff src tests test_utils manage.py test_settings.py mysql_test_settings.py
isort --check-only --diff src tests test_utils manage.py test_settings.py mysql_test_settings.py
lint-imports

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added lint-imports to [testenv:quality]'s commands, right after isort — import-linter was already resolving via test-base.

Comment thread tox.ini Outdated
@@ -1,5 +1,6 @@
[tox]
envlist = py312-django{52}, quality, docs, pii_check, lint-imports

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This lint-imports entry in the envlist can be deleted. There's no [testenv:lint-imports] section, so it falls back to [testenv] and runs pytest again rather than the linter. We're gonna ad the import-linter to the quality check so we're still getting that coverage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the bogus lint-imports envlist entry.

irfanuddinahmad and others added 2 commits September 28, 2026 15:43
Makefile now assumes an already-synced/activated local env; uv run
stays in CI workflow steps only. See openedx/ccx-keys#190 (review
comment r4097501942).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ernize-python-tooling

# Conflicts:
#	requirements/base.txt
#	requirements/ci.txt
#	requirements/dev.txt
#	requirements/doc.txt
#	requirements/quality.txt
#	requirements/test.txt

@feanil feanil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

62b51bc takes care of the uv run prefixes. The other three comments from last round are still open: the dependency bounds in pyproject.toml, moving lint-imports into [testenv:quality] and dropping lint-imports.yml, and the lint-imports entry in the tox envlist.

I rebuilt the wheel off 38916465 with SETUPTOOLS_SCM_PRETEND_VERSION=1.4.0 and re-diffed it against openedx_core-1.4.0 from PyPI. Still nothing dropped, still the same 11 README and ARCHITECTURE additions, and Requires-Dist still differs on exactly Django, edx-drf-extensions and edx-organizations. uv lock --check is clean and all 8 checks are green.

I tried the [testenv:quality] change locally to make sure it resolves: import-linter comes from the quality group through test-base, and tox -e quality finishes in 28s with Contracts: 2 kept, 0 broken. Worth doing now that main has added openedx_catalog as a fourth root package in .importlinter.

One new comment below, on branch protection.

@@ -12,18 +12,19 @@ jobs:
lint-imports:
name: Lint Python Imports

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lint Python Imports is a required status check on main, so deleting this workflow means the check never reports on the head and this PR blocks on itself.

Before this merges and once lint-imports is in [testenv:quality] I can remove the requirements on the Python Lint Imports job. tests (ubuntu-latest, 3.12, quality, 8) is already required and covers it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Left lint-imports.yml in place for now so the required check keeps reporting — lint-imports is wired into quality as of this commit, so this should be ready for you to lift the branch-protection requirement whenever you get a chance. Will remove the workflow file in a follow-up once that's done.

irfanuddinahmad and others added 2 commits September 30, 2026 15:03
… published deps

The last real release (1.4.0) published Django, edx-drf-extensions, and
edx-organizations with no version bounds at all, since pre-migration
setup.py read requirements/base.in (unpinned) rather than base.txt or
constraints.txt. The pyproject.toml dependencies list introduced by the
uv migration added bounds that never existed in published metadata --
most importantly Django<6.0, which would block openedx-platform (or any
other consumer) from resolving Django 6 until openedx-core cuts a new
release.

The edx-drf-extensions>=10.7.0 lower bound also didn't match history: it
came from a stale requirements/base.txt snapshot on this branch at the
time pyproject.toml was authored. The actual last-released pin (v1.4.0
tag) was 10.8.0, and the latest pre-migration pin on main (before
requirements/base.txt was deleted by the migration) was 10.9.0. Neither
matches 10.7.0, and none of these pins were ever part of published
Requires-Dist in the first place.

Restore all three to unbounded, matching PyPI's published metadata for
1.4.0. Django<6.0 is still enforced for this repo's own lockfile/test
resolution via [tool.uv].constraint-dependencies, which only affects
this repo and does not propagate to consumers.

uv.lock regenerated; resolved package set is unchanged (specifiers only).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tox.ini's envlist listed a lint-imports entry with no matching
[testenv:lint-imports] section, so it silently fell back to the generic
[testenv] and just re-ran pytest instead of linting imports. This also
meant Makefile's `make quality` (which delegates to `tox -e quality`)
never actually ran import-linter locally.

Delete the bogus envlist entry and instead run `lint-imports` as a step
in [testenv:quality], right after isort. import-linter is already pulled
in via the quality dependency-group (through test -> test-base), so no
new dependency is needed.

.github/workflows/lint-imports.yml is intentionally left in place: it is
currently a required branch-protection status check on main. Removing it
now would leave that required check permanently stuck at "Expected --
Waiting for status" on this PR's head commit, deadlocking the PR. Per
feanil, that workflow should only be removed once quality's lint-imports
step is confirmed working and he lifts the branch-protection requirement
on "Lint Python Imports" (since tox -e quality is already a required
check and will cover the same ground).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread .github/workflows/ci.yml Outdated
- name: Install Dependencies
run: pip install -r requirements/ci.txt
- name: Install CI dependencies
run: uv sync --group ci

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add --locked here and on the uv run tox step below, so CI fails when uv.lock doesn't
match pyproject.toml instead of relocking it in the runner. Both pass on this branch as-is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added --locked to both steps, verified uv sync --locked --group ci passes cleanly.

Comment thread pyproject.toml Outdated
# applying any version constraints. Bounding these here would restrict
# what versions consumers (e.g. openedx-platform) can resolve. Any bound
# this repo itself needs for local testing/resolution belongs in
# [tool.uv].constraint-dependencies instead (see Django<6.0 below).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: point this at [tool.edx_lint].uv_constraints. constraint-dependencies is written by
edx_lint write_uv_constraints on every make upgrade, so a bound hand-edited into it gets
overwritten.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed -- pointed the comment at [tool.edx_lint].uv_constraints instead (the actual safe-to-edit spot), and confirmed directly that Django<6.0 is already covered globally via edx-lint's common_constraints.txt, so it was never at risk of being lost.

- ci.yml: added --locked to uv sync/uv run tox steps. Verified
  uv sync --locked --group ci passes cleanly.
- pyproject.toml: the comment next to the unbounded Django/etc.
  dependencies pointed at [tool.uv].constraint-dependencies as the
  place to add a repo-specific bound -- that block is tool-generated
  output (edx_lint write_uv_constraints), not an editing target.
  Corrected to point at [tool.edx_lint].uv_constraints instead, and
  noted Django<6.0 is already covered globally via edx-lint's
  common_constraints.txt (confirmed directly), not something this
  repo added itself.

Per feanil's review on openedx#704: discussion_r4147327735, r4147327755.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@feanil
feanil merged commit 2816952 into openedx:main Oct 1, 2026
8 checks passed
@feanil

feanil commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@irfanuddinahmad now that this has landed, I've dropped the requirement on the LintImports check and it should be safe to remove in a follow up PR. Feel free to tag me on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants