Skip to content

Commit bb58b8d

Browse files
authored
Merge pull request #16 from LiberiFatali/chore/uv-idiomatic
refactor(uv): make uv usage idiomatic (hatchling, dependency-groups, Docker, docs)
2 parents 9806196 + 12e7695 commit bb58b8d

9 files changed

Lines changed: 81 additions & 65 deletions

File tree

‎.DS_Store‎

-6 KB
Binary file not shown.

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
timeout-minutes: 20
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919
with:
2020
fetch-depth: 0
2121

@@ -24,17 +24,17 @@ jobs:
2424
enable-cache: true
2525

2626
- name: Install dependencies
27-
run: uv sync --frozen --extra dev
27+
run: uv sync --frozen
2828

2929
- name: Run tests
30-
run: uv run pytest -p no:cacheprovider -o addopts="" tests/ -q
30+
run: uv run pytest --cov=codewiki --cov-report=term-missing -p no:cacheprovider tests/ -q
3131

3232
lint:
3333
name: Lint
3434
runs-on: ubuntu-latest
3535
timeout-minutes: 10
3636
steps:
37-
- uses: actions/checkout@v4
37+
- uses: actions/checkout@v5
3838
with:
3939
fetch-depth: 0
4040

@@ -43,7 +43,7 @@ jobs:
4343
enable-cache: true
4444

4545
- name: Install dependencies
46-
run: uv sync --frozen --extra dev
46+
run: uv sync --frozen
4747

4848
- name: Collect changed Python files
4949
env:

