Skip to content

Commit 3c26950

Browse files
authored
Merge pull request #21 from calicarpa/9-feature-pip-installable
Reviewed with Peva
2 parents 666ab32 + 7c45efb commit 3c26950

80 files changed

Lines changed: 4197 additions & 2002 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v6.0.2
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v8.1.0
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
enable-cache: true
26+
27+
- name: Cache native builds
28+
uses: actions/cache@v5.0.5
29+
with:
30+
path: krum/native
31+
key: native-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('krum/native/**/*.cpp', 'krum/native/**/*.cu', 'krum/native/**/*.hpp', 'uv.lock') }}
32+
33+
- name: Install dependencies
34+
run: uv sync --extra dev
35+
36+
- name: Check imports (no deprecation warnings)
37+
run: |
38+
uv run python -W error::DeprecationWarning -W error::PendingDeprecationWarning -c "from krum import tools, experiments, aggregators, attacks"
39+
uv run python -W error::DeprecationWarning -W error::PendingDeprecationWarning -c "import krum.tools, krum.experiments, krum.aggregators, krum.attacks"

.github/workflows/documentation.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Build and Deploy Documentation
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_dispatch:
75

86
permissions:
97
contents: read
@@ -32,7 +30,7 @@ jobs:
3230
python-version-file: "pyproject.toml"
3331

3432
- name: Install dependencies
35-
run: uv sync --group docs
33+
run: uv sync --extra dev
3634

3735
- name: Build documentation
3836
run: uv run sphinx-build -b html docs docs/_build/html

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
pypi:
10+
name: Build & Publish to PyPI
11+
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write # Required for trusted publishing (recommended)
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v5
20+
21+
- name: Build package
22+
run: uv build
23+
24+
- name: Publish to PyPI
25+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33

