Skip to content

Commit 9b34fdc

Browse files
committed
refactor: consolidate scripts and fix type checking
- Remove run-ci-checks.sh and run-act.sh scripts - Enhance Makefile with all shell script functionality * Add colored output for better readability * Add Docker check before act commands * Add test-quick target for minimal output * Improve error messages and user feedback - Fix type checking for LightGBM * Add lightgbm type stubs in typings/lightgbm/ * Configure ty to ignore possibly-missing-import for lgb_constructor.py * Fix import to use LGBMClassifier directly - Update CHANGELOG.md with v0.2.7a1 alpha release notes * Document LightGBM alpha support * Document Makefile consolidation * Include installation instructions All development tasks now available via make: - make ci-check (replaces ./run-ci-checks.sh) - make act-local (replaces ./run-act.sh local) - make act-lint, act-typecheck, act-test, act-list
1 parent 8e66221 commit 9b34fdc

12 files changed

Lines changed: 187 additions & 167 deletions

File tree

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Changelog
22

3+
## [0.2.7a1] - 2025-11-08 (Alpha)
4+
5+
### Added
6+
- **LightGBM Support (Alpha)**: Initial implementation of `LGBScorecardConstructor` for LightGBM models
7+
- Implemented `extract_leaf_weights()` method for parsing LightGBM tree structure
8+
- Implemented `get_leafs()` method for leaf indices and margins prediction
9+
- Added comprehensive test suite with 9 tests (all passing)
10+
- Created example demonstrating implemented functionality
11+
- **Status**: Alpha release - 2 of 5 core methods implemented
12+
- **Community**: Reference implementation for issue #7 (@RektPunk)
13+
14+
### Changed
15+
- **Development Workflow**: Consolidated shell scripts into enhanced Makefile
16+
- Removed `run-ci-checks.sh` and `run-act.sh` scripts
17+
- Enhanced Makefile with colored output and Docker checks
18+
- Added new targets: `make ci-check`, `make act-local`, `make test-quick`
19+
- Single entry point for all development tasks
20+
21+
### Fixed
22+
- **CI/CD**: Added missing `lightgbm>=4.0.0,<5.0.0` dependency
23+
- **Type Checking**: Added LightGBM type stubs and configured ignore rules
24+
- **GitHub Actions**: Fixed act configuration by removing unsupported flags
25+
26+
### Technical Details
27+
- LightGBM constructor follows same pattern as XGBoost/CatBoost implementations
28+
- Column naming unified to `XAddEvidence` for consistency across all constructors
29+
- Test suite expanded from 95 to 104 tests
30+
- All tests passing in local and CI environments
31+
32+
### Installation
33+
```bash
34+
# Install alpha release
35+
pip install git+https://github.com/xRiskLab/xBooster.git@v0.2.7a1
36+
```
37+
338
## [0.2.7] - 2025-11-06
439

540
### Changed

