diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..db09cad --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + 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 -e . + + - name: Lint + run: | + ruff check genetic_algorithm tests/test_python_package.py + + - name: Run Python tests with coverage + run: | + 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..b869fff --- /dev/null +++ b/genetic_algorithm/__init__.py @@ -0,0 +1,10 @@ +"""Python package alias for the compiled :mod:`ga` extension.""" + +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/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..7bc67a8 --- /dev/null +++ b/tests/test_python_package.py @@ -0,0 +1,5 @@ +def test_genetic_algorithm_importable(): + import genetic_algorithm + + assert hasattr(genetic_algorithm, "Config") + assert hasattr(genetic_algorithm, "Result")