‎.gitignore‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ MANIFEST
3838
htmlcov/
3939
.tox/
4040
.hypothesis/
41-
tests/*
42-
!tests/test_latest_compat.py
43-
!tests/test_review_changes.py
4441

4542
# Jupyter
4643
*.ipynb

‎.python-version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.12.13

‎README.md‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ pip install codewiki-plus
9898
codewiki --version
9999
```
100100

101-
> **开发者选项**:如需从源码开发(获取最新未发布改动),推荐使用 [uv](https://docs.astral.sh/uv/) 按 `uv.lock` 精确复现开发环境:
101+
> **开发者选项**:如需从源码开发(获取最新未发布改动),推荐使用 [uv](https://docs.astral.sh/uv/) 按 `uv.lock` 精确复现开发环境(`pyproject.toml:106` `tool.uv.default-groups = ["dev"]` 已包含 dev 工具):
102102
> ```bash
103103
> git clone https://github.com/mambo-wang/CodeWiki-Plus.git
104104
> cd CodeWiki-Plus
105-
> uv sync --frozen --extra dev # 按 uv.lock 复现完整开发环境(含 dev 依赖)
106-
> uv run codewiki --version # 通过 uv 环境运行 CLI
107-
> uv run pytest tests/ -q -o addopts="" # 运行测试(仓库未装 pytest-cov,须禁用 addopts 默认值)
105+
> uv sync --frozen # 按 uv.lock 复现完整开发环境(含 dev 依赖,hatchling 构建)
106+
> uv run codewiki --version # 通过 uv 环境运行 CLI
107+
> uv run pytest tests/ -q # 运行测试(addopts 已移除 --cov,无需覆盖)
108+
> # 需要覆盖率时:uv run pytest --cov=codewiki --cov-report=term-missing
108109
> ```
109-
> 没有 uv 时也可 `pip install -e .`,但依赖解析不受 `uv.lock` 锁定。
110+
> 没有 uv 时也可 `pip install -e .[dev]`,但依赖解析不受 `uv.lock` 锁定。
110111
111112
**第 2 步:配置 MCP Server**
112113
@@ -832,15 +833,16 @@ Verify:
832833
codewiki --version
833834
```
834835

835-
> **For developers** (latest unreleased changes) — [uv](https://docs.astral.sh/uv/) is recommended to reproduce the dev environment exactly as locked by `uv.lock`:
836+
> **For developers** (latest unreleased changes) — [uv](https://docs.astral.sh/uv/) is recommended to reproduce the dev environment exactly as locked by `uv.lock` (`tool.uv.default-groups = ["dev"]` includes dev tools):
836837
> ```bash
837838
> git clone https://github.com/mambo-wang/CodeWiki-Plus.git
838839
> cd CodeWiki-Plus
839-
> uv sync --frozen --extra dev # reproduce the full dev environment from uv.lock (incl. dev extras)
840-
> uv run codewiki --version # run the CLI inside the uv-managed environment
841-
> uv run pytest tests/ -q -o addopts="" # run tests (pytest-cov isn't installed; disable default addopts)
840+
> uv sync --frozen # reproduce the full dev environment from uv.lock (hatchling build)
841+
> uv run codewiki --version # run the CLI inside the uv-managed environment
842+
> uv run pytest tests/ -q # run tests (no --cov in addopts; no override needed)
843+
> # with coverage: uv run pytest --cov=codewiki --cov-report=term-missing
842844
> ```
843-
> Without uv, `pip install -e .` still works, but dependency resolution is not locked by `uv.lock`.
845+
> Without uv, `pip install -e .[dev]` still works, but dependency resolution is not locked by `uv.lock`.
844846
845847
**Step 2: Configure MCP Server**
846848

‎docker/DOCKER_README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ The Dockerfile (`docker/Dockerfile`) builds the CodeWiki image with:
143143
- `nodejs` and `npm` - For mermaid diagram validation
144144

145145
### Application Setup
146-
1. Copies `pyproject.toml` + `README.md` + `codewiki/` and installs dependencies via `pip install .` (deps resolved from `pyproject.toml`; no separate `requirements.txt`)
147-
2. Installs Python dependencies and the package
148-
3. Copies remaining assets
149-
4. Creates output directories:
146+
1. Copies `pyproject.toml` + `uv.lock` + `README.md` + `.python-version` and runs `uv sync --frozen --no-dev` (locked, reproducible)
147+
2. Copies `codewiki/` + `img/` and runs `uv sync --frozen --no-dev` to install the project
148+
3. Creates output directories:
150149
- `output/cache`
151150
- `output/temp`
152151
- `output/docs`

‎docker/Dockerfile‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
# Use Python 3.12 slim image as base
2-
FROM python:3.12-slim
1+
# uv-based image: uv binary + Python 3.12 (Debian) in one layer
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
33

44
# Set working directory
55
WORKDIR /app
66

7-
# Install system dependencies
7+
# Install system dependencies (git for cloning, nodejs for mermaid validation)
88
RUN apt-get update && apt-get install -y \
99
git \
1010
curl \
1111
nodejs \
1212
npm \
1313
&& rm -rf /var/lib/apt/lists/*
1414

15-
# Copy package source and metadata, then install
16-
COPY pyproject.toml .
17-
COPY README.md .
18-
COPY codewiki ./codewiki
15+
# Leverage Docker layer cache: copy only dependency manifests first
16+
COPY pyproject.toml uv.lock README.md .python-version ./
1917

20-
# Install Python dependencies and package
21-
RUN pip install --no-cache-dir .
18+
# Install locked runtime deps into .venv without the project itself
19+
RUN uv sync --frozen --no-install-project --no-group dev
2220

23-
# Copy remaining assets
21+
# Copy project source
22+
COPY codewiki ./codewiki
2423
COPY img ./img
2524

25+
# Install the project itself (still frozen, no dev extras)
26+
RUN uv sync --frozen --no-group dev
27+
2628
# Create output directories
2729
RUN mkdir -p output/cache output/temp output/docs output/dependency_graphs
2830

29-
# Set environment variables
30-
ENV PYTHONPATH=/app
31+
# Make the uv-managed venv the default PATH so `codewiki` / `python` resolve there
32+
ENV PATH="/app/.venv/bin:$PATH"
3133
ENV PYTHONUNBUFFERED=1
3234

3335
# Expose port
@@ -37,5 +39,5 @@ EXPOSE 8000
3739
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
3840
CMD curl -f http://localhost:8000/ || exit 1
3941

40-
# Default command
42+
# Default command (uses venv python)
4143
CMD ["python", "codewiki/run_web_app.py", "--host", "0.0.0.0", "--port", "8000"]

‎pyproject.toml‎

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
requires = ["setuptools>=68.0.0", "wheel"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "codewiki-plus"
@@ -65,6 +65,17 @@ dependencies = [
6565
"pathspec>=0.12.1"
6666
]
6767

68+
[dependency-groups]
69+
dev = [
70+
"pytest>=7.4.0",
71+
"pytest-cov>=4.1.0",
72+
"pytest-asyncio>=0.21.0",
73+
"black>=23.0.0",
74+
"mypy>=1.5.0",
75+
"ruff>=0.1.0",
76+
]
77+
78+
# Keep pip-compatible extra for `pip install -e .[dev]` fallback (uv canonical is dependency-groups above)
6879
[project.optional-dependencies]
6980
dev = [
7081
"pytest>=7.4.0",
@@ -84,31 +95,15 @@ Documentation = "https://github.com/mambo-wang/CodeWiki-Plus/blob/main/README.md
8495
Repository = "https://github.com/mambo-wang/CodeWiki-Plus"
8596
Issues = "https://github.com/mambo-wang/CodeWiki-Plus/issues"
8697

87-
[tool.setuptools]
88-
packages = [
89-
"codewiki",
90-
"codewiki.cli",
91-
"codewiki.cli.commands",
92-
"codewiki.cli.models",
93-
"codewiki.cli.utils",
94-
"codewiki.cli.adapters",
95-
"codewiki.src",
96-
"codewiki.src.be",
97-
"codewiki.src.be.agent_tools",
98-
"codewiki.src.be.dependency_analyzer",
99-
"codewiki.src.be.dependency_analyzer.analysis",
100-
"codewiki.src.be.dependency_analyzer.analyzers",
101-
"codewiki.src.be.dependency_analyzer.analyzers.route_extractors",
102-
"codewiki.src.be.dependency_analyzer.models",
103-
"codewiki.src.be.dependency_analyzer.utils",
104-
"codewiki.src.fe",
105-
"codewiki.mcp",
106-
"codewiki.mcp.tools",
107-
"codewiki.hooks"
108-
]
98+
[tool.hatch.build]
99+
artifacts = ["codewiki/templates/**/*", "codewiki/py.typed", "codewiki/agents/**/*"]
100+
101+
[tool.hatch.build.targets.wheel]
102+
packages = ["codewiki"]
109103

110-
[tool.setuptools.package-data]
111-
codewiki = ["templates/**/*", "py.typed", "agents/*.md"]
104+
[tool.uv]
105+
managed = true
106+
default-groups = ["dev"]
112107

113108
[tool.black]
114109
line-length = 100
@@ -137,5 +132,6 @@ testpaths = ["tests"]
137132
python_files = ["test_*.py"]
138133
python_classes = ["Test*"]
139134
python_functions = ["test_*"]
140-
addopts = "-v --cov=codewiki --cov-report=term-missing"
135+
addopts = "-v"
136+
# Coverage is CI-only: `uv run pytest --cov=codewiki --cov-report=term-missing` (keeps `uv sync` without dev + local `uv run pytest -q` working without pytest-cov)
141137

‎uv.lock‎

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)