diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..bca3588 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,35 @@ +name: Pre-Commit + +on: + workflow_call: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: write + pull-requests: write + +jobs: + pre-commit: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v6.0.1 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.14" + + - name: Add uv + uses: astral-sh/setup-uv@v7 + + - name: Install dependencies + run: uv sync --dev + + - name: Run pre-commit + uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c033965 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,73 @@ +name: PyTest +on: + workflow_call: + workflow_dispatch: + push: + branches: + - main + pull_request: + paths: + - ".github/workflows/test.yml" + - "render_engine_api/**" + - "tests/**" + - "pyproject.toml" + - "requirements.txt" + +jobs: + gen-coverage-badge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v7 + with: + python-version: "3.14" + enable-cache: true + + - name: run coverage and generate cov-report + run: | + uv run --dev pytest --cov-report xml + - name: genbadge coverage + run: | + uvx --with "genbadge[coverage]" genbadge coverage -i coverage.xml + - name: Commit Badge + uses: stefanzweifel/git-auto-commit-action@v7 + with: + commit_message: Update coverage badge [skip ci] + file_pattern: coverage.svg + + test-against-python-matrix: + # Only test all the supported versions when a pull request is made or the workflow is called + if: ${{github.event_name == 'workflow_call'}} || ${{github.event_name == 'pull_request'}} + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + fail-fast: true + steps: + - uses: actions/checkout@v6.0.1 + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + python-version: ${{ matrix.python-version }} + enable-cache: true # caching dependencies + - name: Run tests + run: | + uv run --dev pytest tests + + test-against-latest-os: + # Always run against the latest version on both Windows, Linux, MacOS + if: github.event.pull_request.user.login != 'dependabot[bot]' + strategy: + matrix: + os: [windows-latest, macos-latest] + fail-fast: true + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v6.0.1 + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + python-version: "3.14" + enable-cache: true # caching dependencies + - name: run tests + run: uv run --dev pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4b541b..dc2be5c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,34 +1,34 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.15.1 - hooks: - # Run the linter. - - id: ruff-check - args: [ --fix ] - # Run the formatter. - - id: ruff-format -- repo: https://github.com/allganize/ty-pre-commit - # Ty version. - rev: v0.0.17 - hooks: - # Run the type checker. - - id: ty-check -- repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: v0.6.0 - hooks: - - id: markdownlint-cli2 -- repo: local - hooks: - - id: deptry - name: deptry - entry: uv run deptry . - language: system - always_run: true - pass_filenames: false + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.15.4 + hooks: + # Run the linter. + - id: ruff-check + args: [--fix] + # Run the formatter. + - id: ruff-format + - repo: https://github.com/allganize/ty-pre-commit + # Ty version. + rev: v0.0.20 + hooks: + # Run the type checker. + - id: ty-check + - repo: https://github.com/DavidAnson/markdownlint-cli2 + rev: v0.21.0 + hooks: + - id: markdownlint-cli2 + - repo: local + hooks: + - id: deptry + name: deptry + entry: uv run deptry . + language: system + always_run: true + pass_filenames: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..716a701 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# Contributing to the Render Engine Projects + +Render Engine API is a unifying API layer for managing and working with [render-engine][render-engine]. +The [CLI][cli], [TUI][tui], and custom tools can use this module as a shared API layer. Please refer to +the main [CONTRIBUTING.md](https://github.com/render-engine/render-engine/blob/main/CONTRIBUTING.md) +for more details on how to contribute. + +## Render Engine API Specific Topics + +Render Engine API is a `uv` based project. For more information on installing `uv` and using it +please see the [uv documentation](https://docs.astral.sh/uv/#installation). To get started, fork +this repository and check out your fork. + +```shell +git clone +``` + +Once you have checked out the repository, run `uv sync --dev` and then activate the `venv` that was +created: + +```shell +uv sync --dev +source .venv/bin/activate +``` + +Once you have done this you will be in the virtual environment and ready to work. It is recommended +that you do a local, editable install of the API in your virtual environment so that you can easily +work with the changes you have made. + +```shell +uv pip install -e . +``` + +This will allow you to test your changes locally. + +[render-engine]: https://github.com/render-engine/render-engine +[cli]: https://github.com/render-engine/render-engine-cli +[tui]: https://github.com/render-engine/render-engine-tui diff --git a/justfile b/justfile new file mode 100644 index 0000000..d8e21a2 --- /dev/null +++ b/justfile @@ -0,0 +1,81 @@ +# Render Engine API - Just recipes +# Run tasks with: just + +DEFAULT_PYTHON_VERSION := "3.14" + +# Default recipe to display available commands +default: + @just --list + +# Sync dependencies using uv +sync: + uv sync --dev + +# Run pytest +test *FLAGS='': + pytest {{ DEFAULT_PYTHON_VERSION }} {{ FLAGS }} + +# Install pre-commit hooks +pre-commit-install: + uvx pre-commit install + +# Run pre-commit on all files +pre-commit: + uvx pre-commit run --all-files + +# Run pre-commit on staged files (default git behavior) +pre-commit-run: + uvx pre-commit run + +# Update pre-commit hook versions +pre-commit-update: + uvx pre-commit autoupdate + +# Run tests in arbitrary Python version. +pytest VERSION *FLAGS='': + uv run -p {{ VERSION }} --dev pytest {{ FLAGS }} + +# Run pytest with coverage report (defaults to XML) +test-cov-report REPORT='xml': + uv run --dev pytest --cov-report={{ REPORT }} + +# Run all nox sessions +nox: + uvx nox + +# Run ruff linter without fixing +lint DIRECTORY='.': + uvx ruff check {{ DIRECTORY }} + +# Run ruff linter with auto-fix +lint-fix DIRECTORY='.': + uvx ruff check --fix {{ DIRECTORY }} + +# Run ruff formatter as check +format DIRECTORY='.': + uvx ruff format --check {{ DIRECTORY }} + +# Run ruff formatter and fix issues +format-fix DIRECTORY='.': + uvx ruff format --check {{ DIRECTORY }} + +ruff: lint format + +# Run both linter and formatter, fixing issues. +ruff-fix DIRECTORY='.': + @# Prefacing with `-` to ignore any errors that might be fixed by formatting. + -uvx ruff check --fix {{ DIRECTORY }} + uvx ruff format {{ DIRECTORY }} + uvx ruff check {{ DIRECTORY }} + @echo "\nEverything looks good!" + +# Run ty type checker +ty PATH='src': + uv run ty check {{ PATH }} # For the moment we have way too many issues in ty so not having it fail. + +# Generate coverage badge +badge: (test-cov-report 'xml') + uvx --with "genbadge[coverage]" genbadge coverage -i coverage.xml + +# Run full CI workflow (sync, lint, test, badge) +ci: sync nox ruff ty badge