Skip to content

Commit 41872d2

Browse files
Copilotnjzjzpre-commit-ci[bot]
authored
feat: set up Copilot agent environment with uv, pre-commit, and GitHub Actions workflow (#536)
This PR sets up the Copilot agent environment following GitHub's official documentation to improve the development experience for AI-assisted coding. ## Changes Made **Copilot Setup Workflow:** - Created `.github/workflows/copilot-setup-steps.yml` following GitHub's official documentation and example structure - Added proper workflow triggers (workflow_dispatch, push, pull_request) with path filtering for easy validation - Configured minimal permissions (`contents: read`) as recommended by GitHub - Pre-configures Copilot's environment with Python 3.11, uv package manager, and all project dependencies - Installs development tools (pre-commit, pyright) and sets up pre-commit hooks automatically - Uses pip-based uv installation to avoid network restrictions in Copilot environment - Verifies installation to ensure environment is properly configured before agent starts **Environment Setup:** - Implemented `uv` for Python environment and dependency management (faster than pip) - Added `uv tool install` for development tools (`pre-commit`, `pyright`) - Configured `pre-commit` as the preferred tool for code quality checks **Updated Copilot Instructions:** - Modified `.github/copilot-instructions.md` to prefer `pre-commit run --all-files` over direct `ruff` usage - Added comprehensive Copilot agent environment setup section - Updated validation workflow to use modern tooling - Added fallback instructions for network-restricted environments **Configuration Fixes:** - Updated `pyproject.toml` to use modern ruff configuration format (`[tool.ruff.lint]`) - Eliminated deprecation warnings about top-level linter settings - Removed deprecated `ignore-init-module-imports` option ## Benefits - **Reliable agent environment** through pre-configured workflow steps that run before the agent starts - **Faster dependency resolution** with `uv` package manager - **Network restriction compatibility** by avoiding blocked domains during setup - **Comprehensive code quality checks** through pre-commit hooks (ruff, prettier, velin, blacken-docs) - **Better developer experience** for Copilot agents with proper tool installation - **Modern tooling practices** following GitHub's recommendations - **Consistent code quality** across all contributors The copilot-setup-steps.yml workflow ensures that Copilot agents have a deterministic, fast, and reliable environment setup instead of relying on trial-and-error dependency discovery. Fixes #535. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/deepmodeling/dpdispatcher/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: njzjz <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 43d6e67 commit 41872d2

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

.github/copilot-instructions.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Always reference these instructions first and fallback to search or bash command
1313
```bash
1414
uv venv .venv
1515
source .venv/bin/activate
16-
uv pip install .[test] coverage ruff pre-commit
16+
uv pip install .[test] coverage
17+
uv tool install pre-commit
18+
uv tool install pyright
1719
```
1820

1921
- **Run the test suite:**
@@ -29,11 +31,11 @@ Always reference these instructions first and fallback to search or bash command
2931
- **Run linting and formatting:**
3032

3133
```bash
32-
ruff check .
33-
ruff format --check .
34+
pre-commit run --all-files
3435
```
3536

36-
- **TIMING: Linting takes <1 second.**
37+
- **TIMING: Linting takes <5 seconds.**
38+
- **Fallback:** If pre-commit fails with network issues, use `ruff check . && ruff format --check .`
3739

3840
- **Run type checking:**
3941

@@ -53,6 +55,24 @@ Always reference these instructions first and fallback to search or bash command
5355

5456
- **TIMING: Documentation build takes ~14 seconds.**
5557

58+
### Copilot Agent Environment Setup
59+
60+
Following GitHub's Copilot agent environment guidelines, this project uses:
61+
62+
- **`uv`** for Python environment and dependency management
63+
- **`uv tool install`** for development tools (`pre-commit`, `pyright`)
64+
- **`pre-commit`** for automated code quality checks (preferred over direct tool usage)
65+
66+
```bash
67+
# Initial setup
68+
uv venv .venv
69+
source .venv/bin/activate
70+
uv pip install .[test] coverage
71+
uv tool install pre-commit
72+
uv tool install pyright
73+
pre-commit install --install-hooks
74+
```
75+
5676
### CLI Usage
5777

5878
- **Test basic CLI functionality:**
@@ -70,7 +90,7 @@ Always reference these instructions first and fallback to search or bash command
7090
## Validation
7191

7292
- **ALWAYS run the test suite after making code changes.** Tests execute quickly (~25 seconds) and should never be cancelled.
73-
- **ALWAYS run linting before committing:** `ruff check . && ruff format --check .`
93+
- **ALWAYS run linting before committing:** `pre-commit run --all-files`
7494
- **ALWAYS run type checking:** `pyright` to catch type-related issues.
7595
- **Test CLI functionality:** Run `dpdisp --help` and test with example scripts to ensure the CLI works correctly.
7696
- **Build documentation:** Run `make html` in the `doc/` directory to verify documentation builds without errors.
@@ -81,7 +101,7 @@ Always reference these instructions first and fallback to search or bash command
81101
- **Build system:** Uses `setuptools` with `pyproject.toml` configuration.
82102
- **Python versions:** Supports Python 3.7+ (check `pyproject.toml` for current support matrix).
83103
- **Testing:** Uses `unittest` framework with coverage reporting.
84-
- **Linting:** Uses `ruff` for both linting and formatting.
104+
- **Linting:** Uses `pre-commit` with `ruff` for linting and formatting, plus other quality checks.
85105
- **Type checking:** Uses `pyright` for static type analysis (configured in `pyproject.toml`).
86106
- **Documentation:** Uses Sphinx with MyST parser for markdown support.
87107

@@ -161,13 +181,14 @@ dpdisp run examples/dpdisp_run.py
161181
- **Always add type hints** - Include proper type annotations in all Python code for better maintainability
162182
- **Always use conventional commit format** - All commit messages and PR titles must follow the conventional commit specification (e.g., `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`)
163183
- **Test artifacts are gitignored** - Job execution creates temporary files that are automatically excluded
164-
- **Pre-commit hooks available** - Use `pre-commit install` to enable automated code quality checks
184+
- **Pre-commit hooks available** - Use `pre-commit install --install-hooks` to enable automated code quality checks
165185
- **Multiple execution contexts** - Code supports local execution, SSH remote execution, and various HPC schedulers
166186
- **Extensive examples** - Use `examples/` directory as reference for proper configuration formats
167187

168188
## Troubleshooting
169189

170190
- **Virtual environment issues:** Always use `uv venv .venv` and `source .venv/bin/activate`
191+
- **Tool installation:** Use `uv tool install pre-commit` and `uv tool install pyright` for dev tools
171192
- **Test failures:** Most tests run locally; some require specific HPC environments and will be skipped
172193
- **Documentation build warnings:** Some warnings about external inventory URLs are expected in sandboxed environments
173194
- **Pre-commit network issues:** If pre-commit fails with network timeouts, run `ruff check` and `ruff format` directly
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Copilot Setup Steps"
2+
3+
# Automatically run the setup steps when they are changed to allow for easy validation, and
4+
# allow manual testing through the repository's "Actions" tab
5+
on:
6+
workflow_dispatch:
7+
push:
8+
paths:
9+
- .github/workflows/copilot-setup-steps.yml
10+
pull_request:
11+
paths:
12+
- .github/workflows/copilot-setup-steps.yml
13+
14+
jobs:
15+
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
16+
copilot-setup-steps:
17+
runs-on: ubuntu-latest
18+
19+
# Set the permissions to the lowest permissions possible needed for your steps.
20+
# Copilot will be given its own token for its operations.
21+
permissions:
22+
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
23+
contents: read
24+
25+
# You can define any steps you want, and they will run before the agent starts.
26+
# If you do not check out your code, Copilot will do this for you.
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.11"
35+
36+
- name: Install uv
37+
run: |
38+
# Install uv using pip to avoid network restrictions
39+
python -m pip install --upgrade pip
40+
python -m pip install uv
41+
42+
- name: Create virtual environment and install dependencies
43+
run: |
44+
uv venv .venv
45+
source .venv/bin/activate
46+
uv pip install .[test] coverage
47+
48+
- name: Install development tools
49+
run: |
50+
uv tool install pre-commit
51+
uv tool install pyright
52+
53+
- name: Set up pre-commit hooks
54+
run: |
55+
source .venv/bin/activate
56+
pre-commit install --install-hooks
57+
58+
- name: Verify installation
59+
run: |
60+
source .venv/bin/activate
61+
python --version
62+
uv --version
63+
pre-commit --version
64+
pyright --version
65+
python -c "import dpdispatcher; print('DPDispatcher installed successfully')"

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ exclude = [
8282
[tool.isort]
8383
profile = "black"
8484

85-
[tool.ruff]
85+
[tool.ruff.lint]
8686
select = [
8787
"E", # errors
8888
"F", # pyflakes
@@ -110,7 +110,6 @@ ignore = [
110110
"D401", # TODO: first line should be in imperative mood
111111
"D404", # TODO: first word of the docstring should not be This
112112
]
113-
ignore-init-module-imports = true
114113

115-
[tool.ruff.pydocstyle]
114+
[tool.ruff.lint.pydocstyle]
116115
convention = "numpy"

0 commit comments

Comments
 (0)