Skip to content

Modernize openedx-calc to uv + pyproject.toml + semantic-release - #217

Merged
feanil merged 21 commits into
openedx:masterfrom
irfanuddinahmad:irfanuddinahmad/modernize-python-tooling
Sep 30, 2026
Merged

feanil merged 21 commits into
openedx:masterfrom
irfanuddinahmad:irfanuddinahmad/modernize-python-tooling

Conversation

@irfanuddinahmad

@irfanuddinahmad irfanuddinahmad commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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

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

  • Move calc/ and symmath/ into src/calc/ and src/symmath/ (src/ layout, per
    the 2026-07-15 decision on #506) — tests/ stays at the repo root since it was
    never nested inside either package and isn't shipped in the distribution.
  • Replace setup.py/setup.cfg with pyproject.toml (PEP 621 static metadata)
  • Switch from pip-compile to uv with PEP 735 dependency groups (test, quality,
    ci, dev); 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, publishing to PyPI via OIDC

Removed

Deleted files:

  • setup.py, setup.cfg (superseded by pyproject.toml; [pycodestyle] moved to
    a standalone .pep8 file, the only section setup.cfg had)
  • .coveragerc (moved to [tool.coverage.*] in pyproject.toml)
  • requirements/ (superseded by uv.lock + [dependency-groups])
  • .github/workflows/pypi-publish.yml (token-based publish-on-tag workflow;
    replaced by release.yml's OIDC publish_to_pypi job)

Removed Makefile targets: none removed — clean/test/requirements/upgrade
all kept, just repointed at uv/tox-uv instead of pip/pip-compile.

Not included

  • No ruff migration — out of scope per the 2026-07-15 decision on #506 (pylint/
    pycodestyle left exactly as they were).
  • No dependency-group version matrix (e.g. django42) — this package has no
    framework dependency at all (lxml, markupsafe, numpy, pyparsing, six,
    sympy), so there's nothing to matrix against.

Versioning

Dynamic, via setuptools-scm reading the latest git tag (fallback_version = "0.0.0"). Pre-flight check passed: latest tag v5.0.0 (via
git tag --sort=-v:refname) matches the version currently live on PyPI (5.0.0), so
semantic-release's first automated release won't compute a version lower than what's
already published.

Known gaps / needs maintainer action (not code issues)

  1. PyPI OIDC trusted publisher needs configuring for openedx-calc before the
    first automated release can publish (tracked in the consolidated comment on
    #506).
    OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN is already a standard org-level secret
    used by many other repos, so no action needed there.
  2. .github/workflows/upgrade-python-requirements.yml calls the org'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.

Testing Notes

Verified locally (not just hoped CI would catch it):

  • uv lock / uv lock --check resolve cleanly, no drift
  • uv sync --group dev and uv sync --group ci succeed
  • uv run tox — both py and quality environments pass: 64 tests pass,
    pycodestyle --config=.pep8 and pylint --rcfile=pylintrc both clean (py312 was
    renamed to the generic py in tox.ini/ci.yml, and ci.yml's job uses a static
    name: Tests — matching pre-migration main's exact naming/casing so the checks
    GitHub reports don't change)
  • uv run --with build python -m build succeeds, producing a correctly versioned
    (5.0.0, matching the git tag) sdist + wheel, with symmath/README.md correctly
    bundled and tests/ correctly excluded
  • Found and fixed a real latent bug in the process: symmath/formula.py does
    import six directly, but six was never listed in requirements/base.in — it
    only worked before because some other pinned dependency happened to pull it in
    transitively. uv's fresh resolution doesn't reproduce that transitive path, so
    tests failed with ModuleNotFoundError: No module named 'six' until six was
    added as an explicit dependency.
  • Independently re-verified every SHA pin in release.yml against the actual
    GitHub tag→commit mapping (gh api repos/<owner>/<repo>/tags) rather than trusting
    the sibling-repo reference implementation's pins as-is: the python-semantic-release,
    actions/upload-artifact, and actions/download-artifact pins copied from that
    reference were wrong (upload/download were swapped, and the semantic-release
    SHA didn't correspond to any commit in that repo at all) and have been corrected
    here.

Code reviewer notes

  • The src/ layout move (calc/ → src/calc/, symmath/ → src/symmath/) is a
    separate first commit, isolated from the metadata/uv/release commits, for easier
    review.
  • six was added to [project].dependencies — see Testing Notes above for why.

This PR was created with Claude Code.

Move the calc and symmath packages into src/calc and src/symmath,
per the src/ layout decision on openedx/public-engineering#506
(2026-07-15): flat-layout editable installs aren't resolvable by
tools like mypy, while src/-layout repos work fine.

tests/ stays at the repo root (it was never nested inside calc/ or
symmath/ to begin with, and isn't shipped in the distribution).

Update .coveragerc's source path accordingly; the remaining path
references (tox.ini, setup.py) are updated in the following commits
that replace those files entirely.
Replace setup.py/setup.cfg with PEP 621 static metadata in
pyproject.toml: name, description, SPDX license expression, authors,
classifiers, static dependencies, setuptools-scm dynamic versioning,
dependency-groups (PEP 735), and semantic-release configuration.

Move [pycodestyle] from setup.cfg into a standalone .pep8 file (no
other tool configuration existed in setup.cfg to port).

Move coverage config from .coveragerc into [tool.coverage.*], with
source paths updated for the new src/ layout, and add omit/exclude
patterns.

Remove the hardcoded __version__ from calc/__init__.py (permanently
stale once setuptools-scm derives it from git tags) in favor of
reading it from installed package metadata via importlib.metadata.

Part of openedx/public-engineering#506.
Replace requirements/*.in + pip-compile with PEP 735 dependency groups
in pyproject.toml (test, quality, ci, dev), managed and locked via uv:

- Add [tool.uv].constraint-dependencies, machine-managed by
  `edx_lint write_uv_constraints` (see [tool.edx_lint].uv_constraints
  for repo-specific overrides).
- Commit uv.lock.
- Delete the requirements/ directory; drop the now-stale
  `include requirements/*` lines from MANIFEST.in.
- Update tox.ini to use tox-uv's uv-venv-lock-runner with
  dependency_groups instead of deps/-r requirements files, with paths
  updated for the src/ layout.
- Update the Makefile's requirements/test/upgrade targets to use
  `uv sync`, `uv run tox`, and `uv lock --upgrade`.
- Update the CI workflow to install uv (pinned to a commit SHA) and
  run `uv sync --group ci` + `uv run tox -e <toxenv>`, with
  per-matrix-job names, read-only permissions, and fetch-depth: 0 so
  setuptools-scm can see tags.
- Add "six" as an explicit runtime dependency: symmath/formula.py
  imports it directly, but it was never listed in requirements/base.in
  -- it only worked before because some other pinned dependency
  happened to pull it in transitively. uv's fresh resolution doesn't
  reproduce that, and tests failed with ModuleNotFoundError until this
  was added.

Part of openedx/public-engineering#506.
Add release.yml: on push to master, runs the CI workflow, then
python-semantic-release (OIDC-free step, github_token from
OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN), then publishes to PyPI via
OIDC trusted publishing (id-token: write, no stored credentials) if a
release was cut. [tool.semantic_release] (build_command, major_on_zero,
allow_zero_version) was already added to pyproject.toml in the metadata
commit.

Delete the old token-based pypi-publish.yml (triggered on `push: tags`,
used PYPI_UPLOAD_TOKEN) -- release.yml's publish_to_pypi job replaces
it with OIDC, per the decision on openedx/public-engineering#506.

Update ci.yml to add a workflow_call trigger (so release.yml can reuse
it) and drop its own push-to-master trigger, since release.yml now
owns that path -- avoids running the test suite twice on every push to
master.

commitlint.yml already called the org's shared reusable workflow; no
change needed there.

Pre-flight check: latest git tag (v5.0.0, via
`git tag --sort=-v:refname`) matches openedx-calc's actual latest
version on PyPI (5.0.0), so semantic-release's next computed version
will not collide with or undercut what's already published.

Part of openedx/public-engineering#506.
@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 @openedx/openedx-unmaintained.

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 27, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jul 27, 2026
irfanuddinahmad and others added 8 commits July 28, 2026 02:46
Verified every uses:@sha in release.yml against the GitHub API
(repos/<owner>/<repo>/commits/<sha>). While these SHAs happened to be
valid commits (unlike the same pins in sibling PRs opaque-keys/
openedx-core, where they were swapped/fabricated), pinning these isn't
required by the migration ticket and isn't done by openedx/XBlock's
actual, already-releasing release.yml. Reverted python-semantic-release,
upload-artifact, and download-artifact to plain version tags matching
XBlock exactly. pypa/gh-action-pypi-publish was already correctly
pinned to the real commit SHA -- left unchanged.
…ration

This repo never had a CHANGELOG.rst. Per the modernize-python-tooling
effort's decision to not disable changelog generation, add one from
scratch and wire python-semantic-release to keep it updated in place:

- Create CHANGELOG.rst containing only the insertion marker
- Remove changelog: "false" from release.yml's PSR step
- Configure [tool.semantic_release.changelog] to update CHANGELOG.rst
  in RST format at the marker
- Set tag_format = "v{version}" explicitly to match this repo's actual
  tag convention (verified via git tag --sort=-v:refname)

Verified locally: running `semantic-release changelog` against this
config produces a correctly formatted Unreleased section (grouped by
commit type, linked to commit SHAs/PRs) above the marker, and also
backfills the v5.0.0 section from the existing tag history.
…ernize-python-tooling

# Conflicts:
#	.github/workflows/ci.yml
#	.github/workflows/pypi-publish.yml
Set changelog: "false" on the PSR release step and remove the
[tool.semantic_release.changelog] config / insertion marker.

Checked against openedx/XBlock's actual production release.yml (the one
repo in this effort that has cut real automated releases) -- every run
passes changelog: false and invokes `semantic-release -v version
--no-changelog`, and the repo has zero github-actions[bot] commits ever.
The auto-changelog config this migration previously added was only ever
verified via a local dry-run prototype, never against a real release.

feanil flagged the same issue on openedx/DoneXBlock#388: "I thought we
were not going to add changelogs since they can't be updated by
python-semantic-release the way we have it setup."
The old instructions had developers manually create+activate a venv
before running make requirements -- uv sync (which make requirements
now runs) creates and manages its own venv, making that step unnecessary
and, since it never mentioned uv, misleading about how the tooling
actually works now.
This repo has immutable releases enabled, which freezes a release's assets the moment it's published. Previously this workflow didn't even attempt to attach dist files to the GitHub release (relying only on the actions/upload-artifact -> download-artifact path for PyPI publish), so every release shipped with an empty GitHub Release page. Matches the fix already proven on openedx/sample-plugin#57 and validated end-to-end on openedx/event-tracking#434: build without publishing (vcs_release: false), then create the release with dist/* attached in one gh release create call. Not adding the separate gitpython/uv workaround from event-tracking#435/#436 here -- these PRs won't merge until upstream python-semantic-release fixes the GitPython 3.1.60 break (python-semantic-release/python-semantic-release#1476).
A prior commit (550a144) deliberately un-pinned python-semantic-release,
actions/upload-artifact, and actions/download-artifact to plain version
tags, reasoning that pinning wasn't required by the migration ticket and
that openedx/XBlock's release.yml doesn't do it either. It also left the
release job's checkout pinned to an actions/checkout SHA for v7.0.0,
stale relative to ci.yml's own v7.0.1 pin.

openedx/sample-plugin is this org's designated gold-standard reference
for release.yml, and it pins all of these (each SHA independently
re-verified against the action's own tag history via the GitHub API).
Restored/corrected the pins to match, picking up version bumps along the
way: actions/checkout v7.0.0 -> v7.0.1, python-semantic-release
v10.6.1 -> v10.6.2, and pypa/gh-action-pypi-publish v1.14.1 -> v1.14.2.

Also brought release.yml in line with sample-plugin in three more ways:
- added `if-no-files-found: error` to the dist upload step, so a release
  that produced no artifacts fails loudly instead of silently.
- added the `github.ref_name == 'master'` guard to publish_to_pypi's
  `if`, matching the release job's own guard, so the job can't fire on
  a non-default-branch workflow run.
- dropped `fetch-depth: 0` from the release job's checkout; python-semantic-release
  auto-deepens a shallow clone itself before evaluating version history,
  so it's never needed there.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
src/calc/__init__.py sets __version__ from importlib.metadata; nothing
else in the package reads or parses __version__, so a shallow clone is
sufficient for CI. sample-plugin's own backend-ci.yml doesn't set
fetch-depth: 0 either. Matches that reference.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Comment thread pyproject.toml Resolved
Comment thread tox.ini Resolved
@salman2013

Copy link
Copy Markdown

@irfanuddinahmad Could you check why the following checks aren't running?

  • Tests (ubuntu-latest, 3.12, py
  • Tests (ubuntu-latest, 3.12, quality)

Aligns with the org-standard pattern (sample-plugin, other migrated
repos): a generic 'py' env instead of a version-pinned one, and a
static job name so GitHub auto-generates matrix-suffixed check names
(e.g. "tests (ubuntu-latest, 3.12, py)") instead of bare toxenv names.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@irfanuddinahmad

Copy link
Copy Markdown
Contributor Author

Fixed in b79ff2a — renamed py312→py in tox.ini/ci.yml and switched the job to a static name: tests, so checks now show up as tests (ubuntu-latest, 3.12, py) / tests (ubuntu-latest, 3.12, quality), matching the sample-plugin convention.

Branch protection on master requires "Tests (ubuntu-latest, 3.12, py)"
and "Tests (ubuntu-latest, 3.12, quality)" (capital T), carried over
from this repo's pre-migration ci.yml. GitHub's required-status-check
matching is case-sensitive, so the previous lowercase "tests" job name
left those required checks permanently unsatisfied.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…e job

Matches openedx/sample-plugin's current release.yml; the custom
OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN secret isn't needed.
Comment thread README.rst
of the python versions specified for the repo (currently 3.11 and 3.12) --
there's no need to create one yourself.

Then you can run the tests with just `tox`.

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.

uv sync creates .venv but doesn't activate it, so there's no tox on PATH after make requirements:

$ make requirements
$ tox -l
bash: line 1: tox: command not found

The activation step this PR removes just above is the one the Makefile now assumes, so keep it, as source .venv/bin/activate. tox -r under "When Upgrading Requirements" needs the same, and the paragraph you added says 3.11 and 3.12 while requires-python is >=3.12.

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 source .venv/bin/activate after both make requirements and make upgrade/before tox -r; fixed the stray "3.11 and 3.12" mention to just 3.12. Verified by following the README literally on a fresh clone.

Comment thread Makefile Outdated

test: ## Run the library test suite
tox
uv run tox

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 tox. 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 tox now.

Makefile now assumes an already-synced/activated local env; uv run
stays in CI workflow steps only. See openedx-unsupported/ccx-keys#190 (review
comment r4097501942).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

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

Just a little docs cleanup and then I think this is good to go.

Comment thread README.rst
of the python versions specified for the repo (currently 3.11 and 3.12) --
there's no need to create one yourself.

Then you can run the tests with just `tox`.

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.

You still need to activate the venv before you can call tox or you can call uv run tox.

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 source .venv/bin/activate after both make requirements and make upgrade/before tox -r; fixed the stray "3.11 and 3.12" mention to just 3.12. Verified by following the README literally on a fresh clone.

Add `source .venv/bin/activate` right after `make requirements` (and
again after `make upgrade`, before `tox -r`) so tox/pytest actually
resolve from the venv uv created, per feanil's repeated review
feedback on openedx#217. Also fix the "3.11 and 3.12" mention to just "3.12",
matching requires-python in pyproject.toml.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@feanil
feanil merged commit 61aeb81 into openedx:master Sep 30, 2026
4 checks passed
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

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants