Skip to content

Commit f5f96fc

Browse files
authored
Merge pull request #2 from longway-code/fix/refine-readme
use uv for management
2 parents 753bb1a + 889d3ba commit f5f96fc

15 files changed

Lines changed: 384 additions & 371 deletions

.github/workflows/ci.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
15-
python-version: ['3.8', '3.9', '3.10', '3.11']
15+
python-version: ['3.10', '3.11', '3.12', '3.13']
1616

1717
steps:
1818
- uses: actions/checkout@v3
@@ -22,19 +22,15 @@ jobs:
2222
with:
2323
python-version: ${{ matrix.python-version }}
2424

25-
- name: Cache pip packages
26-
uses: actions/cache@v3
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v5
2727
with:
28-
path: ~/.cache/pip
29-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
30-
restore-keys: |
31-
${{ runner.os }}-pip-
28+
enable-cache: true
3229

3330
- name: Install dependencies
3431
run: |
35-
python -m pip install --upgrade pip
36-
pip install -e .
37-
pip install -r requirements-dev.txt
32+
uv pip install --system -e .
33+
uv pip install --system -r requirements-dev.txt
3834
3935
- name: Lint with flake8
4036
run: |
@@ -79,10 +75,12 @@ jobs:
7975
with:
8076
python-version: '3.10'
8177

78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v5
80+
8281
- name: Install build dependencies
8382
run: |
84-
python -m pip install --upgrade pip
85-
pip install build twine
83+
uv pip install --system build twine
8684
8785
- name: Build package
8886
run: |

CONTRIBUTING.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,45 @@ Enhancement suggestions are tracked as GitHub issues. When creating an enhanceme
3939

4040
## Development Setup
4141

