-
Notifications
You must be signed in to change notification settings - Fork 8
feat: modernize Python tooling (pyproject.toml + uv + semantic-release) #242
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
base: main
Are you sure you want to change the base?
Changes from all commits
9a6b160
8e905de
c7d2388
c6a2aca
543b2b8
5d13930
5a89d56
0689524
3e3ac11
61d1897
99bb817
b312a34
059e5eb
9368fae
e194a89
c692ce5
50df933
33c58a2
c2df9e5
5826605
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: Semantic Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| run_ci: | ||
| uses: ./.github/workflows/ci.yml | ||
|
|
||
| release: | ||
| needs: run_ci | ||
| runs-on: ubuntu-latest | ||
| if: github.ref_name == 'main' | ||
| 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| 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 | ||
| uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3 | ||
| with: | ||
| github_token: ${{ secrets.OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN }} | ||
| git_committer_name: "github-actions" | ||
| git_committer_email: "actions@users.noreply.github.com" | ||
|
|
||
| - name: Publish | Upload to GitHub Release Assets | ||
| uses: python-semantic-release/publish-action@310a9983a0ae878b29f3aac778d7c77c1db27378 # v10.5.3 | ||
| if: steps.release.outputs.released == 'true' | ||
| with: | ||
| github_token: ${{ secrets.OPENEDX_SEMANTIC_RELEASE_GITHUB_TOKEN }} | ||
| tag: ${{ steps.release.outputs.tag }} | ||
|
|
||
| - name: Upload | Distribution Artifacts | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| 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 == 'main' && needs.release.outputs.released == 'true' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Setup | Download Build Artifacts | ||
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | ||
| with: | ||
| name: distribution-artifacts | ||
| path: dist | ||
|
|
||
| - name: Publish to PyPi | ||
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| include CHANGELOG.rst | ||
| include LICENSE.txt | ||
| include README.rst | ||
| include requirements/base.in | ||
| include requirements/constraints.txt | ||
| recursive-include openedx_ledger *.html *.png *.gif *.js *.css *.jpg *.jpeg *.svg | ||
| recursive-include src/openedx_ledger *.html *.png *.gif *.js *.css *.jpg *.jpeg *.svg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| .PHONY: clean compile_translations coverage diff_cover docs dummy_translations \ | ||
| .PHONY: clean compile-requirements compile_translations coverage diff_cover docs dummy_translations \ | ||
| extract_translations fake_translations help pii_check pull_translations push_translations \ | ||
| quality requirements selfcheck test test-all upgrade validate install_transifex_client | ||
|
|
||
|
|
@@ -26,42 +26,24 @@ coverage: clean ## generate and view HTML coverage report | |
| $(BROWSER)htmlcov/index.html | ||
|
|
||
| docs: ## generate Sphinx HTML documentation, including API docs | ||
| tox -e docs | ||
| uv run tox -e docs | ||
| $(BROWSER)docs/_build/html/index.html | ||
|
|
||
| # Define PIP_COMPILE_OPTS=-v to get more information during make upgrade. | ||
| PIP_COMPILE = pip-compile --upgrade $(PIP_COMPILE_OPTS) | ||
|
|
||
| upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade | ||
| upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in | ||
| pip install -qr requirements/pip-tools.txt | ||
| # Make sure to compile files after any other files they include! | ||
| $(PIP_COMPILE) --allow-unsafe -o requirements/pip.txt requirements/pip.in | ||
| $(PIP_COMPILE) -o requirements/pip-tools.txt requirements/pip-tools.in | ||
| pip install -qr requirements/pip.txt | ||
| pip install -qr requirements/pip-tools.txt | ||
| $(PIP_COMPILE) -o requirements/base.txt requirements/base.in | ||
| $(PIP_COMPILE) -o requirements/test.txt requirements/test.in | ||
| $(PIP_COMPILE) -o requirements/doc.txt requirements/doc.in | ||
| $(PIP_COMPILE) -o requirements/quality.txt requirements/quality.in | ||
| $(PIP_COMPILE) -o requirements/ci.txt requirements/ci.in | ||
| $(PIP_COMPILE) -o requirements/dev.txt requirements/dev.in | ||
| # Let tox control the Django version for tests | ||
| sed '/^[dD]jango==/d' requirements/test.txt > requirements/test.tmp | ||
| mv requirements/test.tmp requirements/test.txt | ||
| compile-requirements: ## generate the uv.lock file without upgrading packages | ||
| uv lock | ||
|
|
||
| upgrade: ## upgrade all packages in uv.lock and sync constraints from edx-lint | ||
| uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml | ||
| uv lock --upgrade | ||
|
|
||
| quality: ## check coding style with pycodestyle and pylint | ||
| tox -e quality | ||
| uv run tox -e quality | ||
|
|
||
| pii_check: ## check for PII annotations on all Django models | ||
| tox -e pii_check | ||
|
|
||
| piptools: ## install pinned version of pip-compile and pip-sync | ||
| pip install -r requirements/pip.txt | ||
| pip install -r requirements/pip-tools.txt | ||
| uv run tox -e pii_check | ||
|
|
||
| requirements: piptools ## install development environment requirements | ||
| pip-sync -q requirements/dev.txt requirements/private.* | ||
| requirements: ## install development environment requirements | ||
| uv sync --group dev | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requirements: ## install development environment requirements
uv sync --group dev
uv tool install tox --with tox-uv
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On reflection, reverting this — it installs an unpinned tox outside |
||
|
|
||
| test: clean ## run tests in the current virtualenv | ||
| DJANGO_SETTINGS_MODULE=test_settings pytest | ||
|
|
@@ -70,22 +52,22 @@ diff_cover: test ## find diff lines that need test coverage | |
| diff-cover coverage.xml | ||
|
|
||
| test-all: quality pii_check ## run tests on every supported Python/Django combination | ||
| tox | ||
| tox -e docs | ||
| uv run tox | ||
| uv run tox -e docs | ||
|
|
||
| validate: quality pii_check test ## run tests and quality checks | ||
|
|
||
| selfcheck: ## check that the Makefile is well-formed | ||
| @echo "The Makefile is well-formed." | ||
|
|
||
| isort: | ||
| isort tests openedx_ledger manage.py setup.py test_settings.py | ||
| isort tests src/openedx_ledger manage.py test_settings.py | ||
|
|
||
| style: | ||
| pycodestyle openedx_ledger tests manage.py setup.py | ||
| pycodestyle src/openedx_ledger tests manage.py | ||
|
|
||
| lint: | ||
| pylint openedx_ledger tests manage.py setup.py | ||
| pylint src/openedx_ledger tests manage.py | ||
|
|
||
| ## Docker in this repo is only supported for running tests locally | ||
| ## as an alternative to virtualenv natively | ||
|
|
@@ -96,14 +78,14 @@ test-shell: ## Run a shell, as root, on the specified service container | |
|
|
||
| extract_translations: ## extract strings to be translated, outputting .mo files | ||
| rm -rf docs/_build | ||
| cd openedx_ledger && ../manage.py makemessages -l en -v1 -d django | ||
| cd openedx_ledger && ../manage.py makemessages -l en -v1 -d djangojs | ||
| cd src/openedx_ledger && ../../manage.py makemessages -l en -v1 -d django | ||
| cd src/openedx_ledger && ../../manage.py makemessages -l en -v1 -d djangojs | ||
|
|
||
| compile_translations: ## compile translation files, outputting .po files for each supported language | ||
| cd openedx_ledger && ../manage.py compilemessages | ||
| cd src/openedx_ledger && ../../manage.py compilemessages | ||
|
|
||
| detect_changed_source_translations: | ||
| cd openedx_ledger && i18n_tool changed | ||
| cd src/openedx_ledger && i18n_tool changed | ||
|
|
||
| pull_translations: ## pull translations from Transifex | ||
| tx pull -a -f -t --mode reviewed | ||
|
|
@@ -112,7 +94,7 @@ push_translations: ## push source translation files (.po) from Transifex | |
| tx push -s | ||
|
|
||
| dummy_translations: ## generate dummy translation (.po) files | ||
| cd openedx_ledger && i18n_tool dummy | ||
| cd src/openedx_ledger && i18n_tool dummy | ||
|
|
||
| build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files | ||
|
|
||
|
|
||
This file was deleted.
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.
astral-sh/setup-uvis missing two parameters:Without
enable-cache: truethe uv package cache is not persisted across runs. Withoutpython-version, Python is not managed bysetup-uv, which leaves thesetup pythonstep above still load-bearing rather than redundant.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.
Confirmed already correct —
setup-uvhas bothenable-cache: trueandpython-versionset.