Skip to content

Commit c7cbcfe

Browse files
authored
vibe code improve (#10)
1 parent 587f268 commit c7cbcfe

18 files changed

Lines changed: 1418 additions & 99 deletions
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Test and Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'Version to publish (leave empty to use current version)'
12+
required: false
13+
type: string
14+
publish:
15+
description: 'Publish to PyPI'
16+
required: false
17+
default: false
18+
type: boolean
19+
20+
jobs:
21+
test:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
python-version: ["3.10", "3.13"]
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v3
32+
with:
33+
version: "latest"
34+
35+
- name: Set up Python ${{ matrix.python-version }}
36+
run: uv python install ${{ matrix.python-version }}
37+
38+
- name: Install dependencies
39+
run: |
40+
uv sync --dev
41+
42+
- name: Lint with ruff
43+
run: |
44+
uv run ruff check .
45+
uv run ruff format --check .
46+
47+
- name: Run tests
48+
run: |
49+
uv run pytest -v
50+
51+
- name: Upload coverage reports
52+
uses: codecov/codecov-action@v4
53+
if: matrix.python-version == '3.11'
54+
with:
55+
file: ./htmlcov/index.html
56+
fail_ci_if_error: false
57+
58+
build:
59+
needs: test
60+
runs-on: ubuntu-latest
61+
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Install uv
67+
uses: astral-sh/setup-uv@v3
68+
with:
69+
version: "latest"
70+
71+
- name: Set up Python
72+
run: uv python install 3.11
73+
74+
- name: Update version if specified
75+
if: ${{ github.event.inputs.version != '' }}
76+
run: |
77+
sed -i 's/version = "[^"]*"/version = "${{ github.event.inputs.version }}"/' pyproject.toml
78+
echo "Updated version to ${{ github.event.inputs.version }}"
79+
80+
- name: Build package
81+
run: |
82+
uv build
83+
84+
- name: Upload build artifacts
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: dist
88+
path: dist/
89+
90+
publish:
91+
needs: [test, build]
92+
runs-on: ubuntu-latest
93+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true'
94+
environment: release
95+
permissions:
96+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
97+
98+
steps:
99+
- name: Download build artifacts
100+
uses: actions/download-artifact@v4
101+
with:
102+
name: dist
103+
path: dist/
104+
105+
- name: Publish to PyPI
106+
uses: pypa/gh-action-pypi-publish@release/v1
107+
with:
108+
verbose: true

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ SHAPE is an app to play Go with AI feedback, specifically designed to point out
44

55
This is an experimental project, and is unlikely to ever become very polished.
66

7-
## Installation
7+
## Quick Start
88

9-
* Run install.sh to download the models.
10-
* Run `poetry shell` and then `poetry install` to install the app in a local Python environment.
11-
* Alternatively, run `pip install .` to install the app in your current Python environment.
9+
Run the application directly using `uvx`:
1210

13-
## Usage
11+
```bash
12+
uvx goshape
13+
```
1414

15-
* Run `shape` to start the app, or use `python shape/main.py`
15+
The first time you run this, `uv` will automatically download the package, create a virtual environment, and install all dependencies.
16+
17+
When the application starts for the first time, it will check for the required KataGo models in `~/.katrain/`. If they are not found, a dialog will appear to guide you through downloading them.
1618

1719
## Manual
1820

@@ -35,3 +37,16 @@ Note that a move being probable does not mean it is a good move.
3537
You can select multiple heatmaps to get a blended view, where size/number is the average probability, and the color is the average rank (current, target, AI).
3638

3739

40+
## TODO list from Gemini
41+
42+
Based on a code review, here are some suggested areas for improvement:
43+
44+
### High Impact
45+
- **User-Friendly Errors (`main.py`):** Show GUI dialogs for errors instead of crashing the application.
46+
47+
### Medium Impact
48+
- **Refactor `GameNode` (`game_logic.py`):** Extract board state and rule logic into a separate `Board` class to simplify `GameNode` and improve modularity.
49+
50+
### Low Impact
51+
- **Code Clarity (`game_logic.py`):** Improve code readability.
52+

install.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

pyproject.toml

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,58 @@
1-
[tool.poetry]
2-
name = "shape"
1+
[project]
2+
name = "goshape"
33
version = "0.1.0"
4-
description = ""
5-
authors = ["Sander Land"]
4+
description = "Shape Habits Analysis and Personalized Evaluation"
5+
authors = [{name = "Sander Land"}]
66
readme = "README.md"
7+
requires-python = ">=3.10,<3.14"
8+
dependencies = [
9+
"PySide6>=6.5.0",
10+
"pyqtgraph>=0.13.7",
11+
"pysgf>=0.9.0",
12+
"numpy>=2.1.2",
13+
"httpx>=0.25.0",
14+
]
715

8-
[tool.poetry.dependencies]
9-
python = "^3.10,<3.13"
10-
PySide6 = "^6.5.0"
11-
pyqtgraph = "^0.13.7"
12-
pysgf = "^0.9.0"
13-
numpy = "^2.1.2"
16+
[dependency-groups]
17+
dev = [
18+
"pytest>=7.0.0",
19+
"pytest-cov>=4.0.0",
20+
"ruff>=0.1.0",
21+
]
1422

15-
[tool.vulture]
16-
ignore_names = ["paintEvent", "keyPressEvent", "mousePressEvent"]
23+
[project.scripts]
24+
goshape = "shape.main:main"
25+
26+
[tool.hatch.build.targets.wheel]
27+
packages = ["shape"]
1728

18-
[tool.black]
29+
[tool.ruff]
1930
line-length = 120
31+
target-version = "py310"
2032

21-
[tool.isort]
22-
profile = "black"
33+
[tool.ruff.lint]
34+
select = [
35+
"E", # pycodestyle errors
36+
"W", # pycodestyle warnings
37+
"F", # pyflakes
38+
"I", # isort
39+
"B", # flake8-bugbear
40+
"C4", # flake8-comprehensions
41+
"UP", # pyupgrade
42+
]
43+
ignore = [
44+
"E501", # line too long, handled by formatter
45+
]
2346

24-
[tool.poetry.scripts]
25-
shape = "shape.main:main"
47+
[tool.ruff.format]
48+
quote-style = "double"
49+
indent-style = "space"
50+
skip-magic-trailing-comma = false
51+
line-ending = "auto"
52+
53+
[tool.vulture]
54+
ignore_names = ["paintEvent", "keyPressEvent", "mousePressEvent"]
2655

2756
[build-system]
28-
requires = ["poetry-core"]
29-
build-backend = "poetry.core.masonry.api"
57+
requires = ["hatchling"]
58+
build-backend = "hatchling.build"

shape/game_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def sample(
3737
secondary_data_data = secondary_data if secondary_data is not None else self.grid
3838
moves = [
3939
(Move(coords=(col, row)), prob, d)
40-
for row, (policy_row, secondary_data_row) in enumerate(zip(self.grid, secondary_data_data))
41-
for col, (prob, d) in enumerate(zip(policy_row, secondary_data_row))
40+
for row, (policy_row, secondary_data_row) in enumerate(zip(self.grid, secondary_data_data, strict=False))
41+
for col, (prob, d) in enumerate(zip(policy_row, secondary_data_row, strict=False))
4242
if prob > 0
4343
]
4444
if self.pass_prob > 0 and not exclude_pass:

0 commit comments

Comments
 (0)