Skip to content

Modernize Python repo: pyproject.toml + uv + semantic-release#251

Merged
salman2013 merged 22 commits into
mainfrom
salman/modernize-branch
Jul 14, 2026
Merged

Modernize Python repo: pyproject.toml + uv + semantic-release#251
salman2013 merged 22 commits into
mainfrom
salman/modernize-branch

Conversation

@salman2013

@salman2013 salman2013 commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Modernizes the Python tooling for xblocks-contrib in three phases, aligning with the Open edX org standard established in openedx/sample-plugin.

Ticket: openedx/public-engineering#506

Changes generated by Claude Sonnet 4.6 using the modernize-python-tooling skill, reviewed by Salman.


Commits

chore: migrate package metadata to pyproject.toml

  • Consolidated all package metadata into pyproject.toml (PEP 621) with static dependencies list and dynamic = ["version"]
  • Configured setuptools-scm (version_scheme = "only-version", local_scheme = "no-local-version")
  • Updated license to SPDX string format (PEP 639): license = "AGPL-3.0" + license-files = ["LICENSE.txt"]
  • Deleted setup.py and setup.cfg

chore: switch dependency management from pip-tools to uv

  • Added [dependency-groups] (PEP 735): test-base, test (Django 5.2), django42, quality, doc, ci, dev
  • Used [tool.uv].conflicts to allow Django 4.2 and 5.2 to coexist in a single uv.lock with separate resolutions
  • [tool.edx_lint].uv_constraints holds repo-specific pins; [tool.uv].constraint-dependencies managed by edx_lint write_uv_constraints
  • Rewrote tox.ini to use tox-uv>=1 and uv-venv-lock-runner with dependency_groups
  • Updated Makefile: upgrade runs uv lock --upgrade, requirements runs uv sync --group dev
  • Updated python-tests.yml: added astral-sh/setup-uv, uv sync --group ci, uv run tox
  • Deleted entire requirements/ directory (11 files)

chore: add python-semantic-release and commitlint workflows

  • Added [tool.semantic_release] with build_command exporting SETUPTOOLS_SCM_PRETEND_VERSION=$NEW_VERSION before uv build
  • Added release.yml: runs python-tests.yml as a reusable workflow, then PSR v10.5.3 on main, publishes to PyPI via OIDC trusted publisher (no token needed)
  • Added commitlint.yml: enforces conventional commit format on PRs
  • Deleted pypi-publish.yml (was causing duplicate publishes)
  • Reverted upgrade-python-requirements.yml to shared openedx/.github reusable workflow
  • Updated README.rst with uv-based setup instructions

Test plan

  • make requirements
  • uv run tox -e django42
  • uv run tox -e django52
  • uv run tox -e docs

salman2013 and others added 2 commits May 18, 2026 23:50
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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 May 18, 2026
@openedx-webhooks

openedx-webhooks commented May 18, 2026

Copy link
Copy Markdown

Thanks for the pull request, @salman2013!

