|
1 | 1 | # Contributing to CloudPilot |
2 | 2 |
|
3 | | -Thank you for your interest in contributing to CloudPilot! Your contributions help make this project better for everyone. Please follow these guidelines when contributing. |
| 3 | +Thank you for contributing. This document describes how to set up a development environment, run the same checks as CI, and submit changes. |
4 | 4 |
|
5 | | -## How to Report Bugs |
| 5 | +## Contents |
6 | 6 |
|
7 | | -- **Search for existing issues:** Before reporting a new bug, please check the [issues](https://github.com/yourusername/CloudPilot/issues) section. |
8 | | -- **Create a new issue:** If the bug hasn’t been reported, create a new issue. Include: |
9 | | - - A clear and descriptive title. |
10 | | - - Steps to reproduce the bug. |
11 | | - - Expected vs. actual behavior. |
12 | | - - Environment details (OS, Python version, etc.). |
| 7 | +- [Reporting bugs](#reporting-bugs) |
| 8 | +- [Feature requests](#feature-requests) |
| 9 | +- [Development setup](#development-setup) |
| 10 | +- [Daily workflow](#daily-workflow) |
| 11 | +- [Code style and static analysis](#code-style-and-static-analysis) |
| 12 | +- [Tests](#tests) |
| 13 | +- [Environment variables for local runs](#environment-variables-for-local-runs) |
| 14 | +- [Pull requests](#pull-requests) |
| 15 | +- [Documentation](#documentation) |
| 16 | +- [Communication](#communication) |
13 | 17 |
|
14 | | -## Feature Requests |
| 18 | +## Reporting bugs |
15 | 19 |
|
16 | | -- **Discuss first:** Open an issue to discuss the feature request before submitting code. |
17 | | -- **Provide details:** Describe the feature, its benefits, and any relevant use cases. |
| 20 | +- Search existing issues before filing a duplicate. |
| 21 | +- Include a clear title, minimal steps to reproduce, expected vs actual behavior, and environment details (OS, Python version, how you installed CloudPilot, relevant env vars). |
18 | 22 |
|
19 | | -## Pull Request Guidelines |
| 23 | +## Feature requests |
20 | 24 |
|
21 | | -1. **Fork the Repository:** |
22 | | - Fork the repo and create your branch from the `main` branch. |
| 25 | +Open an issue to discuss scope and design before investing in a large pull request. |
23 | 26 |
|
24 | | -2. **Code Style:** |
25 | | - - Follow [PEP8](https://www.python.org/dev/peps/pep-0008/) guidelines. |
26 | | - - Run linters such as `flake8` and formatters like `black` before committing. |
27 | | -3. **Write Tests:** |
| 27 | +## Development setup |
28 | 28 |
|
29 | | - - Add or update tests in the `tests/` directory for your changes. |
30 | | - - Ensure all tests pass with `py -m pytest`. |
| 29 | +### Clone and install |
31 | 30 |
|
32 | | -4. **Commit Messages:** |
| 31 | +```bash |
| 32 | +git clone https://github.com/<your-org-or-username>/cloudpilot.git |
| 33 | +cd cloudpilot |
| 34 | +python -m venv .venv |
| 35 | +source .venv/bin/activate # or Windows: .venv\Scripts\Activate.ps1 |
| 36 | +python -m pip install --upgrade pip |
| 37 | +pip install -e ".[dev,ml]" --extra-index-url https://download.pytorch.org/whl/cpu |
| 38 | +``` |
33 | 39 |
|
34 | | - - Write clear, descriptive commit messages. |
35 | | - - Use the present tense (e.g., "Fix bug" not "Fixed bug"). |
| 40 | +Use the default PyPI index (or a CUDA index) instead of the CPU index if you need GPU builds of PyTorch. |
36 | 41 |
|
37 | | -5. **Submit a Pull Request:** |
38 | | - - Provide a clear description of your changes and reference any related issues. |
39 | | - - Follow the repository’s PR template (if available). |
| 42 | +### Alternative: uv |
40 | 43 |
|
41 | | -## Running Tests Locally |
| 44 | +```bash |
| 45 | +git clone https://github.com/<your-org-or-username>/cloudpilot.git |
| 46 | +cd cloudpilot |
| 47 | +uv sync --all-extras |
| 48 | +``` |
42 | 49 |
|
43 | | -- To run all tests: |
| 50 | +The first `uv sync` with the `ml` extra may download a large PyTorch wheel. |
44 | 51 |
|
45 | | - ```bash |
46 | | - py -m pytest |
47 | | - ``` |
| 52 | +### Optional: pre-commit |
48 | 53 |
|
49 | | -- Ensure that all tests pass before opening a pull request. |
| 54 | +Install hooks so Ruff runs on commit: |
| 55 | + |
| 56 | +```bash |
| 57 | +pip install pre-commit |
| 58 | +pre-commit install |
| 59 | +pre-commit run --all-files # optional one-off check |
| 60 | +``` |
| 61 | + |
| 62 | +Configuration lives in [`.pre-commit-config.yaml`](.pre-commit-config.yaml). CI does not require pre-commit; it invokes Ruff directly. |
| 63 | + |
| 64 | +## Daily workflow |
| 65 | + |
| 66 | +1. Create a branch from `main`. |
| 67 | +2. Make changes with tests. |
| 68 | +3. Run `ruff check .`, `ruff format .`, `mypy cloudpilot`, and `pytest` (see below). |
| 69 | +4. Open a PR with a clear description and links to issues. |
| 70 | + |
| 71 | +## Code style and static analysis |
| 72 | + |
| 73 | +| Tool | Command | Config | |
| 74 | +|------|---------|--------| |
| 75 | +| Ruff (lint) | `ruff check .` | [`pyproject.toml`](pyproject.toml) `[tool.ruff]` | |
| 76 | +| Ruff (format) | `ruff format .` | same | |
| 77 | +| Mypy | `mypy cloudpilot` | `[tool.mypy]` | |
| 78 | +| Bandit | `bandit -r cloudpilot -c pyproject.toml` | `[tool.bandit]` | |
| 79 | + |
| 80 | +CI ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)) runs Ruff (check + format check), Mypy, Bandit, `pip-audit` on a frozen environment, and pytest with coverage on Python **3.10**, **3.11**, and **3.12**. |
| 81 | + |
| 82 | +### Supply chain audit (local) |
| 83 | + |
| 84 | +Mirror the CI step: |
| 85 | + |
| 86 | +```bash |
| 87 | +pip freeze > freeze.txt |
| 88 | +pip-audit -r freeze.txt --desc on |
| 89 | +rm freeze.txt # or delete on Windows: del freeze.txt |
| 90 | +``` |
| 91 | + |
| 92 | +`freeze.txt` is gitignored; do not commit it. |
| 93 | + |
| 94 | +## Tests |
| 95 | + |
| 96 | +```bash |
| 97 | +pytest |
| 98 | +``` |
| 99 | + |
| 100 | +Pytest defaults are set in [`pyproject.toml`](pyproject.toml) under `[tool.pytest.ini_options]`: |
| 101 | + |
| 102 | +- `addopts` includes `-m 'not integration'`, so tests marked `@pytest.mark.integration` are skipped in the default run. |
| 103 | +- Markers include `integration` and `requires_torch` (reserved for tests that assume the optional Torch install). |
| 104 | + |
| 105 | +Run only integration-marked tests: |
| 106 | + |
| 107 | +```bash |
| 108 | +pytest -m integration |
| 109 | +``` |
| 110 | + |
| 111 | +Run with coverage (and optional JUnit, as in CI): |
| 112 | + |
| 113 | +```bash |
| 114 | +pytest --junitxml=junit.xml -q --cov=cloudpilot --cov=cli --cov-report=term |
| 115 | +``` |
| 116 | + |
| 117 | +Coverage reporting uses `[tool.coverage.report] fail_under = 45` in `pyproject.toml`. |
| 118 | + |
| 119 | +### Writing tests |
| 120 | + |
| 121 | +- Prefer **mocking** Kubernetes (`kubernetes.client`), AWS (`boto3`), and Prometheus rather than requiring live services. |
| 122 | +- Add or extend tests under [`tests/`](tests/) for behavioral changes. |
| 123 | +- Use `@pytest.mark.integration` only for checks that need a real cluster, cloud accounts, or long-running services, and document any required env vars in the test docstring. |
| 124 | + |
| 125 | +## Environment variables for local runs |
| 126 | + |
| 127 | +When exercising `self_heal` or K8s tuning against a real cluster: |
| 128 | + |
| 129 | +| Variable | When to set | |
| 130 | +|----------|-------------| |
| 131 | +| `CLOUDPILOT_SELF_HEAL_CONFIRM=1` | Only if you intend to delete non-Running pods (dangerous on shared clusters). | |
| 132 | +| `CLOUDPILOT_K8S_DRY_RUN=1` | To exercise tuning logic without `patch_namespaced_deployment`. | |
| 133 | + |
| 134 | +See [README.md](README.md) for the full list. |
| 135 | + |
| 136 | +## Pull requests |
| 137 | + |
| 138 | +1. Fork the repository and branch from `main`. |
| 139 | +2. Keep commits focused; use present-tense, imperative messages (for example: `Add dry-run guard for deployment patch`). |
| 140 | +3. Ensure Ruff, Mypy, and pytest pass locally. |
| 141 | +4. Describe what changed and why; reference related issues. |
50 | 142 |
|
51 | 143 | ## Documentation |
52 | 144 |
|
53 | | -- **Update Documentation:** |
54 | | - If you add new features or change functionality, please update the README and other documentation accordingly. |
| 145 | +Update [README.md](README.md) for user-facing behavior, install paths, env vars, or CLI changes. Update this file when contributor workflow or CI steps change. |
55 | 146 |
|
56 | 147 | ## Communication |
57 | 148 |
|
58 | | -- Use GitHub issues and pull requests to communicate your ideas and progress. |
59 | | -- For major changes, open an issue to discuss your approach before starting to code. |
| 149 | +Use GitHub issues and pull requests. For substantial refactors or API changes, open an issue first to agree on direction. |
60 | 150 |
|
61 | | -Thank you for contributing to CloudPilot! Your efforts help make this project better for the entire community. |
| 151 | +Thank you for helping improve CloudPilot. |
0 commit comments