Skip to content

Commit

Permalink
Switch project to uv lockfile (#148)
Browse files Browse the repository at this point in the history
* Add uv lockfile, bump pre-commit hooks

* Remove requirement files

* Switch all actions to uv

Migrated over from lakefs-spec. Everything is as we have it there -
uv installation, running everything via `uv run`, etc.

The mike setup means that the mike action can only be run after a uv setup.

* Add Python version matrix, fix EOF in pre-commit config

* Check out repo to depth 0 in docs job

* Fix Self import for Python >=3.11
  • Loading branch information
nicholasjng authored Oct 10, 2024
1 parent daee527 commit 847d6dd
Show file tree
Hide file tree
Showing 10 changed files with 1,326 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .github/actions/mike-docs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ runs:
if [ "true" = "${{ inputs.push }}" ]; then
MIKE_OPTIONS+=( "--push" )
fi
mike deploy ${{ inputs.version }} ${{ inputs.alias }} "${MIKE_OPTIONS[@]}"
uv run mike deploy ${{ inputs.version }} ${{ inputs.alias }} "${MIKE_OPTIONS[@]}"
shell: bash
91 changes: 34 additions & 57 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,52 @@ on:

jobs:
lint:
name: Run code checks and formatting hooks
runs-on: ubuntu-latest
env:
MYPY_CACHE_DIR: "${{ github.workspace }}/.cache/mypy"
RUFF_CACHE_DIR: "${{ github.workspace }}/.cache/ruff"
PRE_COMMIT_HOME: "${{ github.workspace }}/.cache/pre-commit"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python and dependencies
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
cache-dependency-path: |
requirements-dev.txt
requirements-docs.txt
pyproject.toml
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install -e . --no-deps
- name: Cache pre-commit tools
uses: actions/cache@v4
with:
path: |
${{ env.MYPY_CACHE_DIR }}
${{ env.RUFF_CACHE_DIR }}
${{ env.PRE_COMMIT_HOME }}
key: ${{ hashFiles('requirements-dev.txt', '.pre-commit-config.yaml') }}-linter-cache
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install Python 3.10 interpreter
run: uv python install 3.10
- name: Install the project
run: uv sync --extra dev
- name: Run pre-commit checks
run: pre-commit run --all-files --verbose --show-diff-on-failure
run: uvx pre-commit run --all-files --verbose --show-diff-on-failure
test:
name: Test nnbench on ${{ matrix.os }}
name: Test nnbench on ${{ matrix.os }} on Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ "3.10", 3.11, 3.12 ]
steps:
- uses: actions/checkout@v4
- name: Set up oldest supported Python on ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Run tests on oldest supported Python
run: |
python -m pip install ".[dev]"
pytest
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install the project in developer mode
run: uv sync --extra dev
- name: Execute python tests
run: uv run pytest -s
docs:
name: Publish latest documentation for nnbench
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python and dependencies
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
cache-dependency-path: |
requirements-dev.txt
requirements-docs.txt
pyproject.toml
- name: Install dependencies
run: |
pip install -r requirements-dev.txt -r requirements-docs.txt
pip install -e . --no-deps
- uses: ./.github/actions/mike-docs
with:
version: latest
pre_release: true # include pre-release notification banner
push: ${{ github.ref == 'refs/heads/main' }} # build always, publish on 'main' only to prevent version clutter
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install Python 3.11 interpreter
run: uv python install 3.11
- name: Install the project
run: uv sync --extra docs
- name: Build documentation using mike
uses: ./.github/actions/mike-docs
with:
version: latest
pre_release: true # include pre-release notification banner
push: ${{ github.ref == 'refs/heads/main' }} # build always, publish on 'main' only to prevent version clutter
22 changes: 7 additions & 15 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,14 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python and dependencies
uses: actions/setup-python@v4
with:
python-version: 3.11
cache: pip
cache-dependency-path: |
requirements-dev.txt
requirements-docs.txt
pyproject.toml
- name: Install dependencies
run: |
pip install -r requirements-dev.txt -r requirements-docs.txt
pip install -e . --no-deps
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install Python 3.11 interpreter
run: uv python install 3.11
- name: Install the project
run: uv sync --all-extras
- name: Build and check
run: |
python -m build
run: uv run -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
24 changes: 3 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,7 @@ repos:
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.17
rev: 0.4.20
hooks:
- id: pip-compile
name: pip-compile requirements-dev.txt
args:
- --no-annotate
- --no-strip-extras
- --python-version=3.10
- --extra=dev
- --output-file=requirements-dev.txt
- pyproject.toml
files: ^(pyproject\.toml|requirements-dev\.txt)$
- id: pip-compile
name: pip-compile requirements-docs.txt
args:
- --no-annotate
- --no-strip-extras
- --python-version=3.10
- --extra=docs
- --output-file=requirements-docs.txt
- pyproject.toml
files: ^(pyproject\.toml|requirements-docs\.txt)$
- id: uv-lock
name: Lock project dependencies
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,6 @@ ignore = [
# Ignore unused imports in all `__init__.py` files
"__init__.py" = ["F401"]

[tool.bandit]
exclude_dirs = ["examples", "tests"]
skips = ["B101", "B404"]

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "DEBUG"

[tool.pydoclint]
style = 'numpy'
exclude = '\.git|venv'
27 changes: 0 additions & 27 deletions requirements-dev.txt

This file was deleted.

64 changes: 0 additions & 64 deletions requirements-docs.txt

This file was deleted.

6 changes: 5 additions & 1 deletion src/nnbench/types/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Type interfaces for benchmarks and benchmark collections."""

import copy
import sys
from collections.abc import Callable, Mapping
from dataclasses import dataclass, field
from types import MappingProxyType
from typing import Any, Literal

from typing_extensions import Self
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from nnbench.context import Context
from nnbench.types.interface import Interface
Expand Down
6 changes: 5 additions & 1 deletion src/nnbench/types/interface.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Type interface for the function interface"""

import inspect
import sys
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, TypeVar

from typing_extensions import Self
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

T = TypeVar("T")
Variable = tuple[str, type, Any]
Expand Down
Loading

0 comments on commit 847d6dd

Please sign in to comment.