Repository navigation
chore: modernize Python tooling (uv, PEP 621, semantic-release, src layout) #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
salman2013
wants to merge
3
commits into
openedx:master
Choose a base branch
from
salman2013:modernize-python-tooling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| name: Semantic Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
|
|
||
| jobs: | ||
| # The same aggregate a pull request has to pass, so the release runs exactly | ||
| # the checks that were required to merge -- and picks up any package added to | ||
| # ci.yml later without needing a change here. | ||
| run_ci: | ||
| uses: ./.github/workflows/ci.yml | ||
|
|
||
| release: | ||
| # Every package this workflow publishes has to build before we tag | ||
| # anything. The GitHub release and the PyPI uploads cannot be taken back, | ||
| # so a package that only fails to build in its publish job would leave the | ||
| # release half-finished. | ||
| needs: [run_ci] | ||
| runs-on: ubuntu-latest | ||
| if: github.ref_name == 'master' | ||
| concurrency: | ||
| group: ${{ github.workflow }}-release-${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| # Note: We checkout the repository at the branch that triggered the workflow. | ||
| # Python Semantic Release will automatically convert shallow clones to full clones | ||
| # if needed to ensure proper history evaluation. However, we forcefully reset the | ||
| # branch to the workflow sha because it is possible that the branch was updated | ||
| # while the workflow was running, which prevents accidentally releasing un-evaluated | ||
| # changes. | ||
| - name: Setup | Checkout Repository on Release Branch | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.ref_name }} | ||
|
|
||
| - name: Setup | Force release branch to be at workflow sha | ||
| run: | | ||
| git reset --hard ${{ github.sha }} | ||
|
|
||
| - name: Action | Semantic Version Release | ||
| id: release | ||
| # Adjust tag with desired version if applicable. | ||
| uses: python-semantic-release/python-semantic-release@9a026e9303981c866c3425723009becb2437c757 # v10.6.2 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| git_committer_name: "github-actions" | ||
| git_committer_email: "actions@users.noreply.github.com" | ||
| changelog: "false" | ||
| # Commit, tag, push and build, but don't create the GitHub release. | ||
| # We create it ourselves in the next step so that the distributions | ||
| # are attached before the release is published. See that step for why. | ||
| vcs_release: "false" | ||
|
|
||
| # This repo has immutable releases enabled, which freezes a release's | ||
| # assets the moment it is published, so assets cannot be attached | ||
| # afterwards. Everything we want on the release has to be built by now | ||
| # and passed to this one command, which creates the release as a draft, | ||
| # uploads the assets, and only then publishes it: | ||
| # https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/immutable-releases | ||
| - name: Publish | Create GitHub Release with Assets | ||
| if: steps.release.outputs.released == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # Reuse the release notes python-semantic-release generated for us. | ||
| RELEASE_NOTES: ${{ steps.release.outputs.release_notes }} | ||
| TAG: ${{ steps.release.outputs.tag }} | ||
| run: | | ||
| # Output the release notes to a file | ||
| printf '%s' "$RELEASE_NOTES" > "$RUNNER_TEMP/release_notes.md" | ||
| # Creates the release as a draft, uploads the assets, and then | ||
| # publishes it -- all within this one command. | ||
| gh release create "$TAG" \ | ||
| --verify-tag \ | ||
| --title "$TAG" \ | ||
| --notes-file "$RUNNER_TEMP/release_notes.md" \ | ||
| dist/* | ||
|
|
||
| - name: Upload | Distribution Artifacts | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| if: steps.release.outputs.released == 'true' | ||
| with: | ||
| name: distribution-artifacts | ||
| path: dist/ | ||
| if-no-files-found: error | ||
|
|
||
| outputs: | ||
| released: ${{ steps.release.outputs.released || 'false' }} | ||
| version: ${{ steps.release.outputs.version }} | ||
|
|
||
| publish_to_pypi: | ||
| # 1. Separate out the publish step from the github release step to run each step at | ||
| # the least amount of token privilege | ||
| # 2. Also, publishing can fail, and its better to have a separate job if you need to retry | ||
| # and it won't require reversing the release. | ||
| runs-on: ubuntu-latest | ||
| needs: release | ||
| if: github.ref_name == 'master' && needs.release.outputs.released == 'true' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Setup | Download Build Artifacts | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| name: distribution-artifacts | ||
| path: dist/ | ||
|
|
||
| - name: Publish to PyPI | ||
| uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,2 @@ | ||
| include LICENSE | ||
| include README.md | ||
| include requirements/base.in | ||
| include requirements/constraints.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| [build-system] | ||
| requires = ["setuptools", "setuptools-scm>8.1"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "xblock-image-explorer" | ||
| description = "XBlock - Image Explorer" | ||
| readme = "README.md" | ||
| license = "AGPL-3.0" | ||
| license-files = ["LICENSE"] | ||
| authors = [ | ||
| {name = "edX", email = "oscm@edx.org"}, | ||
| ] | ||
| keywords = ["Python", "edx", "xblock"] | ||
| classifiers = [ | ||
| "Development Status :: 5 - Production/Stable", | ||
| "Framework :: Django", | ||
| "Framework :: Django :: 4.2", | ||
| "Framework :: Django :: 5.2", | ||
| "Intended Audience :: Developers", | ||
| "Natural Language :: English", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.12", | ||
| ] | ||
| requires-python = ">=3.12" | ||
| dynamic = ["version"] | ||
| dependencies = [ | ||
| "xblock[django]", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/openedx/xblock-image-explorer" | ||
|
|
||
| [project.entry-points."xblock.v1"] | ||
| image-explorer = "image_explorer:ImageExplorerBlock" | ||
|
|
||
| [tool.setuptools_scm] | ||
| version_scheme = "only-version" | ||
| local_scheme = "no-local-version" | ||
| # Dummy version number for when .git isn't accessible. | ||
| # This happens, for example, when bind-mounting into a Docker image. | ||
| fallback_version = "0.0.0.dev0" | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["src"] | ||
| include = ["image_explorer*"] | ||
|
|
||
| [tool.setuptools.package-data] | ||
| "image_explorer" = [ | ||
| "static/**", | ||
| "templates/**", | ||
| "public/**", | ||
| "conf/locale/**", | ||
| ] | ||
|
|
||
| [tool.setuptools.exclude-package-data] | ||
| "*" = ["tests*", "*.tests*", "spec*", "*.spec*"] | ||
|
|
||
| [tool.coverage.run] | ||
| branch = true | ||
| source_pkgs = ["image_explorer"] | ||
| omit = [ | ||
| "*/tests/*", | ||
| "*/migrations/*", | ||
| "*/__pycache__/*", | ||
| "*/settings.py", | ||
| ] | ||
|
|
||
| [tool.coverage.report] | ||
| show_missing = true | ||
| exclude_lines = [ | ||
| "pragma: no cover", | ||
| "def __repr__", | ||
| "raise AssertionError", | ||
| "raise NotImplementedError", | ||
| "if __name__ == .__main__.:", | ||
| "if TYPE_CHECKING:", | ||
| ] | ||
|
|
||
| [tool.coverage.html] | ||
| directory = "htmlcov" | ||
|
|
||
| [dependency-groups] | ||
| # Base test dependencies (no Django — pinned per group below) | ||
| test-base = [ | ||
| "mock", | ||
| "pytest-cov", | ||
| "pytest-django", | ||
| "xblock-sdk", | ||
| ] | ||
| # Default test group uses current supported Django (5.2) | ||
| test = [ | ||
| {include-group = "test-base"}, | ||
| "Django>=5.2,<6.0", | ||
| ] | ||
| # Legacy Django 4.2 support | ||
| django42 = [ | ||
| {include-group = "test-base"}, | ||
| "Django>=4.2,<5.0", | ||
| ] | ||
| quality = [ | ||
| {include-group = "test"}, | ||
| "edx-lint", | ||
| "pycodestyle", | ||
| ] | ||
| package = [ | ||
| "build", | ||
| "twine", | ||
| ] | ||
| # Minimal CI group — install first, then call uv run tox | ||
| ci = [ | ||
| "tox", | ||
| "tox-uv>=1", | ||
| ] | ||
| dev = [ | ||
| {include-group = "quality"}, | ||
| {include-group = "ci"}, | ||
| {include-group = "package"}, | ||
| ] | ||
|
|
||
| [tool.semantic_release] | ||
| # version is dynamic via setuptools-scm; no version_toml needed | ||
| build_command = "python -m pip install --upgrade build && SETUPTOOLS_SCM_PRETEND_VERSION=$NEW_VERSION python -m build" | ||
|
|
||
| [tool.edx_lint] | ||
| uv_constraints = [] | ||
|
|
||
| # NOTE: [tool.uv].constraint-dependencies is machine-managed. | ||
| # Run: uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml | ||
| [tool.uv] | ||
| package = true | ||
| default-groups = [] | ||
| conflicts = [ | ||
| [ | ||
| {group = "test"}, | ||
| {group = "django42"}, | ||
| ], | ||
| ] | ||
| constraint-dependencies = [ | ||
| "Django<6.0", | ||
| "elasticsearch<7.14.0", | ||
| ] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translations/config.yamlis present in the repo (src/image_explorer/translations/) and was included in the master wheel, but is missing from the PR wheel. Add"translations/**"to[tool.setuptools.package-data]:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because translations/ in this repo is a symlink (git mode 120000) pointing to conf/locale/. Setuptools cannot copy symlinks as package data — it fails with:
error: can't copy 'src/image_explorer/translations': doesn't exist or not a regular file
The actual files (like config.yaml) live in conf/locale/, which is already covered by the existing "conf/locale/" entry. So adding "translations/" would be redundant and break the wheel build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reviewed the translations setup — translations/config.yaml is the atlas config used to pull translation files into the source repo (via make pull_translations in the Makefile). Atlas reads the source tree, not the installed wheel, so this file doesn't need to be in the package. Closing this comment.
https://github.com/salman2013/xblock-image-explorer/blob/modernize-python-tooling/src/image_explorer/conf/locale/config.yaml
https://github.com/salman2013/xblock-image-explorer/blob/modernize-python-tooling/Makefile