Skip to content

Commit cd59dfa

Browse files
abrichrclaude
andauthored
Fix Python 3.10/3.11 compatibility (#5)
* Add GitHub Actions CI workflow for testing - Add test.yml workflow that runs on PRs and main branch pushes - Test on Python 3.10 and 3.11 across ubuntu-latest and macos-latest - Use uv for fast dependency management - Run pytest and ruff linter/formatter checks - Linting checks are non-blocking to allow iteration on code quality - Fix multiple ruff linting issues (unused imports, f-string placeholders, ambiguous variable names) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: Python 3.10/3.11 compatibility for nested f-strings in screenshot.py Replace nested f-strings with escaped quotes (Python 3.12+ only) with a two-step approach that works in Python 3.10+: - Extract label_html variable first - Use the variable in the outer f-string This fixes CI failures on Python 3.10 and 3.11. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: Python 3.10/3.11 compatibility for nested f-string with triple quotes Replace nested f-string with triple quotes (Python 3.12+ only) with string concatenation approach that works in Python 3.10+. This was causing import errors in Python 3.10 and 3.11. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * feat: add automated screenshot generation system - Created script to generate README screenshots - Added comprehensive test suite (11 tests) - Added CI workflow for automatic generation - Updated README with screenshots section - Added documentation (SCREENSHOT_SYSTEM.md, SETUP.md) - Generated initial screenshots from captures Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: remove --system flag from uv pip install in CI The --system flag prevents uv from using virtual environments, which causes failures on macOS with Homebrew's externally-managed Python. Removing the flag allows uv to handle virtual environments automatically, fixing the CI error while maintaining the same functionality. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: create virtual environment for uv pip install in CI After removing --system flag, uv requires a virtual environment. Added explicit venv creation step to fix CI error. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: use shared virtual environment for all installations Updated screenshots workflow to: - Create a single shared .venv in the workspace root - Activate the venv before each installation/execution step - Use direct python/playwright commands instead of uv run This ensures all packages are installed into the same environment and playwright can be found when installing browsers. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 319d0b9 commit cd59dfa

27 files changed

Lines changed: 2317 additions & 28 deletions

.github/workflows/screenshots.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
name: Generate Screenshots
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
upload_artifacts:
7+
description: 'Upload screenshots as artifacts'
8+
required: false
9+
type: boolean
10+
default: true
11+
push:
12+
branches:
13+
- main
14+
paths:
15+
- 'src/openadapt_viewer/**'
16+
- 'scripts/generate_readme_screenshots.py'
17+
- '.github/workflows/screenshots.yml'
18+
pull_request:
19+
paths:
20+
- 'src/openadapt_viewer/**'
21+
- 'scripts/generate_readme_screenshots.py'
22+
23+
jobs:
24+
generate-screenshots:
25+
name: Generate README Screenshots
26+
runs-on: macos-latest
27+
28+
steps:
29+
- name: Checkout openadapt-viewer
30+
uses: actions/checkout@v4
31+
with:
32+
path: openadapt-viewer
33+
34+
- name: Checkout openadapt-capture
35+
uses: actions/checkout@v4
36+
with:
37+
repository: OpenAdaptAI/openadapt-capture
38+
path: openadapt-capture
39+
# Use default branch or specific ref if needed
40+
# ref: main
41+
42+
- name: Install uv
43+
uses: astral-sh/setup-uv@v4
44+
with:
45+
version: "latest"
46+
47+
- name: Set up Python 3.11
48+
run: uv python install 3.11
49+
50+
- name: Create shared virtual environment
51+
run: uv venv --python 3.11 .venv
52+
53+
- name: Install openadapt-capture
54+
working-directory: openadapt-capture
55+
run: |
56+
source ../.venv/bin/activate
57+
uv pip install -e .
58+
59+
- name: Install openadapt-viewer with screenshots extra
60+
working-directory: openadapt-viewer
61+
run: |
62+
source ../.venv/bin/activate
63+
uv pip install -e ".[screenshots]"
64+
65+
- name: Install Playwright browsers
66+
run: |
67+
source .venv/bin/activate
68+
playwright install chromium
69+
70+
- name: Check if captures exist
71+
id: check-captures
72+
working-directory: openadapt-capture
73+
run: |
74+
if [ -d "turn-off-nightshift" ] && [ -f "turn-off-nightshift/capture.db" ]; then
75+
echo "nightshift_exists=true" >> $GITHUB_OUTPUT
76+
else
77+
echo "nightshift_exists=false" >> $GITHUB_OUTPUT
78+
echo "⚠️ Warning: turn-off-nightshift capture not found"
79+
fi
80+
81+
if [ -d "demo_new" ] && [ -f "demo_new/capture.db" ]; then
82+
echo "demo_exists=true" >> $GITHUB_OUTPUT
83+
else
84+
echo "demo_exists=false" >> $GITHUB_OUTPUT
85+
echo "⚠️ Warning: demo_new capture not found"
86+
fi
87+
88+
- name: Generate screenshots
89+
if: steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'
90+
working-directory: openadapt-viewer
91+
run: |
92+
source ../.venv/bin/activate
93+
python scripts/generate_readme_screenshots.py \
94+
--capture-dir ../openadapt-capture \
95+
--output-dir docs/images \
96+
--max-events 50
97+
continue-on-error: false
98+
99+
- name: Check generated screenshots
100+
if: steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'
101+
working-directory: openadapt-viewer
102+
run: |
103+
echo "📸 Generated screenshots:"
104+
ls -lh docs/images/*.png || echo "No PNG files found"
105+
106+
echo ""
107+
echo "📊 Screenshot details:"
108+
for img in docs/images/*.png; do
109+
if [ -f "$img" ]; then
110+
size=$(du -h "$img" | cut -f1)
111+
echo " - $(basename "$img"): $size"
112+
fi
113+
done
114+
115+
- name: Upload screenshots as artifacts
116+
if: |
117+
(github.event_name == 'workflow_dispatch' && github.event.inputs.upload_artifacts == 'true') ||
118+
(github.event_name != 'workflow_dispatch' && (steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'))
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: readme-screenshots
122+
path: openadapt-viewer/docs/images/*.png
123+
if-no-files-found: warn
124+
retention-days: 30
125+
126+
- name: Create pull request with screenshots (on main push)
127+
if: |
128+
github.event_name == 'push' &&
129+
github.ref == 'refs/heads/main' &&
130+
(steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true')
131+
uses: peter-evans/create-pull-request@v6
132+
with:
133+
path: openadapt-viewer
134+
token: ${{ secrets.GITHUB_TOKEN }}
135+
commit-message: "docs: update README screenshots"
136+
title: "Update README screenshots"
137+
body: |
138+
## Automated Screenshot Update
139+
140+
This PR updates the README screenshots using the latest viewer code.
141+
142+
### Generated Screenshots
143+
- Turn off Night Shift workflow
144+
- Demo workflow examples
145+
146+
### Changes
147+
- Updated screenshot images in `docs/images/`
148+
149+
Screenshots were automatically generated by the [Screenshots workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
150+
branch: update-screenshots-${{ github.run_id }}
151+
delete-branch: true
152+
labels: documentation,automated
153+
154+
- name: Comment on PR with screenshot preview (on pull request)
155+
if: |
156+
github.event_name == 'pull_request' &&
157+
(steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true')
158+
uses: actions/github-script@v7
159+
with:
160+
script: |
161+
const fs = require('fs');
162+
const path = require('path');
163+
164+
const imagesDir = path.join(process.env.GITHUB_WORKSPACE, 'openadapt-viewer', 'docs', 'images');
165+
166+
let comment = '## 📸 Generated Screenshots Preview\n\n';
167+
comment += 'Screenshots have been generated. Download the artifacts to preview them.\n\n';
168+
169+
if (fs.existsSync(imagesDir)) {
170+
const files = fs.readdirSync(imagesDir).filter(f => f.endsWith('.png'));
171+
if (files.length > 0) {
172+
comment += '### Generated Files:\n';
173+
files.forEach(file => {
174+
const stats = fs.statSync(path.join(imagesDir, file));
175+
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
176+
comment += `- \`${file}\` (${sizeMB} MB)\n`;
177+
});
178+
}
179+
}
180+
181+
comment += '\n---\n';
182+
comment += `🔗 [Download screenshots artifact](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
183+
184+
github.rest.issues.createComment({
185+
owner: context.repo.owner,
186+
repo: context.repo.repo,
187+
issue_number: context.issue.number,
188+
body: comment
189+
});
190+
191+
- name: Summary
192+
if: always()
193+
run: |
194+
echo "## Screenshot Generation Summary" >> $GITHUB_STEP_SUMMARY
195+
echo "" >> $GITHUB_STEP_SUMMARY
196+
197+
if [ "${{ steps.check-captures.outputs.nightshift_exists }}" == "true" ]; then
198+
echo "✅ turn-off-nightshift capture found" >> $GITHUB_STEP_SUMMARY
199+
else
200+
echo "⚠️ turn-off-nightshift capture not found" >> $GITHUB_STEP_SUMMARY
201+
fi
202+
203+
if [ "${{ steps.check-captures.outputs.demo_exists }}" == "true" ]; then
204+
echo "✅ demo_new capture found" >> $GITHUB_STEP_SUMMARY
205+
else
206+
echo "⚠️ demo_new capture not found" >> $GITHUB_STEP_SUMMARY
207+
fi
208+
209+
echo "" >> $GITHUB_STEP_SUMMARY
210+
211+
if [ -d "openadapt-viewer/docs/images" ]; then
212+
echo "### Generated Screenshots" >> $GITHUB_STEP_SUMMARY
213+
echo "" >> $GITHUB_STEP_SUMMARY
214+
for img in openadapt-viewer/docs/images/*.png; do
215+
if [ -f "$img" ]; then
216+
size=$(du -h "$img" | cut -f1)
217+
echo "- $(basename "$img"): $size" >> $GITHUB_STEP_SUMMARY
218+
fi
219+
done
220+
else
221+
echo "⚠️ No screenshots generated" >> $GITHUB_STEP_SUMMARY
222+
fi

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '**'
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, macos-latest]
17+
python-version: ['3.10', '3.11']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v4
25+
with:
26+
version: "latest"
27+
28+
- name: Set up Python ${{ matrix.python-version }}
29+
run: uv python install ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: uv sync --all-extras
33+
34+
- name: Run ruff linter (check)
35+
run: uv run ruff check src/openadapt_viewer/ || true
36+
continue-on-error: true
37+
38+
- name: Run ruff formatter (check)
39+
run: uv run ruff format --check src/openadapt_viewer/ || true
40+
continue-on-error: true
41+
42+
- name: Run pytest
43+
run: uv run pytest tests/ -v

0 commit comments

Comments
 (0)