Skip to content

Commit 3c39f33

Browse files
CopilotRahuldrabit
andauthored
ci: add Python CI matrix with coverage and publish workflow
Agent-Logs-Url: https://github.com/Rahuldrabit/Genetic_algorithm/sessions/edbe1fdb-9301-434a-90c8-2a55d8a15bb0 Co-authored-by: Rahuldrabit <104688569+Rahuldrabit@users.noreply.github.com>
1 parent 658a904 commit 3c39f33

6 files changed

Lines changed: 85 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.9", "3.10", "3.11"]
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install pytest pytest-cov ruff
31+
pip install .
32+
33+
- name: Lint
34+
run: |
35+
ruff check genetic_algorithm tests/test_python_package.py
36+
37+
- name: Run Python tests with coverage
38+
run: |
39+
export PYTHONPATH=.
40+
pytest --cov=genetic_algorithm

.github/workflows/publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Build distributions
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install build
28+
python -m build
29+
30+
- name: Publish package to PyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1
32+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Genetic Algorithm Framework (C++)
22

3+
![CI](https://github.com/Rahuldrabit/Genetic_algorithm/actions/workflows/ci.yml/badge.svg)
4+
35
A reusable C++ genetic algorithm framework you can embed in any application. It exposes a small, modern C++ API and ships with a rich set of crossover, mutation, and selection operators.
46

57
## 🚀 Features

genetic_algorithm/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Python package alias for the compiled :mod:`ga` extension."""
2+
3+
from ga import * # noqa: F401,F403
4+

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Repository = "https://github.com/Rahuldrabit/Genetic_algorithm"
2424
Issues = "https://github.com/Rahuldrabit/Genetic_algorithm/issues"
2525

2626
[tool.scikit-build]
27-
# This project ships a compiled extension module (`ga`) and no pure-Python package tree.
28-
wheel.packages = []
27+
# Ship the compiled extension (`ga`) and a lightweight Python package alias.
28+
wheel.packages = ["genetic_algorithm"]

tests/test_python_package.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test_python_package_alias_importable():
2+
import genetic_algorithm
3+
4+
assert hasattr(genetic_algorithm, "Config")
5+

0 commit comments

Comments
 (0)