From 658a904f715264d9e8c5f1e41f190fce37e0bad3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:35:47 +0000 Subject: [PATCH 1/3] Initial plan From 3c39f33153c54291aba72ba57eee637431a85f36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:40:55 +0000 Subject: [PATCH 2/3] 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> --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 32 ++++++++++++++++++++++++++++ README.md | 2 ++ genetic_algorithm/__init__.py | 4 ++++ pyproject.toml | 4 ++-- tests/test_python_package.py | 5 +++++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml create mode 100644 genetic_algorithm/__init__.py create mode 100644 tests/test_python_package.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..72023ab --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov ruff + pip install . + + - name: Lint + run: | + ruff check genetic_algorithm tests/test_python_package.py + + - name: Run Python tests with coverage + run: | + export PYTHONPATH=. + pytest --cov=genetic_algorithm diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9220122 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,32 @@ +name: Publish to PyPI + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Build distributions + run: | + python -m pip install --upgrade pip + python -m pip install build + python -m build + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + diff --git a/README.md b/README.md index 116c30f..5c50eb4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Genetic Algorithm Framework (C++) +![CI](https://github.com/Rahuldrabit/Genetic_algorithm/actions/workflows/ci.yml/badge.svg) + 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. ## 🚀 Features diff --git a/genetic_algorithm/__init__.py b/genetic_algorithm/__init__.py new file mode 100644 index 0000000..8fc70a6 --- /dev/null +++ b/genetic_algorithm/__init__.py @@ -0,0 +1,4 @@ +"""Python package alias for the compiled :mod:`ga` extension.""" + +from ga import * # noqa: F401,F403 + diff --git a/pyproject.toml b/pyproject.toml index 3c5e72b..4de6866 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,5 +24,5 @@ Repository = "https://github.com/Rahuldrabit/Genetic_algorithm" Issues = "https://github.com/Rahuldrabit/Genetic_algorithm/issues" [tool.scikit-build] -# This project ships a compiled extension module (`ga`) and no pure-Python package tree. -wheel.packages = [] +# Ship the compiled extension (`ga`) and a lightweight Python package alias. +wheel.packages = ["genetic_algorithm"] diff --git a/tests/test_python_package.py b/tests/test_python_package.py new file mode 100644 index 0000000..5599374 --- /dev/null +++ b/tests/test_python_package.py @@ -0,0 +1,5 @@ +def test_python_package_alias_importable(): + import genetic_algorithm + + assert hasattr(genetic_algorithm, "Config") + From 0d241ac1a6b86cd46a3b3452fab12006106f179d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:45:15 +0000 Subject: [PATCH 3/3] ci: harden workflow permissions and refine package alias test 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> --- .github/workflows/ci.yml | 5 +++-- genetic_algorithm/__init__.py | 8 +++++++- tests/test_python_package.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72023ab..db09cad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ on: jobs: test: runs-on: ubuntu-latest + permissions: + contents: read strategy: fail-fast: false matrix: @@ -28,7 +30,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pytest pytest-cov ruff - pip install . + pip install -e . - name: Lint run: | @@ -36,5 +38,4 @@ jobs: - name: Run Python tests with coverage run: | - export PYTHONPATH=. pytest --cov=genetic_algorithm diff --git a/genetic_algorithm/__init__.py b/genetic_algorithm/__init__.py index 8fc70a6..b869fff 100644 --- a/genetic_algorithm/__init__.py +++ b/genetic_algorithm/__init__.py @@ -1,4 +1,10 @@ """Python package alias for the compiled :mod:`ga` extension.""" -from ga import * # noqa: F401,F403 +import ga as _ga +if hasattr(_ga, "__all__"): + __all__ = _ga.__all__ +else: + __all__ = [name for name in dir(_ga) if not name.startswith("_")] + +globals().update({name: getattr(_ga, name) for name in __all__}) diff --git a/tests/test_python_package.py b/tests/test_python_package.py index 5599374..7bc67a8 100644 --- a/tests/test_python_package.py +++ b/tests/test_python_package.py @@ -1,5 +1,5 @@ -def test_python_package_alias_importable(): +def test_genetic_algorithm_importable(): import genetic_algorithm assert hasattr(genetic_algorithm, "Config") - + assert hasattr(genetic_algorithm, "Result")