Skip to content
Merged
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
57 changes: 57 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Ruff

permissions:
contents: read

on:
push:
branches:
- '**'

pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
lint:
name: ruff check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Determine changed Python files
id: changed
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
base="origin/${{ github.event.pull_request.base.ref }}"
else
base="${{ github.event.before }}"
# New branch or force-push: 'before' may not exist locally (or be all-zeros).
if ! git cat-file -e "$base" 2>/dev/null; then
base="HEAD^"
git cat-file -e "$base" 2>/dev/null || base=""
fi
fi

if [ -z "$base" ]; then
files=$(git ls-files '*.py' | xargs)
else
files=$(git diff --name-only --diff-filter=ACMR "$base"...HEAD -- '*.py' | xargs)
fi

echo "files=$files" >> "$GITHUB_OUTPUT"

- name: Install uv
if: steps.changed.outputs.files != ''
uses: astral-sh/setup-uv@v7
with:
version: "latest"

- name: Run ruff
if: steps.changed.outputs.files != ''
run: |
uvx ruff@0.16.1 check --config lint.per-file-ignores={} --output-format=github ${{ steps.changed.outputs.files }}
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default_install_hook_types: [pre-commit, pre-push]

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.1
hooks:
- id: ruff
args: [--config, "lint.per-file-ignores={}"]
stages: [pre-push]

- repo: local
hooks:
- id: pytest
name: pytest
entry: uv run pytest
language: system
pass_filenames: false
always_run: true
stages: [pre-push]
3 changes: 0 additions & 3 deletions chainladder/tails/tests/test_constant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import chainladder as cl
import numpy as np
from chainladder.utils.cupy import cp


def test_constant_balances(qtr):
xp = qtr.get_array_module()
Expand Down
63 changes: 62 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ Repository = "https://github.com/casact/chainladder-python"
dev = [
"lxml",
"pytest",
"pytest-cov",
"pytest-cov",
"pytest-xdist",
"jinja2",
"ipython",
"ipykernel",
"pyright",
"ruff",
"pre-commit",
]
docs = [
"sphinx",
Expand Down Expand Up @@ -95,6 +97,65 @@ all = [
testpaths = ["chainladder", "docs/_ext"]
pythonpath = ["docs/_ext"]

[tool.ruff]
target-version = "py310"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F"]
Comment thread
cursor[bot] marked this conversation as resolved.

# Grandfathered violations that predate enabling this rule set. New and
# newly-touched code is still held to the full ruleset above; these files
# are exempted only from the specific codes they already violated so the
# check can be required without blocking unrelated PRs. Remove entries as
# files are cleaned up.
[tool.ruff.lint.per-file-ignores]
"chainladder/adjustments/bootstrap.py" = ["E721", "E722", "F841"]
"chainladder/adjustments/disposal.py" = ["F401"]
"chainladder/adjustments/tests/test_berqsherm.py" = ["F841"]
"chainladder/adjustments/tests/test_disposal.py" = ["F841"]
"chainladder/adjustments/trend.py" = ["F401"]
"chainladder/core/base.py" = ["E721"]
"chainladder/core/common.py" = ["F401"]
"chainladder/core/correlation.py" = ["E741"]
"chainladder/core/dunders.py" = ["E721", "E722", "F841"]
"chainladder/core/io.py" = ["E731"]
"chainladder/core/pandas.py" = ["E721", "F841"]
"chainladder/core/slice.py" = ["E712", "E721", "E741"]
"chainladder/core/tests/rtest_correlation.py" = ["E722", "F821"]
"chainladder/core/tests/test_arithmetic.py" = ["E711"]
"chainladder/core/tests/test_display.py" = ["E722"]
"chainladder/core/tests/test_grain.py" = ["F401", "F841"]
"chainladder/core/tests/test_triangle.py" = ["E712", "E721", "F811", "F841"]
"chainladder/core/triangle.py" = ["E712", "E721", "E731", "F401", "F841"]
"chainladder/development/base.py" = ["E712", "F401", "F841"]
"chainladder/development/clark.py" = ["E721", "E731"]
"chainladder/development/constant.py" = ["E712"]
"chainladder/development/glm.py" = ["F401"]
"chainladder/development/incremental.py" = ["E721", "F401"]
"chainladder/development/learning.py" = ["E711", "F401"]
"chainladder/development/tests/rtest_clark.py" = ["E722"]
"chainladder/development/tests/rtest_development.py" = ["E722", "F401"]
"chainladder/development/tests/rtest_munich.py" = ["E722", "F401"]
"chainladder/development/tests/test_constant.py" = ["F841"]
"chainladder/development/tests/test_development.py" = ["E722"]
"chainladder/development/tests/test_incremental.py" = ["F841"]
"chainladder/development/tests/test_munich.py" = ["F841"]
"chainladder/methods/base.py" = ["F401"]
"chainladder/methods/capecod.py" = ["F401"]
"chainladder/methods/mack.py" = ["F401"]
"chainladder/methods/tests/rtest_mack.py" = ["E722", "F401"]
"chainladder/tails/bondy.py" = ["F401"]
"chainladder/tails/curve.py" = ["E721", "F401"]
"chainladder/tails/tests/rtest_exponential.py" = ["E722", "F401"]
"chainladder/tails/tests/test_constant.py" = ["F401"]
"chainladder/utils/cupy.py" = ["E722", "F401"]
"chainladder/utils/dask.py" = ["E722", "E741"]
"chainladder/utils/sparse.py" = ["E721"]
"chainladder/utils/tests/test_utilities.py" = ["E712", "E741", "F811", "F841"]
"chainladder/utils/triangle_weight.py" = ["F401"]
"chainladder/utils/utility_functions.py" = ["E721", "F401"]
"chainladder/workflow/tests/test_voting.py" = ["E731"]

[tool.setuptools]
include-package-data = true

Expand Down
Loading
Loading