Skip to content

Commit 80ad9ce

Browse files
Copilotl0lawrence
andcommitted
Add general-purpose fix-mypy, fix-pylint, and fix-black Copilot skills
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
1 parent 285de54 commit 80ad9ce

3 files changed

Lines changed: 974 additions & 0 deletions

File tree

.github/skills/fix-black/SKILL.md

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
---
2+
name: fix-black
3+
description: Automatically fix black code formatting issues in any Azure SDK for Python package. Expects GitHub issue URL, package path, and optional virtual env path in the request. Format "fix black issue <issue-url> [in <package-path>] [using venv <path>]"
4+
---
5+
6+
# Fix Black Formatting Issues Skill
7+
8+
This skill automatically fixes black code formatting issues in any Azure SDK for Python package by running the black formatter and creating a pull request with the changes.
9+
10+
## Overview
11+
12+
Intelligently fixes black formatting issues by:
13+
1. Getting the GitHub issue URL and package path from the user
14+
2. Reading and analyzing the issue details
15+
3. Setting up or using existing virtual environment
16+
4. Installing required dependencies
17+
5. Running black on the package to auto-format code
18+
6. Verifying the formatting changes
19+
7. Creating a pull request that references the GitHub issue
20+
8. Providing a summary of what was formatted
21+
22+
## Running Black
23+
24+
**Command for entire package:**
25+
```powershell
26+
python -m azpysdk black --pkg-path <package-path>
27+
```
28+
29+
**Command for specific file/module:**
30+
```powershell
31+
python -m azpysdk black --pkg-path <package-path> -- path/to/file.py
32+
```
33+
34+
## Reference Documentation
35+
36+
- [Black Documentation](https://black.readthedocs.io/en/stable/)
37+
- [Azure SDK Python Black Configuration](https://github.com/Azure/azure-sdk-for-python/blob/main/eng/black-pyproject.toml)
38+
39+
## Fixing Strategy
40+
41+
### Step 0: Get GitHub Issue and Package Details
42+
43+
**Check if user provided in their request:**
44+
- GitHub issue URL (look for `https://github.com/Azure/azure-sdk-for-python/issues/...` in user's message)
45+
- Package path (look for phrases like "in sdk/...", e.g. `sdk/storage/azure-storage-blob`)
46+
- Virtual environment path (look for phrases like "using venv", "use env", "virtual environment at", or just the venv name)
47+
48+
**If GitHub issue URL is missing:**
49+
Ask: "Please provide the GitHub issue URL for the black formatting problems you want to fix."
50+
51+
**If package path is missing:**
52+
Ask: "Please provide the package path (e.g. sdk/storage/azure-storage-blob)."
53+
54+
**If virtual environment is missing:**
55+
Ask: "Do you have an existing virtual environment path, or should I create 'env'?"
56+
57+
**Once you have the issue URL:**
58+
Read the issue to understand which files/modules need reformatting.
59+
60+
### Step 1: CRITICAL - Activate Virtual Environment FIRST
61+
62+
**IMMEDIATELY activate the virtual environment before ANY other command:**
63+
64+
```powershell
65+
# Activate the provided virtual environment (e.g., env, venv)
66+
.\<venv-name>\Scripts\Activate.ps1
67+
68+
# If creating new virtual environment:
69+
python -m venv env
70+
.\env\Scripts\Activate.ps1
71+
```
72+
73+
**⚠️ IMPORTANT: ALL subsequent commands MUST run within the activated virtual environment. Never run commands outside the venv.**
74+
75+
### Step 2: Install Dependencies (within activated venv)
76+
77+
```powershell
78+
# Navigate to the package directory (within activated venv)
79+
cd <package-path>
80+
81+
# Install dev dependencies from dev_requirements.txt (within activated venv)
82+
pip install -r dev_requirements.txt
83+
84+
# Install the package in editable mode (within activated venv)
85+
pip install -e .
86+
```
87+
88+
### Step 3: Run Black to Auto-Format (within activated venv)
89+
90+
Black is an auto-formatter — it rewrites files to comply with the style. Simply run the command and it applies all changes automatically.
91+
92+
**Format entire package:**
93+
```powershell
94+
# Run black on the entire package (within activated venv)
95+
python -m azpysdk black --pkg-path <package-path>
96+
```
97+
98+
**Format specific files (if issue mentions specific files):**
99+
```powershell
100+
# Run black on specific files (within activated venv)
101+
python -m azpysdk black --pkg-path <package-path> -- path/to/specific_file.py
102+
```
103+
104+
### Step 4: Review Changes
105+
106+
After running black, review the changes that were made:
107+
108+
```powershell
109+
# See which files were modified
110+
git diff --name-only
111+
112+
# Review the actual changes
113+
git diff
114+
```
115+
116+
### Step 5: Verify No Remaining Formatting Issues
117+
118+
Re-run black in check mode to confirm all files are now properly formatted:
119+
120+
```powershell
121+
# Verify formatting (within activated venv)
122+
python -m azpysdk black --pkg-path <package-path>
123+
```
124+
125+
If black reports no files were changed, all formatting issues are resolved.
126+
127+
### Step 6: Summary
128+
129+
Provide a summary:
130+
- GitHub issue being addressed
131+
- Number of files reformatted
132+
- Types of formatting changes applied (line length, string quotes, trailing commas, etc.)
133+
134+
### Step 7: Create Pull Request
135+
136+
After successfully fixing black formatting issues, create a pull request:
137+
138+
**Stage and commit the changes:**
139+
```powershell
140+
# Stage all modified files
141+
git add .
142+
143+
# Create a descriptive commit message referencing the issue
144+
git commit -m "style(<package-name>): apply black code formatting (#<issue-number>)
145+
146+
- Reformatted files to comply with black code style
147+
- Applied Azure SDK Python black configuration
148+
149+
Closes #<issue-number>"
150+
```
151+
152+
**Create pull request using GitHub CLI or MCP server:**
153+
154+
Option 1 - Using GitHub CLI (if available):
155+
```powershell
156+
# Create a new branch
157+
$branchName = "style/<package-name>-black-<issue-number>"
158+
git checkout -b $branchName
159+
160+
# Push the branch
161+
git push origin $branchName
162+
163+
# Create PR using gh CLI
164+
gh pr create `
165+
--title "style(<package-name>): Apply black code formatting (#<issue-number>)" `
166+
--body "## Description
167+
This PR applies black code formatting to the <package-name> package as reported in #<issue-number>.
168+
169+
## Changes
170+
- Applied black code formatting following Azure SDK Python configuration
171+
- All files now comply with the repo-wide black style settings
172+
173+
## Testing
174+
- [x] Ran black on affected files and verified all formatting is correct
175+
- [x] No functional code changes, formatting only
176+
177+
## Related Issues
178+
Fixes #<issue-number>" `
179+
--base main `
180+
--repo Azure/azure-sdk-for-python
181+
```
182+
183+
Option 2 - Manual PR creation (if GitHub CLI not available):
184+
1. Push branch: `git push origin <branch-name>`
185+
2. Navigate to: https://github.com/Azure/azure-sdk-for-python/compare/main...<branch-name>
186+
3. Create the pull request manually with the description above
187+
188+
Option 3 - Using GitHub MCP server (if available):
189+
Use the GitHub MCP tools to create a pull request programmatically against the Azure/azure-sdk-for-python repository, main branch.
190+
191+
## Black Configuration
192+
193+
The Azure SDK for Python uses a repo-wide black configuration located at `eng/black-pyproject.toml`. Key settings include:
194+
- Line length: 120 characters
195+
- Target Python versions: 3.8+
196+
197+
The `python -m azpysdk black` command automatically uses this configuration, so no manual configuration is needed.
198+
199+
## Common Black Formatting Changes
200+
201+
### Line Too Long
202+
Black will automatically break long lines at 120 characters using Python's implicit line continuation inside brackets.
203+
204+
### String Quotes
205+
Black normalizes string quotes to double quotes throughout the file.
206+
207+
### Trailing Commas
208+
Black adds trailing commas to multi-line data structures and function signatures where appropriate.
209+
210+
### Blank Lines
211+
Black ensures consistent blank lines between top-level definitions (2 blank lines) and methods (1 blank line).
212+
213+
## Example Workflow
214+
215+
```powershell
216+
# 0. Get issue details
217+
# User provides: https://github.com/Azure/azure-sdk-for-python/issues/99999
218+
# User provides package path: sdk/storage/azure-storage-blob
219+
# Issue mentions: black formatting failures in CI
220+
221+
# 1. CRITICAL - Activate virtual environment FIRST
222+
.\<venv-name>\Scripts\Activate.ps1 # Use the venv name provided by user
223+
cd sdk/storage/azure-storage-blob
224+
pip install -r dev_requirements.txt
225+
pip install -e .
226+
227+
# 2. Run black to auto-format the package
228+
python -m azpysdk black --pkg-path sdk/storage/azure-storage-blob
229+
230+
# 3. Review what changed
231+
git diff --name-only
232+
git diff
233+
234+
# 4. Verify no remaining issues
235+
python -m azpysdk black --pkg-path sdk/storage/azure-storage-blob
236+
237+
# 5. Create PR referencing the issue
238+
$branchName = "style/azure-storage-blob-black-99999"
239+
git checkout -b $branchName
240+
git add .
241+
git commit -m "style(azure-storage-blob): apply black code formatting (#99999)
242+
243+
Closes #99999"
244+
git push origin $branchName
245+
gh pr create `
246+
--title "style(azure-storage-blob): Apply black code formatting (#99999)" `
247+
--body "Fixes #99999" `
248+
--base main `
249+
--repo Azure/azure-sdk-for-python
250+
```
251+
252+
## Notes
253+
254+
- Black is an opinionated formatter with no configuration options beyond line length and target version
255+
- Changes are purely cosmetic — black never changes the semantics of your code
256+
- Always review the diff after running black to understand what changed
257+
- The Azure SDK uses `eng/black-pyproject.toml` for repo-wide black configuration
258+
- If a file has `# fmt: off` / `# fmt: on` comments, black will skip those sections intentionally
259+
- Always reference the GitHub issue in commits and PRs

0 commit comments

Comments
 (0)