Skip to content

Commit

Permalink
Add py.typed file and fix mypy, improve pre-commit configuration (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored May 22, 2024
1 parent 3378585 commit be17763
Show file tree
Hide file tree
Showing 16 changed files with 2,860 additions and 3,715 deletions.
2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ changelog:
- ci
- title: 🤷🏻 Other changes
labels:
- '*'
- "*"
2 changes: 1 addition & 1 deletion .github/scripts/read_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

# first get line with version_info, then extract thing in parantheses, then replace ", " with "."
# first get line with version_info, then extract thing in parentheses, then replace ", " with "."
grep "version_info =" | sed "s/^.*(\([^()]*\)).*$/\1/" | sed "s/, /./g"
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
cache-name: benchmark-model-cache
with:
path: examples/benchmark_models
key: models-${{ hashFiles('benchmark.py', '.github/workflows/benchmark.yml') }}
key: models-${{ hashFiles('examples/benchmark.py', '.github/workflows/benchmark.yml') }}
- name: Run benchmark
run: |
python benchmark.py
python examples/benchmark.py
echo "_(benchmark **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_" >> result.md
cat benchmark.md >> result.md
shell: pixi run bash {0}
shell: pixi run bash -e {0}
- name: Comment on PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
Expand Down
17 changes: 3 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,8 @@ jobs:
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/[email protected]
- uses: quantco/pre-commit-conda@v1
with:
python-version: '3.8'

lint-workflow-files:
name: "Lint workflow files"
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
# https://github.com/rhysd/actionlint/blob/main/docs/usage.md#use-actionlint-on-github-actions
- name: Download actionlint
id: get_actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
- name: Check workflow files
run: ${{ steps.get_actionlint.outputs.executable }} -color
python-version: "3.8"
53 changes: 39 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
exclude: ^\.copier-answers\.yml$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
- repo: local
hooks:
- id: check-yaml
# ruff
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
# mypy
- id: mypy
name: mypy
entry: pixi run -e default mypy
language: system
types: [python]
require_serial: true
# pre-commit-hooks
- id: trailing-whitespace-fixer
name: trailing-whitespace-fixer
entry: pixi run -e lint trailing-whitespace-fixer
language: system
types: [text]
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-toml
- repo: https://github.com/quantco/pre-commit-mirrors-ruff
rev: 0.4.3
hooks:
- id: ruff-conda
- id: ruff-format-conda
- repo: https://github.com/quantco/pre-commit-mirrors-mypy
rev: 1.10.0
hooks:
- id: mypy-conda
name: end-of-file-fixer
entry: pixi run -e lint end-of-file-fixer
language: system
types: [text]
# typos
- id: typos
name: typos
entry: pixi run -e lint typos --force-exclude
language: system
types: [text]
require_serial: true
4 changes: 2 additions & 2 deletions benchmark.py → examples/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from slim_trees import dumps_lgbm_compressed, dumps_sklearn_compressed
from slim_trees.pickling import dumps_compressed, get_pickled_size, loads_compressed

MODELS_PATH = "examples/benchmark_models"
MODELS_PATH = Path("examples/benchmark_models")


def load_model(model_name: str, generate: Callable) -> Any:
model_path = Path(f"{MODELS_PATH}/{model_name}.pkl")
model_path = Path(MODELS_PATH / f"{model_name}.pkl")

if model_path.exists():
print(f"Loading model `{model_name}.pkl` from disk...")
Expand Down
4 changes: 2 additions & 2 deletions examples/pickle_lgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import lightgbm as lgb
from lightgbm import Booster
from utils import (

from examples.utils import (
evaluate_compression_performance,
evaluate_prediction_difference,
generate_dataset,
)

from slim_trees import dump_lgbm_compressed
from slim_trees.lgbm_booster import dump
from slim_trees.pickling import load_compressed
Expand Down
4 changes: 2 additions & 2 deletions examples/pickle_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import tempfile

from sklearn.ensemble import RandomForestRegressor
from utils import (

from examples.utils import (
evaluate_compression_performance,
evaluate_prediction_difference,
generate_dataset,
)

from slim_trees import dump_sklearn_compressed
from slim_trees.pickling import load_compressed
from slim_trees.sklearn_tree import dump
Expand Down
File renamed without changes.
Loading

0 comments on commit be17763

Please sign in to comment.