Skip to content

Commit c51b19d

Browse files
committed
chore: enforce strict CI checks and typing
1 parent b926241 commit c51b19d

25 files changed

Lines changed: 781 additions & 295 deletions

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
checks:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.13"
19+
20+
- name: Set up uv
21+
uses: astral-sh/setup-uv@v5
22+
with:
23+
enable-cache: true
24+
25+
- name: Install project dependencies
26+
run: uv sync --frozen
27+
28+
- name: Install tooling
29+
run: |
30+
uv pip install \
31+
ruff \
32+
mypy \
33+
pytest \
34+
pytest-cov \
35+
pip-audit \
36+
pydantic
37+
38+
- name: Ruff format check
39+
run: uv run ruff format --check
40+
41+
- name: Ruff lint
42+
run: uv run ruff check
43+
44+
- name: Mypy
45+
run: uv run mypy src
46+
47+
- name: Pytest
48+
run: uv run pytest
49+
50+
- name: Dependency security audit
51+
run: uv run pip-audit

.github/workflows/release.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
checks:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.13"
19+
20+
- name: Set up uv
21+
uses: astral-sh/setup-uv@v5
22+
with:
23+
enable-cache: true
24+
25+
- name: Install project dependencies
26+
run: uv sync --frozen
27+
28+
- name: Install tooling
29+
run: |
30+
uv pip install \
31+
ruff \
32+
mypy \
33+
pytest \
34+
pytest-cov \
35+
pip-audit \
36+
pydantic
37+
38+
- name: Ruff format check
39+
run: uv run ruff format --check
40+
41+
- name: Ruff lint
42+
run: uv run ruff check
43+
44+
- name: Mypy
45+
run: uv run mypy src
46+
47+
- name: Pytest
48+
run: uv run pytest
49+
50+
- name: Dependency security audit
51+
run: uv run pip-audit
52+
53+
publish:
54+
needs: checks
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
61+
62+
- name: Create GitHub release
63+
uses: softprops/action-gh-release@v2
64+
with:
65+
generate_release_notes: true

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
A user-friendly tool for removing image backgrounds with multiple methods and a guided flow. It is designed for batch processing and for handling both everyday photos and green-screen shots.
66

7+
## Installation
8+
- Make sure Python 3.13 and `uv` are available.
9+
- Clone the repository and install dependencies.
10+
11+
```bash
12+
git clone <repository-url>
13+
cd Remove-Background
14+
uv sync
15+
```
16+
17+
## How to Use
18+
- Start the interactive flow and follow the prompts.
19+
- Outputs are saved as transparent PNGs in an `output/` folder under the selected directory.
20+
21+
```bash
22+
uv run main.py
23+
```
24+
725
## Usage Options
826
- Guided interactive flow: select a folder, pick a removal method, adjust strength, and confirm before processing.
927
- Green-screen workflow: optimized for solid green backdrops to clean edges and reduce color spill.

docs/README.ja.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
複数の方式とガイド付きの流れを備えた、使いやすい背景除去ツールです。まとめて処理したい場合や、一般写真・グリーンスクリーン写真の両方に対応します。
66

7+
## インストール
8+
- Python 3.13 と `uv` を用意してください。
9+
- リポジトリを取得して依存関係をインストールします。
10+
11+
```bash
12+
git clone <repository-url>
13+
cd Remove-Background
14+
uv sync
15+
```
16+
17+
## 使い方
18+
- 対話フローを起動して案内に従います。
19+
- 出力は透明 PNG で、選択したフォルダ配下の `output/` に保存されます。
20+
21+
```bash
22+
uv run main.py
23+
```
24+
725
## 利用オプション
826
- ガイド付きの対話的な流れ:フォルダを選択し、方式を選び、強さを調整してから確認して処理します。
927
- グリーンスクリーン向け:単色の緑背景に最適化し、縁をきれいにし色かぶりを抑えます。

docs/README.zh-CN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
这是一款易用的图片去背工具,提供多种方案与引导式流程,适合批量处理,也能应付普通照片与绿幕照片。
66

7+
## 安装
8+
- 确认 Python 3.13 与 `uv` 可用。
9+
- 下载项目并安装依赖。
10+
11+
```bash
12+
git clone <repository-url>
13+
cd Remove-Background
14+
uv sync
15+
```
16+
17+
## 使用方法
18+
- 启动交互流程并按提示操作。
19+
- 输出为透明 PNG,保存在所选文件夹的 `output/` 内。
20+
21+
```bash
22+
uv run main.py
23+
```
24+
725
## 使用方案
826
- 引导式流程:选择文件夹、选择方案、调整强度、确认后开始处理。
927
- 绿幕流程:适合纯绿背景,让边缘更干净并减少色彩残留。

docs/README.zh-TW.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
這是一款易用的圖片去背工具,提供多種方案與引導式流程,適合批次處理,也能應付一般照片與綠幕照片。
66

7+
## 安裝
8+
- 確認 Python 3.13 與 `uv` 可用。
9+
- 下載專案並安裝相依套件。
10+
11+
```bash
12+
git clone <repository-url>
13+
cd Remove-Background
14+
uv sync
15+
```
16+
17+
## 使用方法
18+
- 啟動互動流程並依提示操作。
19+
- 輸出為透明 PNG,存放在所選資料夾的 `output/` 內。
20+
21+
```bash
22+
uv run main.py
23+
```
24+
725
## 使用方案
826
- 引導式流程:選擇資料夾、選擇方案、調整強度、確認後開始處理。
927
- 綠幕流程:適合純綠背景,讓邊緣更乾淨並減少色彩殘留。

main.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
uv run main.py
1010
"""
1111

12+
import logging
1213
import sys
1314

14-
from src.core.processor import ImageProcessor
1515
from src.backends import BackendRegistry
16+
from src.core.processor import ImageProcessor
1617
from src.ui import InteractiveUI
1718

1819

@@ -23,6 +24,7 @@ def main() -> int:
2324
Returns:
2425
退出碼 (0: 成功, 1: 失敗或取消)
2526
"""
27+
logging.basicConfig(level=logging.INFO, format="%(message)s")
2628
try:
2729
# 1. 建立 UI
2830
ui = InteractiveUI()
@@ -49,16 +51,18 @@ def main() -> int:
4951
ui.show_result(result)
5052
ui.wait_for_exit()
5153

52-
return 0 if result.is_complete_success else 1
53-
5454
except KeyboardInterrupt:
55-
print("\n\n已取消")
55+
sys.stdout.write("\n\n已取消\n")
56+
sys.stdout.flush()
5657
return 1
5758

58-
except Exception as e:
59-
print(f"\n錯誤: {e}", file=sys.stderr)
59+
except Exception as exc:
60+
sys.stderr.write(f"\n錯誤: {exc}\n")
61+
sys.stderr.flush()
6062
return 1
63+
else:
64+
return 0 if result.is_complete_success else 1
6165

6266

63-
if __name__ == '__main__':
67+
if __name__ == "__main__":
6468
sys.exit(main())

0 commit comments

Comments
 (0)