diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f630e48..dbf1aad6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,40 +4,39 @@ on: [push, pull_request] jobs: test: - runs-on: ubuntu-latest strategy: matrix: - python_version: ['3.11', '3.12', '3.13'] + python_version: ["3.11", "3.12", "3.13"] steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python_version }} - - name: Setup Graphviz - uses: ts-graphviz/setup-graphviz@v2 - - name: Install uv - uses: yezz123/setup-uv@v4 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install hatch - hatch env create - - name: Lint and typecheck - run: | - hatch run lint-check - - name: Test - run: | - hatch run test-cov-xml - - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true - verbose: true + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python_version }} + - name: Setup Graphviz + uses: ts-graphviz/setup-graphviz@v2 + - name: Install uv + uses: yezz123/setup-uv@v4 + - name: Install dependencies + run: | + uv sync --all-extras + - name: Lint and typecheck + run: | + uv run ruff check . + uv run ruff format --check . + uv run mypy mknodes/ + - name: Test + run: | + pytest --cov-report=xml + - uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + verbose: true release: runs-on: ubuntu-latest @@ -48,27 +47,29 @@ jobs: id-token: write contents: write steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: Install dependencies - shell: bash - run: | - python -m pip install --upgrade pip - pip install hatch - - name: Build and publish on PyPI - env: - HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }} - HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }} - run: | - hatch build - hatch publish - - name: Create release - uses: ncipollo/release-action@v1 - with: - draft: true - body: ${{ github.event.head_commit.message }} - artifacts: dist/*.whl,dist/*.tar.gz - token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install uv + uses: yezz123/setup-uv@v4 + - name: Install dependencies + shell: bash + run: | + python -m pip install --upgrade pip + pip install hatch + - name: Build and publish on PyPI + env: + HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }} + HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }} + run: | + hatch build + hatch publish + - name: Create release + uses: ncipollo/release-action@v1 + with: + draft: true + body: ${{ github.event.head_commit.message }} + artifacts: dist/*.whl,dist/*.tar.gz + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 341d3839..889951c9 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -19,15 +19,15 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.12" + - name: Install uv + uses: yezz123/setup-uv@v4 - name: Setup Graphviz uses: ts-graphviz/setup-graphviz@v2 - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install hatch - hatch env create + uv sync --all-extras - name: Run benchmarks uses: CodSpeedHQ/action@v3 with: token: ${{ secrets.CODSPEED_TOKEN }} - run: "hatch run pytest benchmarks/ --codspeed" + run: "uv run pytest benchmarks/ --codspeed" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 7a362745..987ce664 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -23,30 +23,27 @@ defaults: jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: Setup Graphviz - uses: ts-graphviz/setup-graphviz@v2 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install hatch - hatch env create - - name: Build - run: hatch run mkdocs build -v - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ./site + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Setup Graphviz + uses: ts-graphviz/setup-graphviz@v2 + - name: Install dependencies + run: | + uv sync --all-extras + - name: Build + run: uv run mkdocs build -v + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: ./site deploy: environment: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9da5be7e..e24a9f3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,48 +1,48 @@ default_language_version: - python: python3.12 + python: python3.12 default_stages: [pre-commit] repos: -- repo: local - hooks: - - id: pytest-check - name: pytest-check - entry: hatch run test - language: system - # stages: [push] - types: [python] - pass_filenames: false - always_run: true -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - # - id: trailing-whitespace - # - id: check-ast - - id: check-case-conflict - - id: check-docstring-first - - id: check-merge-conflict - # - id: check-yaml - - id: check-toml - - id: check-json - - id: detect-private-key - - id: forbid-new-submodules - # - id: check-added-large-files -# https://pre-commit.com/hooks.html -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 - hooks: - - id: mypy - # args: [--ignore-missing-imports] - additional_dependencies: [] + - repo: local + hooks: + - id: pytest-check + name: pytest-check + entry: uv run pytest + language: system + # stages: [push] + types: [python] + pass_filenames: false + always_run: true + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + # - id: trailing-whitespace + # - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + # - id: check-yaml + - id: check-toml + - id: check-json + - id: detect-private-key + - id: forbid-new-submodules + # - id: check-added-large-files + # https://pre-commit.com/hooks.html + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.11.2 + hooks: + - id: mypy + # args: [--ignore-missing-imports] + additional_dependencies: [] -- repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.6.9 - hooks: - - id: ruff - - id: ruff-format + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.6.9 + hooks: + - id: ruff + - id: ruff-format -- repo: https://github.com/commitizen-tools/commitizen - rev: v3.29.1 - hooks: - - id: commitizen - stages: [commit-msg] - additional_dependencies: [typing-extensions] + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.29.1 + hooks: + - id: commitizen + stages: [commit-msg] + additional_dependencies: [typing-extensions] diff --git a/duties.py b/duties.py index 082c14c2..d256916d 100644 --- a/duties.py +++ b/duties.py @@ -1,35 +1,27 @@ from __future__ import annotations -import json - from duty import duty -ENV_PREFIX = "hatch run " - -PARAMS = ["--disable-pip-version-check", "--outdated", "--format=json"] -UPDATE_CMD = f"""{ENV_PREFIX}python -m pip list {" ".join(PARAMS)}""" - - @duty(capture=False) def build(ctx, *args: str): """Build a MkNodes page.""" args_str = " " + " ".join(args) if args else "" - ctx.run(f"{ENV_PREFIX}mknodes build{args_str}") + ctx.run(f"uv run mknodes build{args_str}") @duty(capture=False) def serve(ctx, *args: str): """Serve a MkNodes page.""" args_str = " " + " ".join(args) if args else "" - ctx.run(f"{ENV_PREFIX}mknodes serve{args_str}") + ctx.run(f"uv run mknodes serve{args_str}") @duty(capture=False) def test(ctx, *args: str): """Serve a MkNodes page.""" args_str = " " + " ".join(args) if args else "" - ctx.run(f"{ENV_PREFIX}pytest{args_str}") + ctx.run(f"uv run pytest{args_str}") @duty(capture=False) @@ -38,38 +30,33 @@ def clean(ctx): ctx.run("git clean -dfX") -@duty -def update(ctx, *args: str): +@duty(capture=False) +def update(ctx): """Update all environment packages using pip directly.""" - args_str = " " + " ".join(args) if args else "" - reqs = ctx.run(UPDATE_CMD + args_str) - packages = [x["name"] for x in json.loads(reqs)] - if packages: - pkgs = " ".join(packages) - print(f"Packages to update: {pkgs}") - ctx.run(f"{ENV_PREFIX}python -m pip install -U {pkgs}{args_str}", capture=False) - else: - print("No packages to update!") - ctx.run(f"{ENV_PREFIX}python -m pip install -e .", capture=False) + ctx.run("uv sync --all-extras") @duty(capture=False) def lint(ctx): - """Update all environment packages using pip directly.""" - ctx.run(f"{ENV_PREFIX}lint") + """Lint and fix the code.""" + ctx.run("uv run ruff check --fix .") + ctx.run("uv run ruff format .") + ctx.run("uv run mypy mknodes/") @duty(capture=False) def lint_check(ctx): - """Update all environment packages using pip directly.""" - ctx.run(f"{ENV_PREFIX}lint-check") + """Lint the code.""" + ctx.run("uv run ruff check .") + ctx.run("uv run ruff format --check .") + ctx.run("uv run mypy mknodes/") @duty(capture=False) def profile(ctx, *args: str): """Run generating the docs using pyinstrument.""" args_str = " " + " ".join(args) if args else "" - ctx.run(f"{ENV_PREFIX}pyinstrument mknodes/manual/root.py{args_str}") + ctx.run(f"uv run pyinstrument mknodes/manual/root.py{args_str}") @duty(capture=False)