44
# Except directories, placeholders, gitignores, LICENSE, Markdown files and Python sources
55
!*/
6+
!krum/*
67
!.placeholder
78
!.gitignore
89
!LICENSE
910
!*.md
1011
!*.py
1112
!*.toml
1213
!.python-version
14+
!uv.lock
15+
!.pre-commit-config.yaml
1316

1417
# Except documentation files
1518
docs/_build
1619
!*.rst
20+
!Makefile
1721
!*.html
1822
!*.css
1923
!*.js
@@ -24,4 +28,4 @@ docs/_build
2428
!*.yml
2529

2630
# IDE stuff
27-
.idea
31+
.idea

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.12
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
files: ^krum/
8+
- id: ruff-format

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
>=3.10
1+
>=3.10, <3.15

README.md

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,46 @@ This project implements various Byzantine-resilient Gradient Aggregation Rules (
1313
- **Extensible**: Easy to add new aggregation rules or attacks.
1414
- **High-performance**: Optional native C++ backend for Krum.
1515

16+
## Supported Python versions
17+
18+
This project supports Python **3.10 through 3.14**.
19+
1620
## Installation
1721

18-
This project uses `uv` for dependency management.
22+
### From PyPI
23+
24+
```bash
25+
pip install krum
26+
```
27+
28+
With `uv` (Recommended):
1929

2030
```bash
21-
# Clone the repository
22-
git clone https://github.com/your-username/krum.git
31+
uv pip install krum
32+
# or directly in a uv project
33+
uv add krum
34+
```
35+
36+
### From source
37+
38+
For development or if you want to modify the source, clone the repository and install in editable mode with the development dependencies:
39+
40+
```bash
41+
git clone https://github.com/calicarpa/krum.git
2342
cd krum
43+
pip install -e ".[dev]"
44+
```
45+
46+
With `uv` (Recommended):
2447

25-
# Install dependencies
26-
uv pip install -e .
48+
```bash
49+
git clone https://github.com/calicarpa/krum.git
50+
cd krum
51+
uv sync --extra dev
2752
```
2853

54+
This installs all linting, type-checking, and documentation tools.
55+
2956
## Usage
3057

3158
You can run training simulations using `train.py`. The script accepts numerous arguments to configure the experiment.
@@ -71,6 +98,45 @@ uv run python train.py \
7198

7299
- *in progress*
73100

101+
## Contributing
102+
103+
### Linting, formatting, and type-checking
104+
105+
This project uses [Ruff](https://docs.astral.sh/ruff/) for unified linting and formatting, and [ty](https://github.com/astral-sh/ty) for type-checking.
106+
107+
Run the formatter and linter:
108+
109+
```bash
110+
ruff format .
111+
ruff check --fix .
112+
```
113+
114+
Run the type checker:
115+
116+
```bash
117+
ty check
118+
```
119+
120+
### Pre-commit hooks
121+
122+
Install pre-commit hooks to block non-compliant commits:
123+
124+
```bash
125+
pre-commit install
126+
```
127+
128+
### Documentation
129+
130+
Build the documentation locally:
131+
132+
```bash
133+
cd docs
134+
make html #
135+
make watch #
136+
make serve #
137+
make clean #
138+
```
139+
74140
## License
75141

76-
See [LICENSE](LICENSE) for details.
142+
MIT License — see [LICENSE](LICENSE).

docs/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
# Makefile for Krum documentation
22

3-
.PHONY: help html clean servedocs live watch
3+
.PHONY: help html build clean serve watch
44

55
help:
66
@echo "Available targets:"
77
@echo " html - Build HTML documentation"
8+
@echo " build - Build HTML documentation (alias for html)"
89
@echo " clean - Remove generated files"
9-
@echo " servedocs - Build and serve static documentation"
10+
@echo " serve - Build and serve static documentation"
1011
@echo " watch - Watch for changes and serve (auto-rebuild)"
1112

1213
html:
1314
uv run sphinx-build -b html . _build/html
1415

16+
build: html
17+
1518
clean:
1619
rm -rf _build
1720

18-
servedocs:
21+
serve:
1922
uv run sphinx-build -b html . _build/html && uv run python -m http.server 8000 -d _build/html
2023

2124
watch:
22-
uv run sphinx-autobuild -b html . _build/html --port 8000 --host 127.0.0.1
25+
uv run sphinx-autobuild -b html . _build/html --port 8000 --host 127.0.0.1

docs/_static/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616

1717
.bd-toc .page-toc + .sidebar-secondary-item {
1818
display: none;
19+
}
20+
21+
/* Contributions Avatar */
22+
.sphinx-contributors img {
23+
border-radius: 50%;
1924
}

docs/conf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9+
import importlib
910
import os
1011
import sys
1112

1213
sys.path.insert(0, os.path.abspath(".."))
1314

15+
# Make krum submodules available as top-level imports for autodoc compatibility
16+
for _mod in ("aggregators", "attacks", "experiments", "native", "tools"):
17+
sys.modules[_mod] = importlib.import_module(f"krum.{_mod}")
18+
1419
project = "Krum, the Library"
1520
copyright = "2026"
1621
author = "Peva BLANCHARD, Arthur DANJOU, El-Mahdi EL-MHAMDI, Sébastien ROUAULT, Mohammed Ammar SAID"
@@ -30,9 +35,10 @@
3035
"sphinx.ext.intersphinx",
3136
"sphinx_favicon",
3237
"sphinx_togglebutton",
33-
"sphinx_contributors"
38+
"sphinx_contributors",
3439
]
3540

41+
3642
def linkcode_resolve(domain, info):
3743
"""Return a URL to the source code on GitHub for the given object."""
3844
if domain != "py":
@@ -90,9 +96,7 @@ def linkcode_resolve(domain, info):
9096

9197

9298
# Use MathJax to render math in HTML
93-
mathjax_path = (
94-
"https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
95-
)
99+
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
96100

97101
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
98102

@@ -158,7 +162,7 @@ def linkcode_resolve(domain, info):
158162
{
159163
"title": "How to add a custom dataset",
160164
"url": "how-to/add-custom-dataset",
161-
}
165+
},
162166
],
163167
},
164168
{

0 commit comments

Comments
 (0)