diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b24745f0..874a97bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,13 +8,13 @@ Thank you for your interest in contributing to Relax! This document provides gui - [Code of Conduct](#code-of-conduct) - [How Can I Contribute?](#how-can-i-contribute) -- [Development Setup](#development-setup) -- [Development Workflow](#development-workflow) +- [Developing](#developing) - [Code Style](#code-style) - [Commit Conventions](#commit-conventions) - [Pull Request Process](#pull-request-process) - [Reporting Bugs](#reporting-bugs) - [Requesting Features](#requesting-features) +- [Community](#community) - [License](#license) ## Code of Conduct @@ -38,58 +38,17 @@ This project follows a standard code of conduct. Please be respectful, inclusive - **Examples** — Add new training examples or tutorials - **Testing** — Improve test coverage and add integration tests -## Development Setup +## Developing -```bash -# Clone the repository -git clone https://github.com/redai-studio/Relax.git -cd Relax +Follow the [development workflow](docs/en/guide/how-to-contribute.md#developing) for step-by-step commands: -# Create virtual environment (recommended) -python -m venv .venv -source .venv/bin/activate - -# Install dependencies -pip install -r requirements.txt - -# Install in development mode -pip install -e . -``` - -## Development Workflow - -### 1. Create a Branch - -```bash -# Feature -git checkout -b feature/your-feature-name - -# Bug fix -git checkout -b fix/your-bug-fix - -# Documentation -git checkout -b docs/your-doc-change -``` - -### 2. Make Changes - -- Follow existing code patterns and conventions -- Add or update tests for your changes -- Update documentation if applicable (both English and Chinese) - -### 3. Validate - -```bash -# Run pre-commit checks (lint + format) -pre-commit run --all-files - -# Run tests -pytest tests/ -``` - -### 4. Submit a Pull Request - -Push your branch and open a PR against `main`. Fill out the PR template completely. +1. Fork and clone the repository, add `upstream`, and sync your local `main`. +2. Set up the development environment and install Relax in editable mode. +3. Run the [DeepEyes example](docs/en/examples/deepeyes.md) to verify the training environment. +4. Create a working branch and install Git hooks with pre-commit. +5. Make your changes, add or update tests, and run the relevant unit tests. Update both language versions of the documentation when needed. +6. Review, stage, and commit your changes using [Conventional Commits](#commit-conventions). Git hooks run automatically on commit; review any fixes and stage them again before retrying. +7. Push your working branch to your fork and open a PR targeting `redai-studio/Relax`'s `main` branch. Fill out the [PR template](.github/PULL_REQUEST_TEMPLATE.md). ## Code Style @@ -133,11 +92,11 @@ feat(rollout): add streaming data consumption for async mode ### Before Submitting -- [ ] Code compiles and runs without errors -- [ ] `pre-commit run --all-files` passes -- [ ] Tests pass (`pytest tests/`) +- [ ] Relevant tests pass locally +- [ ] Git hooks pass and code is formatted - [ ] Documentation updated (if applicable) - [ ] Commit messages follow Conventional Commits +- [ ] Branch is up to date with `main` ### PR Review @@ -149,7 +108,7 @@ feat(rollout): add streaming data consumption for async mode ### Tips for a Good PR - Keep PRs focused and reasonably sized -- Provide a clear description of **what**, **why**, and **how** +- Provide a clear description of **what**, **why**, **how**, and **testing** - Link related issues (e.g., `Fixes #123`) - Add screenshots or logs for UI or behavior changes diff --git a/docs/en/guide/how-to-contribute.md b/docs/en/guide/how-to-contribute.md index 040881b6..789f846b 100644 --- a/docs/en/guide/how-to-contribute.md +++ b/docs/en/guide/how-to-contribute.md @@ -2,20 +2,32 @@ Thank you for your interest in contributing to Relax! This guide will help you get started. -## Getting Started +## Developing -### 1. Set Up Development Environment +### 1. Get the Code -Create a virtual environment and install dependencies: +**Fork** [redai-studio/Relax](https://github.com/redai-studio/Relax) on GitHub, then clone your fork locally. Replace `` with your GitHub username: ```bash -# Clone the repository -git clone https://github.com/redai-studio/Relax.git +git clone https://github.com//Relax.git cd Relax +git remote add upstream https://github.com/redai-studio/Relax.git -# Create virtual environment +# Sync with the main branch of the upstream repository +git checkout main +git pull upstream main +``` + +`origin` points to your fork, and `upstream` points to the Relax repository. For subsequent contributions, switch to your local `main` and pull upstream updates before creating a working branch. Develop on working branches and keep your local `main` for syncing with upstream. + +### 2. Set Up the Development Environment + +See the [installation guide](./installation.md) for environment requirements. + +```bash +# Create a virtual environment python -m venv .venv -source .venv/bin/activate # On Windows: .venv\Scripts\activate +source .venv/bin/activate # Install dependencies pip install -r requirements.txt @@ -24,16 +36,6 @@ pip install -r requirements.txt pip install -e . ``` -### 2. Start Ray and Deploy Services - -```bash -# Start Ray cluster -ray start --head - -# Deploy all services -python -m relax.core.controller deploy --config configs/env.yaml -``` - ### 3. Run Example Experiment ```bash @@ -45,64 +47,50 @@ cd examples/deepeyes bash run_deepeyes.sh ``` -## Development Workflow - -### 1. Create a Branch +### 4. Start Developing ```bash -# Create a feature branch -git checkout -b feature/your-feature-name +git checkout -b feature/your-change +``` -# Or a bugfix branch -git checkout -b fix/your-bug-fix +Install pre-commit and Git hooks: + +```bash +pip install pre-commit +pre-commit install ``` -### 2. Make Changes +Once installed, checks run automatically on each `git commit`. -- Write clean, readable code -- Follow the existing code style -- Add tests for new features -- Update documentation as needed +### 5. Run Unit Tests -### 3. Run Tests +After changing the code, add tests for new or fixed behavior and choose the test scope appropriate for your changes: ```bash # Run all tests pytest tests/ -# Run specific test file +# Run a specific test file pytest tests/utils/test_metrics_service.py # Run with coverage pytest --cov=relax tests/ ``` -### 4. Format Code - -```bash -# Format with black -black relax/ - -# Sort imports -isort relax/ - -# Run linter -flake8 relax/ -``` +### 6. Commit Changes -### 5. Commit Changes +After completing the relevant validation, review your changes and stage the files you intend to commit. Replace `` with actual paths, separated by spaces: ```bash -# Stage changes -git add . - -# Commit with descriptive message -git commit -m "feat: add new feature" -# or -git commit -m "fix: resolve bug in metrics service" +git status +git diff +git add +git commit -m "feat: describe your change" ``` -Follow [Conventional Commits](https://www.conventionalcommits.org/): +If a hook modifies files or reports errors, review and fix the changes, then run `git add` and `git commit` again until the checks pass and the commit succeeds. + +Follow [Conventional Commits](https://www.conventionalcommits.org/) for commit messages: - `feat:` - New feature - `fix:` - Bug fix @@ -112,15 +100,16 @@ Follow [Conventional Commits](https://www.conventionalcommits.org/): - `test:` - Adding or updating tests - `chore:` - Maintenance tasks -### 6. Push and Create Pull Request +### 7. Open a PR ```bash -# Push to your fork -git push origin feature/your-feature-name - -# Create pull request on GitHub +git push origin feature/your-change ``` +On GitHub, open a PR from your working branch in your fork to **`main` in `redai-studio/Relax`**, and fill out the [PR template](https://github.com/redai-studio/Relax/blob/main/.github/PULL_REQUEST_TEMPLATE.md). Replace the branch name in the command if you chose a different one. + +Address CI results and review feedback on the same branch, then check, commit, and push your changes. The PR updates automatically. + ## Code Style Guidelines ### Python Style @@ -167,7 +156,6 @@ def compute_reward( ### Writing Tests ```python -import pytest from relax.utils.metrics.client import MetricsClient def test_metrics_client_log_metric(): @@ -191,13 +179,15 @@ def test_metrics_client_log_metric(): ### Adding Documentation -1. Add markdown files to `docs/guide/` or `docs/zh/guide/` -2. Update `.vitepress/config.mts` to add to sidebar +1. Add markdown files to `docs/en/guide/` or `docs/zh/guide/` +2. Update `docs/.vitepress/config.mts` to add to sidebar 3. Include code examples and diagrams 4. Provide both English and Chinese versions ### Building Documentation +Install Node.js, then run the following commands from the repository root: + ```bash # Start documentation dev server make docs-dev diff --git a/docs/zh/guide/how-to-contribute.md b/docs/zh/guide/how-to-contribute.md index dca0c31e..3991505c 100644 --- a/docs/zh/guide/how-to-contribute.md +++ b/docs/zh/guide/how-to-contribute.md @@ -1,21 +1,33 @@ # 如何贡献 -感谢您对 Relax 项目的关注!本指南将帮助您开始贡献。 +感谢你对 Relax 项目的关注!本指南将帮助你开始贡献。 -## 开始 +## 开发流程 -### 1. 设置开发环境 +### 1. 获取代码 -创建虚拟环境并安装依赖: +在 GitHub 上 **Fork** [redai-studio/Relax](https://github.com/redai-studio/Relax),再将你的 fork 克隆到本地。将 `` 替换为你的 GitHub 用户名: ```bash -# 克隆仓库 -git clone https://github.com/redai-studio/Relax.git +git clone https://github.com//Relax.git cd Relax +git remote add upstream https://github.com/redai-studio/Relax.git +# 同步主仓库的 main 分支 +git checkout main +git pull upstream main +``` + +`origin` 指向你的 fork,`upstream` 指向 Relax 主仓库。后续贡献前,切回本地 `main` 并拉取上游更新,再创建工作分支。请在工作分支上开发,保持本地 `main` 用于同步主线。 + +### 2. 设置开发环境 + +环境要求见[安装指南](./installation.md)。 + +```bash # 创建虚拟环境 python -m venv .venv -source .venv/bin/activate # Windows: .venv\Scripts\activate +source .venv/bin/activate # 安装依赖 pip install -r requirements.txt @@ -24,16 +36,6 @@ pip install -r requirements.txt pip install -e . ``` -### 2. 启动 Ray 并部署服务 - -```bash -# 启动 Ray 集群 -ray start --head - -# 部署所有服务 -python -m relax.core.controller deploy --config configs/env.yaml -``` - ### 3. 运行示例实验 ```bash @@ -45,26 +47,24 @@ cd examples/deepeyes bash run_deepeyes.sh ``` -## 开发工作流 - -### 1. 创建分支 +### 4. 开始开发 ```bash -# 创建功能分支 -git checkout -b feature/your-feature-name +git checkout -b feature/your-change +``` -# 或创建修复分支 -git checkout -b fix/your-bug-fix +安装 pre-commit 和 Git hooks: + +```bash +pip install pre-commit +pre-commit install ``` -### 2. 进行更改 +安装后,每次 `git commit` 都会自动运行检查。 -- 编写清晰、可读的代码 -- 遵循现有代码风格 -- 为新功能添加测试 -- 根据需要更新文档 +### 5. 执行单元测试 -### 3. 运行测试 +完成代码修改后,为新增或修复的行为补充测试,并根据改动选择测试范围: ```bash # 运行所有测试 @@ -77,32 +77,20 @@ pytest tests/utils/test_metrics_service.py pytest --cov=relax tests/ ``` -### 4. 格式化代码 - -```bash -# 使用 black 格式化 -black relax/ - -# 排序导入 -isort relax/ - -# 运行 linter -flake8 relax/ -``` +### 6. 提交更改 -### 5. 提交更改 +完成相应验证后,先查看改动,再暂存本次准备提交的文件(将 `` 替换为实际路径,多个路径用空格分隔): ```bash -# 暂存更改 -git add . - -# 使用描述性消息提交 -git commit -m "feat: add new feature" -# 或 -git commit -m "fix: resolve bug in metrics service" +git status +git diff +git add +git commit -m "feat: describe your change" ``` -遵循 [Conventional Commits](https://www.conventionalcommits.org/): +如果 hook 自动修改了文件或报告错误,请查看并修正改动,再重新 `git add` 和 `git commit`,直到检查通过并提交成功。 + +提交消息遵循 [Conventional Commits](https://www.conventionalcommits.org/): - `feat:` - 新功能 - `fix:` - Bug 修复 @@ -112,15 +100,16 @@ git commit -m "fix: resolve bug in metrics service" - `test:` - 添加或更新测试 - `chore:` - 维护任务 -### 6. 推送并创建 Pull Request +### 7. 创建 PR ```bash -# 推送到您的 fork -git push origin feature/your-feature-name - -# 在 GitHub 上创建 pull request +git push origin feature/your-change ``` +在 GitHub 上,从你 fork 中的工作分支向 **`redai-studio/Relax` 的 `main` 分支**创建 PR,并填写 [PR 模板](https://github.com/redai-studio/Relax/blob/main/.github/PULL_REQUEST_TEMPLATE.md)。如果使用了其他分支名,请相应替换命令中的名称。 + +后续根据 CI 结果和审查意见,在同一分支修改、检查、提交并推送,PR 会自动更新。 + ## 代码风格指南 ### Python 风格 @@ -155,12 +144,18 @@ def compute_reward( raise ValueError(f"未知的奖励类型: {reward_type}") ``` +### 文档风格 + +- 使用清晰、简洁的语言 +- 包含代码示例 +- 在有帮助时添加图表 +- 保持文档更新 + ## 测试指南 ### 编写测试 ```python -import pytest from relax.utils.metrics.client import MetricsClient def test_metrics_client_log_metric(): @@ -184,13 +179,15 @@ def test_metrics_client_log_metric(): ### 添加文档 -1. 将 markdown 文件添加到 `docs/guide/` 或 `docs/zh/guide/` -2. 更新 `.vitepress/config.mts` 以添加到侧边栏 +1. 将 markdown 文件添加到 `docs/en/guide/` 或 `docs/zh/guide/` +2. 更新 `docs/.vitepress/config.mts` 以添加到侧边栏 3. 包含代码示例和图表 4. 提供中英文两个版本 ### 构建文档 +请先安装 Node.js,再在仓库根目录执行以下命令: + ```bash # 启动文档开发服务器 make docs-dev @@ -221,6 +218,26 @@ make docs-preview - **How(如何)**:更改如何工作 - **Testing(测试)**:如何测试更改 +示例: + +```markdown +## What +为 DeepEyes 示例添加自定义奖励函数支持 + +## Why +用户需要灵活定义任务的奖励逻辑 + +## How +- 添加 `custom_reward.py` 模块 +- 更新配置以支持自定义奖励函数 +- 添加文档和示例 + +## Testing +- 添加自定义奖励函数的单元测试 +- 使用 DeepEyes 示例进行测试 +- 验证向后兼容性 +``` + ## 审查流程 1. **自动检查**:CI/CD 运行测试和 linter @@ -236,7 +253,7 @@ make docs-preview - 对他人友善和尊重 - 欢迎新人 - 提供建设性反馈 -- 假定善意 +- 心怀善意 ### 寻求帮助 @@ -244,6 +261,15 @@ make docs-preview - 加入我们的微信群 - 检查现有 issues 和 PRs +### 报告问题 + +报告 Bug 时: + +- 使用清晰、具有描述性的标题 +- 描述复现步骤 +- 包含错误消息和日志 +- 说明运行环境(操作系统、Python 版本等) + ## 贡献领域 ### 代码 @@ -281,8 +307,8 @@ make docs-preview ## 许可证 -通过为 Relax 做出贡献,您同意您的贡献将根据 Apache 2.0 许可证授权。 +你贡献的代码和文档将按 Apache 2.0 开源许可证发布。 ## 感谢! -感谢您为 Relax 做出贡献!您的贡献帮助这个项目变得更好。 +你的每一份提交都在让 Relax 框架越来越完善,感谢你为 Relax 做出的贡献!