Skip to content

Commit

Permalink
build: add a Makefile that uses uv
Browse files Browse the repository at this point in the history
Also adjusts the tox file and the github workflows
  • Loading branch information
lengau committed Sep 19, 2024
1 parent 4525894 commit cbba4d7
Show file tree
Hide file tree
Showing 7 changed files with 2,064 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- [ ] Have you followed the guidelines for contributing?
- [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you successfully run `tox`?
- [ ] Have you successfully run `make lint && make test`?

-----
22 changes: 12 additions & 10 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ jobs:
sphinx:
runs-on: ubuntu-latest
steps:
- name: Start UV install
run: |
sudo snap install --classic astral-uv --no-wait
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Tox
run: pip install tox
- name: Lint documentation
run: tox run --colored yes -e lint-docs
- name: Build documentation
run: tox run --colored yes -e build-docs
- name: Finish UV install
run: |
sudo snap watch --last=install
- name: Lint docs
run: |
make lint-docs
- name: Build docs
run: |
make docs
- name: Upload documentation
uses: actions/upload-artifact@v4
with:
Expand Down
127 changes: 74 additions & 53 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,105 +17,126 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install tools
run: |
make setup
- name: Run Linters
run: |
make -k lint
- name: conventional commits
uses: webiny/[email protected]
with:
allowed-commit-types: "build,chore,ci,docs,feat,fix,perf,refactor,style,test"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Configure environment
run: |
echo "::group::Begin snap install"
echo "Installing snaps in the background while running apt and pip..."
sudo snap install --no-wait --classic pyright
sudo snap install --no-wait codespell shellcheck ruff
echo "::endgroup::"
echo "::group::pip install"
python -m pip install tox
echo "::endgroup::"
echo "::group::Create virtual environments for linting processes."
tox run --colored yes -m lint --notest
echo "::endgroup::"
echo "::group::Wait for snap to complete"
snap watch --last=install
echo "::endgroup::"
- name: Run Linters
run: tox run --skip-pkg-install --no-list-dependencies --colored yes -m lint
unit:
strategy:
matrix:
platform: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest, macos-latest]
resolution: [highest]
include:
- platform: ubuntu-latest
resolution: lowest
runs-on: ${{ matrix.platform }}
env:
UV_CACHE_DIR: ${{ github.workspace }}/.cache/uv
steps:
- uses: actions/cache@v4
id: cache-uv
with:
path: ${{ env.UV_CACHE_DIR }}
key: ${{ matrix.platform }}-uv-${{ matrix.resolution }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install tools
shell: bash
run: |
make setup
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: |
3.10
3.11
3.12
3.13-dev
cache: 'pip'
- name: Configure environment
- name: Configure venv and test
shell: bash
run: |
echo "::group::pip install"
python -m pip install tox
echo "::endgroup::"
mkdir -p results
- name: Setup Tox environments
run: tox run --colored yes -m tests --notest
- name: Test with tox
run: tox run --skip-pkg-install --no-list-dependencies --result-json results/tox-${{ matrix.platform }}.json --colored yes -m unit-tests
for python_version in 3.10 3.11 3.12 3.13; do
echo "::group::Python $python_version (install)"
uv sync --python=$python_version --reinstall --resolution=${{ matrix.resolution }}
echo "::endgroup::"
echo "::group::Python $python_version (test)"
make test-unit
echo "::endgroup::"
done
env:
PYTEST_ADDOPTS: "--no-header -vv -rN"
- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
directory: ./results/
files: coverage*.xml
name: coverage-unit-${{ matrix.python-version }}-${{ matrix.platform }}
files: .coverage*.xml
- name: Upload test results
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: unit-test-results-${{ matrix.platform }}
path: results/
name: results-unit-${{ matrix.python-version }}-${{ matrix.platform }}-${{ matrix.resolution }}
path: |
./.results.*.xml
./.coverage.*.xml
integration:
strategy:
matrix:
platform: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest, macos-latest]
platform: [ubuntu-latest, windows-latest, macos-latest]
resolution: [highest]
include:
- platform: ubuntu-latest
resolution: lowest
runs-on: ${{ matrix.platform }}
env:
UV_CACHE_DIR: ${{ github.workspace }}/.cache/uv
steps:
- uses: actions/cache@v4
id: cache-uv
with:
path: ${{ env.UV_CACHE_DIR }}
key: ${{ matrix.platform }}-uv-${{ matrix.resolution }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install tools
shell: bash
run: |
make setup
- name: Set up Python
if: ${{ runner.os != 'Linux' }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: |
3.10
3.12
3.13-dev
cache: 'pip'
- name: Configure environment
python-version: "3.10"
- name: Configure venv and test
shell: bash
run: |
echo "::group::pip install"
python -m pip install tox
echo "::group::Sync"
uv sync --reinstall --resolution=${{ matrix.resolution }}
echo "::endgroup::"
echo "::group::Test"
make test-integration
echo "::endgroup::"
mkdir -p results
- name: Setup Tox environments
run: tox run --colored yes -m tests --notest
- name: Test with tox
run: tox run --skip-pkg-install --no-list-dependencies --result-json results/tox-${{ matrix.platform }}.json --colored yes -m integration-tests
env:
PYTEST_ADDOPTS: "--no-header -vv -rN"
- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
name: coverage-integration-${{ matrix.python-version }}-${{ matrix.platform }}
files: .coverage*.xml
- name: Upload test results
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: integration-test-results-${{ matrix.platform }}
path: results/
name: results-integration-${{ matrix.python-version }}-${{ matrix.platform }}-${{ matrix.resolution }}
path: |
./.results.*.xml
./.coverage.*.xml
48 changes: 21 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ help: ## Show this help.
setup: ## Set up a development environment
ifeq ($(OS),Linux)
sudo snap install codespell ruff shellcheck
sudo snap install --classic --beta astral-uv
sudo snap alias astral-uv.uv uv
sudo snap alias astral-uv.uvx uvx
sudo snap install --classic astral-uv
sudo apt-get --yes install libxml2-dev libxslt-dev
else ifeq ($(OS),Windows_NT)
pipx install uv
choco install shellcheck
Expand All @@ -27,41 +26,36 @@ else ifeq ($(OS),Darwin)
brew install shellcheck
endif
ifneq ($(OS),Linux)
uv tool install codespell
uv tool install ruff
uv tool update-shell
uv tool install --upgrade codespell
uv tool install --upgrade ruff
endif
uv tool install --upgrade yamllint
uv tool update-shell

.PHONY: setup-pre-commit
.PHONY: setup-precommit
setup-precommit: ## Set up pre-commit hooks in this repository.
ifeq (, $(shell which pre-commit))
uv tool install pre-commit
endif
pre-commit install
uvx pre-commit install

.PHONY: autoformat
autoformat: format-ruff format-codespell ## Run all automatic formatters

.PHONY: lint
lint: lint-ruff lint-codespell lint-mypy lint-pyright lint-shellcheck lint-yaml lint-docs ## Run all linters
lint: lint-ruff lint-codespell lint-mypy lint-pyright lint-yaml ## Run all linters

.PHONY: test
test: test-unit test-integration ## Run all tests
test: test-unit test-integration ## Run all tests with the default python

.PHONY: docs
docs: ## Build documentation
uv run --extra docs sphinx-build -b html -W docs docs/_build
uv run --frozen --extra docs sphinx-build -b html -W docs docs/_build

.PHONY: docs-auto
docs-auto: ## Build and host docs with sphinx-autobuild
uv run --extra docs sphinx-autobuild -b html --open-browser --port=8080 --watch $(PROJECT) -W docs docs/_build

# Helpful in `help` to split the main targets from things that build
---------------- : ## ----------------
uv run --frozen --extra docs sphinx-autobuild -b html --open-browser --port=8080 --watch $(PROJECT) -W docs docs/_build

.PHONY: format-codespell
format-codespell: ## Fix spelling issues with codespell
uv run codespell --toml pyproject.toml --write-changes $(SOURCES)
codespell --toml pyproject.toml --write-changes $(SOURCES)

.PHONY: format-ruff
format-ruff: ## Automatically format with ruff
Expand All @@ -70,19 +64,19 @@ format-ruff: ## Automatically format with ruff

.PHONY: lint-codespell
lint-codespell: ## Check spelling with codespell
uv run codespell --toml pyproject.toml $(SOURCES)
codespell --toml pyproject.toml $(SOURCES)

.PHONY: lint-docs
lint-docs: ## Lint the documentation
uv run --extra docs sphinx-lint --max-line-length 80 --enable all $(DOCS)
uv run --frozen --extra docs sphinx-lint --enable all $(DOCS)

.PHONY: lint-mypy
lint-mypy: ## Check types with mypy
uv run mypy $(SOURCES)
uv run mypy $(PROJECT)

.PHONY: lint-pyright
lint-pyright: ## Check types with pyright
uv run pyright
uv run pyright $(SOURCES)

.PHONY: lint-ruff
lint-ruff: ## Lint with ruff
Expand All @@ -91,16 +85,16 @@ lint-ruff: ## Lint with ruff

.PHONY: lint-shellcheck
lint-shellcheck:
sh -c 'git ls-files | file --mime-type -Nnf- | grep shellscript | cut -f1 -d: | xargs -r shellcheck'
sh -c 'git ls-files | file --mime-type -Nnf- | grep shellscript | rev | cut -d: -f2- | rev | xargs -r shellcheck'

.PHONY: lint-yaml
lint-yaml: ## Lint YAML files with yamllint
uv run yamllint .
yamllint .

.PHONY: test-unit
test-unit: ## Run unit tests
uv run pytest --cov=$(PROJECT) --cov-config=pyproject.toml --cov-report=xml:.coverage.unit.xml --junit-xml=.results.unit.xml tests/unit
uv run --frozen pytest --cov=$(PACKAGE) --cov-config=pyproject.toml --cov-report=xml:.coverage.unit.xml --junit-xml=.results.unit.xml tests/unit

.PHONY: test-integration
test-integration: ## Run integration tests
uv run pytest --cov=$(PROJECT) --cov-config=pyproject.toml --cov-report=xml:.coverage.integration.xml --junit-xml=.results.integration.xml tests/integration
uv run --frozen pytest --cov=$(PACKAGE) --cov-config=pyproject.toml --cov-report=xml:.coverage.integration.xml --junit-xml=.results.integration.xml tests/integration
Loading

0 comments on commit cbba4d7

Please sign in to comment.