This repository is currently maintained by @openedx/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 Fixed
@salman2013 salman2013 changed the title Salman/modernize branch Modernize Python repos: pyproject.toml + uv + semantic-release May 18, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@salman2013
salman2013 force-pushed the salman/modernize-branch branch from 0b62620 to 767f8d9 Compare May 18, 2026 19:20
@salman2013 salman2013 changed the title Modernize Python repos: pyproject.toml + uv + semantic-release Modernize Python repo: pyproject.toml + uv + semantic-release May 18, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions May 20, 2026
Resolved conflicts by keeping deletions of requirements/*.txt and
.github/workflows/pypi-publish.yml, which were intentionally removed
as part of the pip-tools → uv migration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@salman2013
salman2013 marked this pull request as ready for review June 3, 2026 19:38
Resolved conflicts by keeping requirements/*.txt deletions from modernize-branch
(migrated to pyproject.toml/uv). Includes codecov-action bump to v6.0.2 from main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@farhan

farhan commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@salman2013 Thanks for creating the PR!

I am sharing a review which is done with the help of Claude, please address if you agree:

Consider the standard repo as xblocks-extra after merging of openedx/xblocks-extra#50 and openedx/xblocks-extra#38.

Below are the gaps in PR #251 relative to the standardized xblocks-extra (main + PR 50 + PR 38).


1. pyproject.toml

2. MANIFEST.in

  • CHANGELOG.rst must go. PR 50 deletes CHANGELOG.rst (semantic-release with changelog: "false" → GitHub Releases are the changelog). PR Modernize Python repo: pyproject.toml + uv + semantic-release #251 still ships CHANGELOG.rst in the repo and include CHANGELOG.rst in MANIFEST.in — both should be removed.
  • Philosophy differs. The standard is exclusion-based (prune .github/docs/tests, exclude dev files) with package data declared in pyproject's [tool.setuptools.package-data]. PR Modernize Python repo: pyproject.toml + uv + semantic-release #251 is inclusion-based (recursive-include per file extension) with manual deep-path prunes. Aligning means moving the asset globs into [tool.setuptools.package-data] and slimming MANIFEST.in down to exclusions.
  • include LICENSE.txt is redundant — already covered by license-files in pyproject.

3. tox.ini

4. release.yml

5. CI workflow

6. Makefile

Repo-level stragglers in PR #251

  • Delete CHANGELOG.rst, .coveragerc, and (after ruff migration) pylintrc / pylintrc_tweaks.
  • Standard repo has a .python-version file; xblocks-core has none.

Top 3 by impact:

  1. ruff migration replacing the pylint/pycodestyle/pydocstyle/isort stack
  2. CHANGELOG.rst removal to match the semantic-release flow
  3. Deciding tox-in-CI vs direct-uv-in-CI — that one goes the other direction and may mean updating the xblocks-extra standard instead

🤖 Generated with Claude Code

salman2013 and others added 3 commits June 22, 2026 22:24
PSR's action environment does not have uv available, so uv build fails.
Switch to python -m build (installing it via pip) and remove the now-
unnecessary setup-uv step from release.yml.

Ref: openedx/XBlock#928

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace pylint/pycodestyle/pydocstyle/isort with ruff (E, F, I, W rules)
- Remove CHANGELOG.rst (semantic-release uses GitHub Releases)
- Move coverage config from .coveragerc into pyproject.toml
- Add Django classifiers and pin setuptools-scm>=8.0
- Add lint/format/test/docs Makefile targets delegating to tox
- SHA-pin all GitHub Actions in release.yml
- Add push-to-main trigger and set fail-fast: false in python-tests.yml
- Delete pylintrc, pylintrc_tweaks, .coveragerc, CHANGELOG.rst

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Modernizes the repo’s Python packaging/tooling by moving metadata/config into pyproject.toml, switching dependency management to uv, and introducing automated releases via python-semantic-release (plus commit message linting).

Changes:

  • Migrate packaging metadata/config from setup.py/setup.cfg into pyproject.toml (PEP 621) with setuptools-scm.
  • Replace pip-tools/requirements/*.txt with uv dependency groups + updated tox.ini and Make targets.
  • Add GitHub Actions workflows for semantic-release publishing and commitlint; update Python CI to use uv.

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pyproject.toml New canonical packaging + tool configuration; defines dependency groups for uv/tox.
tox.ini Switch tox to tox-uv with uv-venv-lock-runner and dependency groups.
Makefile Replace pip-tools workflow with uv-based install/upgrade and new lint/test/docs targets.
README.rst Update documentation for uv-based setup and adjust project status wording.
.github/workflows/python-tests.yml Update CI to install dependencies with uv and run tox via uv run.
.github/workflows/release.yml Add semantic-release-based GitHub Release + PyPI publish via OIDC.
.github/workflows/commitlint.yml Add Conventional Commits enforcement via reusable workflow.
MANIFEST.in Adjust packaged root files after metadata migration/removals.
setup.py Removed legacy setuptools metadata and pip-tools requirement loading.
setup.cfg Removed legacy tool configuration (isort/wheel).
requirements/* Removed pip-tools compiled requirements and constraints files in favor of uv.
pylintrc / pylintrc_tweaks Removed pylint configuration (quality now via ruff).
.github/workflows/pypi-publish.yml Removed legacy PyPI publish workflow (superseded by release workflow).
.coveragerc Removed in favor of coverage config in pyproject.toml.
CHANGELOG.rst Removed legacy changelog file (semantic-release configured without changelog generation).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.rst
Comment thread pyproject.toml Outdated
Comment thread .github/workflows/release.yml
Comment thread Makefile
Comment thread .github/workflows/python-tests.yml

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

small fixes to fully align with the xblocks-extra standard.

Comment thread .github/workflows/python-tests.yml
Comment thread pyproject.toml
salman2013 and others added 2 commits July 6, 2026 15:50
- Rename CI matrix job name to matrix.toxenv for clearer failure identification
- Expand ruff lint rules (B, C4, UP, DJ) with inline comments
- Add E501 ignore, isort known-third-party, and formatter indent-style
- Move coverage config to include omit patterns, exclude_lines, and show_missing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread .github/workflows/release.yml Fixed
Limit GITHUB_TOKEN to contents: read for the CI job to follow
least-privilege principle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@farhan

farhan commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Thanks @salman2013 — the big items from the last round are all done. One small thing remains:

CI — redundant setup-python step

astral-sh/setup-uv handles Python installation on its own when you pass python-version. The separate actions/setup-python step is redundant and inconsistent with the xblocks-extra standard.

# Remove this:
- name: Set up Python ${{ matrix.python-version }}
  uses: actions/setup-python@a309ff8b... # v6.2.0
  with:
    python-version: ${{ matrix.python-version }}

# Keep only this, with the two extra params:
- name: Install uv
  uses: astral-sh/setup-uv@08807647... # v8.1.0
  with:
    enable-cache: true
    python-version: "${{ matrix.python-version }}"

Everything else looks good — ruff, coverage in pyproject, classifiers, SHA-pinning, fail-fast: false, matrix job name, secrets: inherit, and the Makefile targets all match the xblocks-extra standard now.

Change request proposed in assistance with Claude Code

astral-sh/setup-uv handles Python installation via python-version param.
Removed separate actions/setup-python step and added enable-cache: true
to setup-uv, matching xblocks-extra standard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@salman2013
salman2013 requested a review from farhan July 7, 2026 11:31
Comment thread xblocks_contrib/lti/lti.py Fixed
Comment thread xblocks_contrib/lti/lti.py Fixed
salman2013 and others added 3 commits July 8, 2026 17:24
Auto-fixed 85 violations (f-strings, dict literals, deprecated builtins, etc.)
and manually fixed 25 more (raise...from None in except blocks, noqa suppressions
for pre-existing B017/B018/B008/B026 patterns, loop variable shadowing rename).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove request.body and oauth_headers from log.error() calls to prevent
clear-text logging of sensitive OAuth data (CodeQL: py/clear-text-logging-sensitive-data).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread xblocks_contrib/lti/lti.py Dismissed
@farhan

farhan commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Important

Written with the assistance of Claude Code, human-reviewed before posting.

Test Results: Modernize Python repo

Tested locally on salman/modernize-branch using the modernize-python-repos skill.


❌ Failures (must fix before merging)

1 — Hardcoded __version__ in package source

xblocks_contrib/__init__.py:12 still has __version__ = "0.17.0". With setuptools-scm deriving the version from git tags, this will be permanently stale after any new tag. Remove it (and update docs/conf.py which reads it via regex). If the version is needed at runtime, replace with importlib.metadata.

2 — Invented fail_under coverage threshold

The original .coveragerc had no fail_under — only a [run] section. The PR adds fail_under = 70 in [tool.coverage.report]. The migration rule is: if no threshold existed before, omit it entirely — do not invent one. Remove this line.


⚠️ Warnings

1 — Test files in the wheel (129 files)

The PR wheel contains test files (e.g. xblocks_contrib/annotatable/tests/test_annotatable.py) not present in the main branch wheel. Root cause: prune */tests in MANIFEST.in only prunes one directory level deep, and the isolated build with setuptools-scm discovers all git-tracked files. Recommend adding:

