Skip to content

[CI] Switch to uv and ruff #466

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Setup Python Environment"
description: "Set up Python environment for the given Python version"

inputs:
python-version:
description: "Python version to use"
required: true
default: "3.12"
uv-version:
description: "uv version to use"
required: true
default: "0.6.9"

runs:
using: "composite"
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{inputs.python-version}}

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: ${{inputs.uv-version}}
enable-cache: "true"
cache-suffix: ${{matrix.python-version}}

- name: Install Python dependencies
run: uv sync --frozen --all-extras
shell: bash
97 changes: 10 additions & 87 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,27 @@
name: Release


# Most parts are borrowed from https://github.com/pola-rs/polars/blob/main/.github/workflows/release-python.yml


on:
workflow_dispatch:
inputs:
# Latest commit to include with the release. If omitted, use the latest commit on the main branch.
# Latest commit to include with the release.
# If omitted, use the latest commit on the main branch.
sha:
description: Commit SHA
type: string
# Create the sdist and build the wheels, but do not publish to PyPI / GitHub.
# Create the sdist and build the wheels, but do not publish to PyPI/GitHub.
dry-run:
description: Dry run
type: boolean
default: false
env:
PYTHON_VERSION: '3.11'

defaults:
run:
shell: bash

jobs:
create-sdist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Create source distribution
run: python setup.py sdist

- name: Test sdist
run: |
pip install --force-reinstall --verbose dist/*.tar.gz
python -c 'import kloppy'

- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: sdist-kloppy
path: dist/*.tar.gz

build-wheel:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install wheel
run: pip install wheel

- name: Build wheel
run: python setup.py bdist_wheel

- name: Test wheel
run: |
pip install --force-reinstall --verbose dist/*.whl
python -c 'import kloppy'

- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-kloppy
path: dist/*.whl

publish-to-pypi:
needs: [create-sdist, build-wheel]
environment:
name: release-python
url: https://pypi.org/project/kloppy
publish:
environment: release # needed for PyPI OIDC
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- name: Download sdists and wheels
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true

- name: Publish to PyPI
if: inputs.dry-run == false
uses: pypa/gh-action-pypi-publish@release/v1
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
verbose: true
version: "0.5.14"
- run: uv build
- uses: pypa/gh-action-pypi-publish@release/v1
65 changes: 40 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
name: Python Package Linux
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- master
- master

jobs:
build:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{hashFiles('.pre-commit-config.yaml')}}

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Run pre-commit
run: uv run pre-commit run -a --show-diff-on-failure

- name: Check lock file consistency
run: uv sync --locked

tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
fail-fast: false
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[test]"
- name: Code formatting
run: |
pip install black==22.3.0
black --check .
- name: Test with pytest
if: '!cancelled()'
run: |
pytest --color=yes
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
python-version: ${{matrix.python-version}}

- name: Run tests
run: uv run python -m pytest kloppy/tests
121 changes: 117 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,119 @@
exclude: |
(?x)^(
docs/site/.*| # Exclude mkdocs compiled files
\.history/.*| # Exclude history files
.*cache.*/.*| # Exclude cache directories
.*venv.*/.*| # Exclude virtual environment directories
)$
fail_fast: true
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
# --------------------------- 🔍 Code Quality Tools -------------------------- #

### Python Tools ###
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.11
hooks:
- id: black
language_version: python3
- id: ruff-format
name: "🐍 python · Format with Ruff"
- id: ruff
name: "🐍 python · Lint and perform safe auto-fixes with Ruff"
args: [--fix]

# - repo: https://github.com/RobertCraigie/pyright-python
# rev: v1.1.391
# hooks:
# - id: pyright
# name: "🐍 python · Check types"

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.24.1
hooks:
- id: validate-pyproject
name: "🐍 python · Validate pyproject.toml"
additional_dependencies: ["validate-pyproject-schema-store[all]"]

### Data & Config Validation ###
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.33.0
hooks:
- id: check-github-workflows
name: "🐙 github-actions · Validate gh workflow files"
args: ["--verbose"]

### Markdown ###
- repo: https://github.com/hukkin/mdformat
rev: 0.7.22
hooks:
- id: mdformat
name: "📝 markdown · Format markdown"
additional_dependencies:
- mdformat-gfm
- mdformat-ruff
- mdformat-frontmatter
- mdformat-mkdocs
- ruff

# - repo: https://github.com/markdownlint/markdownlint
# rev: v0.12.0
# hooks:
# - id: markdownlint
# name: "📝 markdown · Lint markdown"

### Notebooks ###
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.1
hooks:
- id: nbqa
entry: nbqa mdformat
name: "📓 notebook · Format markdown cells"
args: ["--nbqa-md"]
types: [jupyter]
additional_dependencies:
- mdformat
- mdformat-gfm
- mdformat-ruff
- mdformat-frontmatter
- ruff

### Additional File Types ###
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
name: "✨ misc-files · Format misc files"
types_or: [yaml, html, css, javascript, toml]
additional_dependencies:
- [email protected]

# ----------------------------- ⚡️ uv Build Tools ---------------------------- #

# This helps ensure cross-compatibility with people who don't wish to use uv
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.7.8
hooks:
- id: uv-sync
name: "⚡️ uv · Sync dependencies with uv"
- id: uv-lock
name: "⚡️ uv · Update dependency lockfile"
- id: uv-export
name: "⚡️ uv · Export dependencies to requirements.txt"
args: ["--no-hashes", --output-file, requirements-dev.txt]

# ---------------------------------------------------------------------------- #
# 🧪 Tests (Local) #
# ---------------------------------------------------------------------------- #

- repo: local
hooks:
- id: pytest-collect
name: 🧪 test · Validate test formatting
entry: ./.venv/bin/pytest kloppy/tests
language: system
types: [python]
args: ["--collect-only"]
pass_filenames: false
always_run: true
Loading
Loading