Makefile

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,132 @@
1-
.PHONY: help test lint format typecheck ci-check act-local act-lint act-test clean
1+
# Color output
2+
BLUE := \033[0;34m
3+
GREEN := \033[0;32m
4+
YELLOW := \033[1;33m
5+
RED := \033[0;31m
6+
NC := \033[0m # No Color
7+
8+
# act configuration
9+
CONTAINER_ARCH := linux/amd64
10+
ACT_IMAGE := catthehacker/ubuntu:act-22.04
11+
12+
.PHONY: help test lint format typecheck ci-check act-local act-lint act-test clean check-docker
213

314
help: ## Show this help message
4-
@echo "Available commands:"
5-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
15+
@echo "$(BLUE)Available commands:$(NC)"
16+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
617

718
# Local testing (fast, no Docker)
819
test: ## Run tests locally
9-
uv run pytest tests/ -v
20+
@echo "$(BLUE)Running test suite...$(NC)"
21+
@uv run pytest tests/ -v
22+
@echo "$(GREEN)✓ All tests passed$(NC)"
23+
24+
test-quick: ## Run tests with minimal output
25+
@echo "$(BLUE)Running test suite (quick mode)...$(NC)"
26+
@uv run pytest tests/ -q --tb=line
27+
@echo "$(GREEN)✓ All tests passed$(NC)"
1028

1129
lint: ## Run linting checks
12-
uv run ruff check xbooster/ tests/
30+
@echo "$(BLUE)Linting with ruff...$(NC)"
31+
@uv run ruff check xbooster/ tests/
32+
@echo "$(GREEN)✓ Lint passed$(NC)"
1333

1434
format: ## Format code with ruff
15-
uv run ruff format xbooster/ tests/
35+
@echo "$(BLUE)Formatting code with ruff...$(NC)"
36+
@uv run ruff format xbooster/ tests/
37+
@echo "$(GREEN)✓ Code formatted$(NC)"
1638

1739
format-check: ## Check code formatting
18-
uv run ruff format --check xbooster/ tests/
40+
@echo "$(BLUE)Checking format with ruff...$(NC)"
41+
@uv run ruff format --check xbooster/ tests/
42+
@echo "$(GREEN)✓ Format check passed$(NC)"
1943

2044
typecheck: ## Run type checking with ty
21-
uv run ty check
22-
23-
ci-check: lint format-check typecheck ## Run all CI checks locally (fast)
24-
@echo "✅ All CI checks passed!"
45+
@echo "$(BLUE)Type checking with ty...$(NC)"
46+
@uv run ty check
47+
@echo "$(GREEN)✓ Type check passed$(NC)"
48+
49+
ci-check: ## Run all CI checks locally (fast, no Docker)
50+
@echo "$(BLUE)🔍 Running CI Checks Locally$(NC)"
51+
@echo "================================"
52+
@echo ""
53+
@echo "$(BLUE)[1/4]$(NC) Linting with ruff..."
54+
@uv run ruff check xbooster/ tests/
55+
@echo "$(GREEN)$(NC) Lint passed"
56+
@echo ""
57+
@echo "$(BLUE)[2/4]$(NC) Checking format with ruff..."
58+
@uv run ruff format --check xbooster/ tests/
59+
@echo "$(GREEN)$(NC) Format check passed"
60+
@echo ""
61+
@echo "$(BLUE)[3/4]$(NC) Type checking with ty..."
62+
@uv run ty check
63+
@echo "$(GREEN)$(NC) Type check passed"
64+
@echo ""
65+
@echo "$(BLUE)[4/4]$(NC) Running test suite..."
66+
@uv run pytest tests/ -q --tb=line
67+
@echo "$(GREEN)$(NC) All tests passed"
68+
@echo ""
69+
@echo "================================"
70+
@echo "$(GREEN)✨ All CI checks passed!$(NC)"
71+
72+
# Docker/act utilities
73+
check-docker: ## Check if Docker is running
74+
@if ! docker info > /dev/null 2>&1; then \
75+
echo "$(RED)Error: Docker is not running$(NC)"; \
76+
echo "Please start Docker Desktop and try again."; \
77+
exit 1; \
78+
fi
2579

2680
# act-based testing (uses Docker)
27-
act-local: ## Run lightweight local workflow with act
28-
act -W .github/workflows/local-test.yml
29-
30-
act-lint: ## Run only lint job with act
31-
act -W .github/workflows/ci.yml --job lint
32-
33-
act-typecheck: ## Run only type-check job with act
34-
act -W .github/workflows/ci.yml --job type-check
35-
36-
act-test: ## Run only one test matrix with act
37-
act -W .github/workflows/ci.yml --job test --matrix python-version:3.11 --matrix xgboost-version:3.0.5
81+
act-local: check-docker ## Run lightweight local workflow with act (recommended)
82+
@echo "$(BLUE)Running lightweight local workflow...$(NC)"
83+
@echo "$(YELLOW)Memory usage: ~1.5GB$(NC)"
84+
@act -W .github/workflows/local-test.yml --container-architecture $(CONTAINER_ARCH)
85+
@echo ""
86+
@echo "$(GREEN)✓ act completed successfully$(NC)"
87+
88+
act-lint: check-docker ## Run only lint job with act
89+
@echo "$(BLUE)Running lint job...$(NC)"
90+
@act -W .github/workflows/ci.yml --job lint --container-architecture $(CONTAINER_ARCH)
91+
@echo ""
92+
@echo "$(GREEN)✓ act completed successfully$(NC)"
93+
94+
act-typecheck: check-docker ## Run only type-check job with act
95+
@echo "$(BLUE)Running type-check job...$(NC)"
96+
@act -W .github/workflows/ci.yml --job type-check --container-architecture $(CONTAINER_ARCH)
97+
@echo ""
98+
@echo "$(GREEN)✓ act completed successfully$(NC)"
99+
100+
act-test: check-docker ## Run one test matrix with act (Python 3.11 + XGBoost 3.0.5)
101+
@echo "$(BLUE)Running test matrix (Python 3.11, XGBoost 3.0.5)...$(NC)"
102+
@echo "$(YELLOW)Memory usage: ~2GB$(NC)"
103+
@act -W .github/workflows/ci.yml --job test \
104+
--matrix python-version:3.11 \
105+
--matrix xgboost-version:3.0.5 \
106+
--container-architecture $(CONTAINER_ARCH)
107+
@echo ""
108+
@echo "$(GREEN)✓ act completed successfully$(NC)"
38109

39110
act-list: ## List all available workflows and jobs
40-
act -l
111+
@echo "$(BLUE)Available workflows and jobs:$(NC)"
112+
@act -l
41113

42114
# Utility commands
43115
clean: ## Clean up build artifacts and caches
44-
rm -rf build/ dist/ *.egg-info .pytest_cache .ruff_cache
45-
find . -type d -name __pycache__ -exec rm -rf {} +
116+
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
117+
@rm -rf build/ dist/ *.egg-info .pytest_cache .ruff_cache
118+
@find . -type d -name __pycache__ -exec rm -rf {} +
119+
@echo "$(GREEN)✓ Cleaned$(NC)"
46120

47121
install: ## Install dependencies
48-
uv sync --dev
122+
@echo "$(BLUE)Installing dependencies...$(NC)"
123+
@uv sync --dev
124+
@echo "$(GREEN)✓ Dependencies installed$(NC)"
49125

50126
build: ## Build package
51-
uv build
127+
@echo "$(BLUE)Building package...$(NC)"
128+
@uv build
129+
@echo "$(GREEN)✓ Package built$(NC)"
52130

53131
version: ## Show current version
54132
@uv run python -c "from xbooster import __version__; print(f'xBooster v{__version__}')"

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ include = ["tests/**"]
150150
unresolved-import = "ignore"
151151
no-matching-overload = "ignore"
152152

153-
# Specific overrides for xbooster modules with XGBoost/CatBoost
153+
# Specific overrides for xbooster modules with XGBoost/CatBoost/LightGBM
154154
[[tool.ty.overrides]]
155-
include = ["xbooster/xgb_constructor.py", "xbooster/cb_constructor.py", "xbooster/catboost_*.py"]
155+
include = ["xbooster/xgb_constructor.py", "xbooster/cb_constructor.py", "xbooster/catboost_*.py", "xbooster/lgb_constructor.py"]
156156
[tool.ty.overrides.rules]
157157
unresolved-attribute = "ignore"
158158
possibly-missing-attribute = "ignore"
159+
possibly-missing-import = "ignore"
159160
invalid-return-type = "ignore"
160161
invalid-assignment = "ignore"
161162
no-matching-overload = "ignore"

run-act.sh

Lines changed: 0 additions & 95 deletions
This file was deleted.

run-ci-checks.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

typings/lightgbm/__init__.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Type stubs for lightgbm package."""
2+
3+
from typing import Any
4+
5+
class LGBMClassifier:
6+
"""Type stub for LightGBM classifier."""
7+
8+
booster_: Any
9+
n_estimators: int
10+
11+
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
12+
def fit(self, *args: Any, **kwargs: Any) -> Any: ...
13+
def predict(self, *args: Any, **kwargs: Any) -> Any: ...
14+
def predict_proba(self, *args: Any, **kwargs: Any) -> Any: ...
15+
16+
class Booster:
17+
"""Type stub for LightGBM Booster."""
18+
19+
def dump_model(self) -> Any: ...
20+
def trees_to_dataframe(self) -> Any: ...
21+
22+
def __getattr__(name: str) -> Any: ...

typings/py.typed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Marker file for PEP 561 type stubs

typings/scipy/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Type stubs for scipy package."""

typings/scipy/special.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Type stubs for scipy.special module."""
2+
3+
import numpy as np
4+
5+
def expit(x: float | np.ndarray) -> float | np.ndarray:
6+
"""Sigmoid function (expit)."""
7+
...

typings/scipy/stats.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Type stubs for scipy.stats module."""
2+
3+
class norm: # noqa: N801
4+
"""Stub for scipy.stats.norm."""
5+
6+
def ppf(self, q: float) -> float:
7+
"""Percent point function (inverse of cdf)."""
8+
...

0 commit comments

Comments
 (0)