-
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
6cc3b11
04bb271
094fb63
eb84697
911a5cc
2059bad
ca4c7d8
1172278
0426c54
1a91f62
d0d6e8a
af7b7b7
b2eff5b
4a939c5
bb6e648
70e1cb8
02f0268
eaaca2f
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,103 @@ | ||
| 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@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 | ||
| uses: python-semantic-release/python-semantic-release@9a026e9303981c866c3425723009becb2437c757 # v10.6.2 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| git_committer_name: "github-actions" | ||
|
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.
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. Switched to GITHUB_TOKEN, removes the dependency on this secret entirely. |
||
| 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. `gh release create` handles this by creating the release as | ||
| # a draft, uploading the assets, and only then publishing 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 }} | ||
| RELEASE_NOTES: ${{ steps.release.outputs.release_notes }} | ||
| TAG: ${{ steps.release.outputs.tag }} | ||
| run: | | ||
| printf '%s' "$RELEASE_NOTES" > "$RUNNER_TEMP/release_notes.md" | ||
| 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 == 'main' && 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| .. DEPRECATED: This changelog is no longer maintained. Release notes are | ||
| published only on the GitHub Releases page: | ||
| https://github.com/openedx/openedx-ledger/releases | ||
|
|
||
| Change Log | ||
| ########## | ||
|
|
||
|
|
@@ -15,11 +19,6 @@ Unreleased | |
| ********** | ||
| * Nothing unreleased | ||
|
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. We should deprecate this file as we have moved to PSR
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. Added. |
||
|
|
||
| [2.0.0] | ||
|
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. We shouldn't remove it
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. Kept -- and CHANGELOG.rst now has a deprecation notice since release.yml publishes real GitHub Releases. |
||
| ******** | ||
| * chore: Upgrade Python requirements | ||
|
|
||
|
|
||
| [1.8.0] | ||
| ******** | ||
| * chore: Upgrade Python requirements | ||
|
|
||
| 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,66 +26,59 @@ coverage: clean ## generate and view HTML coverage report | |
| $(BROWSER)htmlcov/index.html | ||
|
|
||
| docs: ## generate Sphinx HTML documentation, including API docs | ||
| 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 | ||
| uv sync --group doc | ||
|
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. https://github.com/openedx/openedx-ledger/pull/242/changes#r4016431241 referring the relevant comment
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. Same fix as the linked comment -- consolidated to make docs.
Contributor
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
|
||
| DJANGO_SETTINGS_MODULE=test_settings PYTHONPATH=$(CURDIR) SPHINXOPTS=-W uv run doc8 --ignore-path docs/_build README.rst docs | ||
|
Contributor
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. We're dropping the Same for the other |
||
| rm -f docs/openedx_ledger.rst | ||
| rm -f docs/modules.rst | ||
| DJANGO_SETTINGS_MODULE=test_settings PYTHONPATH=$(CURDIR) SPHINXOPTS=-W uv run make -e -C docs clean | ||
| DJANGO_SETTINGS_MODULE=test_settings PYTHONPATH=$(CURDIR) SPHINXOPTS=-W uv run make -e -C docs html | ||
| uv run python -m build --wheel | ||
| uv run twine check dist/* | ||
|
|
||
| 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 sync --group quality | ||
| touch tests/__init__.py | ||
| uv run pylint src/openedx_ledger tests manage.py | ||
| rm tests/__init__.py | ||
| uv run pycodestyle src/openedx_ledger tests manage.py | ||
| uv run isort --check-only --diff tests src/openedx_ledger manage.py test_settings.py | ||
| $(MAKE) selfcheck | ||
|
|
||
| pii_check: ## check for PII annotations on all Django models | ||
| tox -e pii_check | ||
| DJANGO_SETTINGS_MODULE=test_settings uv run code_annotations django_find_annotations --config_file .pii_annotations.yml --lint --report --coverage | ||
|
|
||
| piptools: ## install pinned version of pip-compile and pip-sync | ||
| pip install -r requirements/pip.txt | ||
| pip install -r requirements/pip-tools.txt | ||
|
|
||
| requirements: piptools ## install development environment requirements | ||
| pip-sync -q requirements/dev.txt requirements/private.* | ||
| requirements: ## install development environment requirements | ||
| uv sync --group dev | ||
|
irfanuddinahmad marked this conversation as resolved.
|
||
|
|
||
| test: clean ## run tests in the current virtualenv | ||
| DJANGO_SETTINGS_MODULE=test_settings pytest | ||
|
|
||
| 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 | ||
| test-all: quality pii_check docs ## run tests on every supported Python/Django combination | ||
| uv run tox | ||
|
|
||
| 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 +89,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 +105,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 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.