feat: modernize Python tooling to uv + pyproject.toml + semantic-release - #704
feat: modernize Python tooling to uv + pyproject.toml + semantic-release#704irfanuddinahmad wants to merge 5 commits into
Conversation
Replace setup.py/setup.cfg with PEP 621 static metadata in pyproject.toml, using setuptools-scm for version derivation from git tags. Consolidate .coveragerc into [tool.coverage.*] tables. Remove the hardcoded __version__ in src/openedx_core/__init__.py and docs/conf.py in favor of importlib.metadata, since setuptools-scm makes any hardcoded value stale after the next tag. Part of openedx/public-engineering#506 (tracked in openedx/public-engineering#516).
Replace requirements/*.in/*.txt (pip-compile) with PEP 735 dependency groups in pyproject.toml, resolved into a committed uv.lock. Update tox.ini to use tox-uv's uv-venv-lock-runner and dependency_groups instead of pip-installed deps. Update the CI workflow, docs (Read the Docs) build, and lint-imports workflow to install via uv/uv sync instead of pip. Delete the requirements/ directory (base/test/quality/doc/dev/ci/pip/ pip-tools .in and .txt files, constraints.txt, private.readme) and the stale MANIFEST.in / .gitignore references to it. Part of openedx/public-engineering#506 (tracked in openedx/public-engineering#516).
Add [tool.semantic_release] to pyproject.toml (OIDC-based PyPI publish, python -m build as the build command since python-semantic-release's action environment doesn't have uv available). Replace the old token-based .github/workflows/pypi-publish.yml (push: tags trigger, PYPI_UPLOAD_TOKEN secret) with release.yml: runs the CI workflow, then python-semantic-release on push to main, then publishes to PyPI via OIDC trusted publishing (no stored credentials). commitlint.yml (conventional-commit enforcement) already existed in this repo and needed no changes. Part of openedx/public-engineering#506 (tracked in openedx/public-engineering#516).
|
Thanks for the pull request, @irfanuddinahmad! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
Re-triggering CI: the |
setup.cfg's [isort] section (include_trailing_comma, indent, line_length, multi_line_output) was dropped during Phase 1 metadata consolidation without being ported to [tool.isort] in pyproject.toml. Without it, isort fell back to its defaults and wanted to collapse existing multi-line parenthesized imports (e.g. in tests/openedx_content/applets/components/test_models.py) into fewer, wider lines, failing `tox -e quality`'s isort --check-only --diff src tests test_utils manage.py test_settings.py mysql_test_settings.py step in CI. Verified locally: isort --check-only --diff now reports no changes needed.
Verified every uses:@sha in release.yml against the GitHub API (repos/<owner>/<repo>/commits/<sha>) rather than trusting the pins as written. Two real problems, both invisible to PR CI since release.yml only runs on push to main: - python-semantic-release/python-semantic-release and actions/upload-artifact/download-artifact were pinned to SHAs that don't exist in those repos at all -- the upload-artifact and download-artifact SHAs were specifically swapped with each other. Reverted to plain version tags (@v10.6.1, @v7, @v8), matching openedx/XBlock's actual release.yml, which has already cut real production releases successfully with this exact pattern. - pypa/gh-action-pypi-publish was pinned to v1.14.1's annotated *tag object* SHA (2834a31...) rather than the underlying commit SHA (ba38be9e...) -- a tag-object SHA is a real git object but is not what a `uses:` checkout should reference. Corrected to the commit SHA, which is the one form this specific pin genuinely needs.
Summary
Modernize
openedx-coreto uv + pyproject.toml (PEP 621/735) + python-semantic-release.Part of openedx/public-engineering#506 (tracked in openedx/public-engineering#516).
setup.py/setup.cfgwithpyproject.toml(PEP 621 static metadata), version derived from git tags viasetuptools-scmuvwith PEP 735 dependency groups; commituv.locktox.inito usetox-uvwithuv-venv-lock-runnerastral-sh/setup-uv; SHA-pin all actionspython-semantic-release+release.yml, replacing the old token-basedpypi-publish.ymlwith OIDC trusted publishingNot included:
src/layout. This repo already usessrc/openedx_{core,content,tagging,catalog}andsrc/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'ssys.pathentries, andtox.inialready pointed atsrc/.Removed
Deleted files:
setup.py,setup.cfg,.coveragerc,requirements/(all.in/.txtfiles,constraints.txt,private.readme),.github/workflows/pypi-publish.yml(replaced byrelease.yml, OIDC instead of thePYPI_UPLOAD_TOKENsecret).Removed Makefile targets:
compile-requirementsuv lockupgradeandrequirementstargets were kept but rewritten to useuv(edx_lint write_uv_constraints+uv lock --upgrade, anduv sync --group dev, respectively) instead ofpip-compile/pip-sync.Versioning
Dynamic —
setuptools-scmderives the build version from the latest git tag. Pre-flight check passed: latest git tagv1.1.0matches 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 lockresolves 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, withopenedx_core.__version__correctly resolving to1.1.0viaimportlib.metadatapython -m build+twine check dist/*both pass; inspected the built wheel and confirmed all five packages (withpy.typedmarkers) are bundled correctlymypyresolves the editable install correctly under this repo's existingsrc/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 missingpytest/freezegunstubs from the deliberately-partial ad hoc install, not a resolution problem)tox -llists all envs correctly (py312-django52,quality,docs,pii_check,lint-imports) —tox.iniparses cleanly against the new[dependency-groups]namesCould not verify locally:
uv sync --group dev(andtest/quality/doc, which all transitively depend onmysqlclient) fails to build in this sandbox becausemysqlclienthas no macOS wheel on PyPI and needs local MySQL client headers (pkg-config,libmysqlclient) that aren't installable here (no Homebrew/package manager in this sandbox). This is a pre-existing characteristic of the repo (the same coupling existed in the oldrequirements/quality.txt, which also pulled inmysqlclienttransitively via-r test.txt), not something introduced by this migration, and it's expected to build fine on GitHub Actions'ubuntu-latestrunners (which ship with MySQL client libraries preinstalled — the same way the pre-migration CI already builtmysqlclientwithout any extraapt-getstep). Full test-suite / quality-check execution is therefore relying on this PR's own CI run rather than local verification.Code reviewer notes
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_TOKENsecret used byrelease.ymlis configured for this repo..github/workflows/upgrade-python-requirements.ymlcallsopenedx/.github's shared reusable workflow, which hardcodesadd-paths: requirementswith no override input. Now thatrequirements/is deleted, that scheduled job will keep running but silently stop producing real dependency-upgrade PRs (empty diff, no failure, no alert). This can't be fixed from this repo — it needs a fix inopenedx/.githubitself (e.g. parameterizingadd_paths, or auto-detectinguv.lockvs.requirements/).mysqlclientis bundled into thetest-basedependency group (and thereforetest/quality/doc/ci/devtransitively), matching the pre-migration coupling inrequirements/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].ciis intentionally minimal (tox,tox-uvonly, noinclude-group) — CI's ownuv sync --group cistep only needstoxonPATH;toxinstalls each env's actual dependency group itself viauv-venv-lock-runner.This PR was created with Claude Code.