-
Notifications
You must be signed in to change notification settings - Fork 25
Modernize Python repo: pyproject.toml + uv + semantic-release #388
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
Changes from all commits
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,95 @@ | ||
| name: Semantic Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| run_tests: | ||
| uses: ./.github/workflows/ci.yml | ||
| secrets: inherit | ||
| permissions: | ||
| contents: read | ||
|
|
||
| release: | ||
| needs: run_tests | ||
| if: github.ref_name == 'master' | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: ${{ github.workflow }}-release | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.ref_name }} | ||
|
|
||
| - name: Reset to triggered commit | ||
| run: git reset --hard ${{ github.sha }} | ||
|
|
||
| - name: Python Semantic 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[bot]" | ||
| git_committer_email: "github-actions[bot]@users.noreply.github.com" | ||
| changelog: "false" | ||
| # Commit, tag, push and build, but don't create the GitHub release. | ||
| # We create it ourselves below so that the distributions are attached | ||
| # before the release is published (immutable releases require this ordering). | ||
| 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 must be built first and passed to this | ||
| # one command, which creates the release as a draft, uploads the assets, | ||
| # and only then publishes it. | ||
| - name: 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 dist artifacts | ||
|
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. Paired with - name: 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/* |
||
| if: steps.release.outputs.released == 'true' | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
farhan marked this conversation as resolved.
|
||
| if-no-files-found: error | ||
|
|
||
| outputs: | ||
| released: ${{ steps.release.outputs.released }} | ||
| version: ${{ steps.release.outputs.version }} | ||
|
|
||
| publish_to_pypi: | ||
| needs: release | ||
| if: needs.release.outputs.released == 'true' | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Download dist artifacts | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| name: dist | ||
| 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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ pip-log.txt | |
|
|
||
| # Unit test / coverage reports | ||
| .coverage | ||
| coverage.xml | ||
| .tox | ||
| nosetests.xml | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| include requirements/base.in | ||
| include NOTICE | ||
| include LICENSE | ||
| include requirements/constraints.txt | ||
|
|
||
| prune .github | ||
| prune docs | ||
| prune htmlcov | ||
| exclude coverage.xml | ||
| exclude .coverage | ||
| exclude uv.lock | ||
| exclude tox.ini |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,44 @@ | ||
| .PHONY: docs upgrade test quality install | ||
| .PHONY: docs upgrade test quality install install-test install-dev | ||
|
|
||
| REPO_NAME := DoneXBlock | ||
| DOCKER_NAME := donexblock | ||
|
|
||
| # For opening files in a browser. Use like: $(BROWSER)relative/path/to/file.html | ||
| BROWSER := python -m webbrowser file://$(CURDIR)/ | ||
| BROWSER := uv run python -m webbrowser file://$(CURDIR)/ | ||
|
|
||
| help: ## display this help message | ||
| @echo "Please use \`make <target>' where <target> is one of" | ||
| @awk -F ':.*?## ' '/^[a-zA-Z]/ && NF==2 {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort | ||
|
|
||
| install-test: | ||
|
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 have decided to not to drop the make file targets, we can provide their alternatives. |
||
| pip install -q -r requirements/test.txt | ||
|
|
||
| install-dev: | ||
| pip install -q -r requirements/dev.txt | ||
|
|
||
| install: install-test | ||
|
|
||
| quality: ## Run the quality checks | ||
|
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. We are not adding ruff in this scope because it needs to add more files formatting, so i removed that. |
||
| pylint --rcfile=pylintrc done | ||
| python setup.py -q sdist | ||
| twine check dist/* | ||
| uv run pylint --rcfile=pylintrc src/done | ||
| uv run python -m build --sdist | ||
| uv run twine check dist/* | ||
|
|
||
| test: ## Run the tests | ||
| mkdir -p var | ||
| rm -rf .coverage | ||
| python -m coverage run --rcfile=.coveragerc -m pytest | ||
| uv run python -m coverage run -m pytest | ||
| uv run python -m coverage xml | ||
|
|
||
| covreport: ## Show the coverage results | ||
| python -m coverage report -m --skip-covered | ||
|
|
||
| upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade | ||
| upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in | ||
| pip install -q -r requirements/pip-tools.txt | ||
| pip install -q -r requirements/pip.txt | ||
| pip-compile --upgrade --allow-unsafe -o requirements/pip.txt requirements/pip.in | ||
| pip-compile --upgrade -o requirements/pip-tools.txt requirements/pip-tools.in | ||
| pip install -q -r requirements/pip.txt | ||
| pip install -q -r requirements/pip-tools.txt | ||
| pip-compile --upgrade -o requirements/base.txt requirements/base.in | ||
| pip-compile --upgrade -o requirements/dev.txt requirements/dev.in | ||
| pip-compile --upgrade -o requirements/test.txt requirements/test.in | ||
| pip-compile --upgrade -o requirements/quality.txt requirements/quality.in | ||
| pip-compile --upgrade -o requirements/tox.txt requirements/tox.in | ||
| pip-compile --upgrade -o requirements/ci.txt requirements/ci.in | ||
| pip-compile --upgrade -o requirements/docs.txt requirements/docs.in | ||
| # lets tox controls the django versions. | ||
| sed -i.tmp '/^[d|D]jango==/d' requirements/test.txt | ||
| rm requirements/test.txt.tmp | ||
| uv run python -m coverage report -m --skip-covered | ||
|
|
||
| upgrade: ## update uv.lock and regenerate uv constraint-dependencies | ||
| uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml | ||
| uv lock --upgrade | ||
|
|
||
| .PHONY: requirements | ||
| requirements: ## install development environment requirements | ||
| pip install -r requirements/pip.txt | ||
| pip install -qr requirements/pip-tools.txt | ||
| pip install -r requirements/dev.txt | ||
| uv sync --group dev | ||
|
|
||
| install-test: ## install test dependencies | ||
| uv sync --group test | ||
|
|
||
| install-dev: ## install development dependencies | ||
| uv sync --group dev | ||
|
|
||
| install: install-test ## install default (test) dependencies | ||
|
|
||
| dev.clean: | ||
| -docker rm $(DOCKER_NAME)-dev | ||
|
|
@@ -68,7 +52,7 @@ dev.run: dev.clean dev.build ## Clean, build and run test image | |
|
|
||
| ## Localization targets | ||
|
|
||
| WORKING_DIR := done | ||
| WORKING_DIR := src/done | ||
| EXTRACT_DIR := $(WORKING_DIR)/conf/locale/en/LC_MESSAGES | ||
| EXTRACTED_DJANGO := $(EXTRACT_DIR)/django-partial.po | ||
| EXTRACTED_TEXT := $(EXTRACT_DIR)/django.po | ||
|
|
||
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.
Set
vcs_release: "false"to match the sample-plugin standard