[tool.setuptools.exclude_package_data]
"*" = ["tests*", "*.tests*", "spec*", "*.spec*"]

@farhan
farhan force-pushed the salman/modernize-branch branch from f070339 to 6c47d7e Compare July 9, 2026 10:54
salman2013 and others added 3 commits July 10, 2026 15:39
- Remove hardcoded __version__ from __init__.py (stale with setuptools-scm)
- Update docs/conf.py to use importlib.metadata instead of reading __version__
- Remove invented fail_under = 70 coverage threshold (none existed before)
- Add exclude_package_data to prevent test files from being included in wheel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Setuptools requires [tool.setuptools.exclude-package-data] (hyphen),
not [tool.setuptools.exclude_package_data] (underscore), per its
pyproject.toml schema. The underscore variant caused a build failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@salman2013

Copy link
Copy Markdown
Contributor Author

@farhan Could you please take a look at PR again.

…conflicts

Merge origin/main (automated requirements upgrade #277) into branch.
Resolved modify/delete conflicts by keeping branch deletions of
requirements/*.txt — these files were intentionally removed as part
of migrating dependency management from pip-tools to uv.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

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

Ran full local verification (quality + docs + django42 + django52 — 841 tests pass on both Django versions). One blocker to address before merge, see inline.

Comment thread .github/workflows/release.yml Outdated
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to In Eng Review in Contributions Jul 13, 2026
…requirement

OIDC requires pre-configuring a trusted publisher on pypi.org before it can
work. Without that setup, the publish step would fail after PSR tags and bumps
the version, leaving a dangling tag with no package on PyPI.

Reverts to PYPI_UPLOAD_TOKEN secret auth, matching the existing pypi-publish.yml
on main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

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

LGTM!

Some manual testing of blocks before merging will be great.

@salman2013
salman2013 merged commit f5f9ced into main Jul 14, 2026
11 of 13 checks passed
@salman2013
salman2013 deleted the salman/modernize-branch branch July 14, 2026 10:54
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Jul 14, 2026
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.

7 participants