42+
### Prerequisites
43+
44+
- Python 3.10 or higher
45+
- [uv](https://github.com/astral-sh/uv) package manager
46+
47+
### Setup Steps
48+
4249
1. Clone your fork:
4350
```bash
4451
git clone https://github.com/yourusername/ContrastCheck.git
4552
cd ContrastCheck
4653
```
4754

48-
2. Create a virtual environment:
55+
2. Install uv if you haven't already:
4956
```bash
50-
python -m venv venv
51-
source venv/bin/activate # On Windows: venv\Scripts\activate
57+
# On macOS and Linux
58+
curl -LsSf https://astral.sh/uv/install.sh | sh
59+
60+
# On Windows
61+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
62+
```
63+
64+
3. Create a virtual environment with Python 3.10+:
65+
```bash
66+
uv venv --python 3.10
67+
```
68+
69+
4. Activate the virtual environment:
70+
```bash
71+
# On macOS/Linux:
72+
source .venv/bin/activate
73+
74+
# On Windows:
75+
.venv\Scripts\activate
5276
```
5377

54-
3. Install development dependencies:
78+
5. Install development dependencies:
5579
```bash
56-
pip install -e .
57-
pip install -r requirements-dev.txt
80+
uv pip install -e ".[dev]"
5881
```
5982

6083
## Coding Standards

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
.PHONY: help install install-dev test test-cov lint format clean build upload docs
1+
.PHONY: help venv install install-dev test test-cov lint format clean build upload docs
22

33
help:
44
@echo "ContrastCheck - Development Commands"
55
@echo ""
66
@echo "Available targets:"
7+
@echo " venv - Create virtual environment with uv"
78
@echo " install - Install package in production mode"
89
@echo " install-dev - Install package with development dependencies"
910
@echo " test - Run tests with pytest"
@@ -15,12 +16,17 @@ help:
1516
@echo " upload - Upload package to PyPI"
1617
@echo " docs - Generate documentation"
1718

19+
venv:
20+
uv venv --python 3.10
21+
@echo "Virtual environment created. Activate it with:"
22+
@echo " source .venv/bin/activate (macOS/Linux)"
23+
@echo " .venv\\Scripts\\activate (Windows)"
24+
1825
install:
19-
pip install -e .
26+
uv pip install -e .
2027

2128
install-dev:
22-
pip install -e .
23-
pip install -r requirements-dev.txt
29+
uv pip install -e ".[dev]"
2430

2531
test:
2632
pytest

README.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ContrastCheck
22

3-
[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
3+
[![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

66
A powerful tool for analyzing text-background contrast ratios in UI screenshots using PaddleOCR and K-means clustering to ensure WCAG accessibility compliance.
@@ -18,36 +18,60 @@ A powerful tool for analyzing text-background contrast ratios in UI screenshots
1818

1919
### Prerequisites
2020

21-
- Python 3.8 or higher
22-
- pip package manager
21+
- Python 3.10 or higher
22+
- [uv](https://github.com/astral-sh/uv) - Fast Python package and project manager
2323

24-
### Install from source
24+
### Install uv
25+
26+
If you don't have uv installed:
2527

2628
```bash
27-
git clone https://github.com/longweillw-blip/ContrastCheck.git
28-
cd ContrastCheck
29-
pip install -e .
29+
# On macOS and Linux
30+
curl -LsSf https://astral.sh/uv/install.sh | sh
31+
32+
# On Windows
33+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
34+
35+
# Or via pip
36+
pip install uv
3037
```
3138

32-
### Install dependencies
39+
### Install from source
3340

3441
```bash
35-
pip install -r requirements.txt
42+
git clone https://github.com/longway-code/ContrastCheck.git
43+
cd ContrastCheck
44+
45+
# Create virtual environment with uv (Python 3.10+)
46+
uv venv --python 3.10
47+
48+
# Activate virtual environment
49+
# On macOS/Linux:
50+
source .venv/bin/activate
51+
# On Windows:
52+
.venv\Scripts\activate
53+
54+
# Install the package
55+
uv pip install -e .
3656
```
3757

38-
For development:
58+
### Install dependencies
3959

4060
```bash
41-
pip install -r requirements-dev.txt
61+
# Production dependencies
62+
uv pip install -r requirements.txt
63+
64+
# Development dependencies
65+
uv pip install -r requirements-dev.txt
4266
```
4367

4468
### GPU Support (Optional)
4569

4670
For faster OCR processing with GPU:
4771

4872
```bash
49-
pip uninstall paddlepaddle
50-
pip install paddlepaddle-gpu
73+
uv pip uninstall paddlepaddle
74+
uv pip install paddlepaddle-gpu
5175
```
5276

5377
## Quick Start
@@ -227,6 +251,19 @@ ContrastCheck/
227251

228252
## Development
229253

254+
### Setup Development Environment
255+
256+
```bash
257+
# Create virtual environment with Python 3.10+
258+
uv venv --python 3.10
259+
260+
# Activate virtual environment
261+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
262+
263+
# Install in development mode with dev dependencies
264+
uv pip install -e ".[dev]"
265+
```
266+
230267
### Running Tests
231268

232269
Run all tests:
@@ -310,15 +347,15 @@ If you use ContrastCheck in your research or project, please cite:
310347
title = {ContrastCheck: UI Screenshot Contrast Ratio Analyzer},
311348
author = {ContrastCheck Contributors},
312349
year = {2026},
313-
url = {https://github.com/longweillw-blip/ContrastCheck}
350+
url = {https://github.com/longway-code/ContrastCheck}
314351
}
315352
```
316353

317354
## Support
318355

319356
If you encounter any issues or have questions:
320357

321-
- Open an issue on [GitHub](https://github.com/yourusername/ContrastCheck/issues)
358+
- Open an issue on [GitHub](https://github.com/longway-code/ContrastCheck/issues)
322359
- Check the [examples](examples/) directory for usage examples
323360
- Read the [WCAG 2.1 documentation](https://www.w3.org/WAI/WCAG21/quickref/) for accessibility guidelines
324361

contrast_check/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
__version__ = "0.1.0"
99
__author__ = "ContrastCheck Contributors"
1010

11-
from .ocr_extractor import OCRExtractor
1211
from .color_extractor import ColorExtractor
1312
from .contrast_checker import ContrastChecker
13+
from .ocr_extractor import OCRExtractor
1414

1515
__all__ = ["OCRExtractor", "ColorExtractor", "ContrastChecker"]

contrast_check/color_extractor.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Color extraction module using K-means clustering.
33
"""
44

5-
import numpy as np
6-
from typing import Tuple, List
7-
from PIL import Image
5+
from typing import List, Tuple
6+
87
import cv2
8+
import numpy as np
99
from sklearn.cluster import KMeans
1010

1111

@@ -26,9 +26,7 @@ def __init__(self, n_text_colors: int = 3, n_bg_colors: int = 3):
2626
self.n_bg_colors = n_bg_colors
2727

2828
def extract_text_color(
29-
self,
30-
image: np.ndarray,
31-
text_mask: np.ndarray
29+
self, image: np.ndarray, text_mask: np.ndarray
3230
) -> Tuple[int, int, int]:
3331
"""
3432
Extract dominant text color from the masked region.
@@ -48,15 +46,14 @@ def extract_text_color(
4846

4947
# Convert BGR to RGB
5048
text_pixels_rgb = cv2.cvtColor(
51-
text_pixels.reshape(-1, 1, 3),
52-
cv2.COLOR_BGR2RGB
49+
text_pixels.reshape(-1, 1, 3), cv2.COLOR_BGR2RGB
5350
).reshape(-1, 3)
5451

5552
# Use K-means to find dominant colors
5653
kmeans = KMeans(
5754
n_clusters=min(self.n_text_colors, len(text_pixels)),
5855
random_state=42,
59-
n_init=10
56+
n_init=10,
6057
)
6158
kmeans.fit(text_pixels_rgb)
6259

@@ -73,7 +70,7 @@ def extract_background_color(
7370
image: np.ndarray,
7471
text_mask: np.ndarray,
7572
bbox: List[List[float]],
76-
margin: int = 10
73+
margin: int = 10,
7774
) -> Tuple[int, int, int]:
7875
"""
7976
Extract background color around the text region.
@@ -109,15 +106,12 @@ def extract_background_color(
109106

110107
# Convert BGR to RGB
111108
bg_pixels_rgb = cv2.cvtColor(
112-
bg_pixels.reshape(-1, 1, 3),
113-
cv2.COLOR_BGR2RGB
109+
bg_pixels.reshape(-1, 1, 3), cv2.COLOR_BGR2RGB
114110
).reshape(-1, 3)
115111

116112
# Use K-means to find dominant colors
117113
kmeans = KMeans(
118-
n_clusters=min(self.n_bg_colors, len(bg_pixels)),
119-
random_state=42,
120-
n_init=10
114+
n_clusters=min(self.n_bg_colors, len(bg_pixels)), random_state=42, n_init=10
121115
)
122116
kmeans.fit(bg_pixels_rgb)
123117

@@ -140,4 +134,4 @@ def rgb_to_hex(rgb: Tuple[int, int, int]) -> str:
140134
Returns:
141135
Hex color code string
142136
"""
143-
return '#{:02x}{:02x}{:02x}'.format(int(rgb[0]), int(rgb[1]), int(rgb[2]))
137+
return "#{:02x}{:02x}{:02x}".format(int(rgb[0]), int(rgb[1]), int(rgb[2]))

0 commit comments

Comments
 (0)