Skip to content

Commit d01369f

Browse files
docs(docs): code quality metrics with 5 supporting modules
changes: - file: readme_gen.py area: docs modified: [ReadmeGenerator, _extract_project_metadata] stats: lines: "+58/-32 (net +26)" files: 6 complexity: "+100% complexity (monitor)"
1 parent 65364e6 commit d01369f

File tree

11 files changed

+75
-37
lines changed

11 files changed

+75
-37
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.2.7] - 2026-03-07
11+
12+
### Docs
13+
- Update code2docs/README.md
14+
- Update code2docs/docs/api.md
15+
- Update code2docs/docs/architecture.md
16+
- Update code2docs/docs/configuration.md
17+
- Update code2docs/docs/modules.md
18+
19+
### Other
20+
- Update code2docs/generators/readme_gen.py
21+
1022
## [0.2.6] - 2026-03-07
1123

1224
### Test

README.md

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

3-
![version](https://img.shields.io/badge/version-0.2.6-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![docs](https://img.shields.io/badge/docs-auto--generated-blueviolet)
3+
![version](https://img.shields.io/badge/version-0.2.7-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![docs](https://img.shields.io/badge/docs-auto--generated-blueviolet)
44

55
> Auto-generate and sync project documentation from source code analysis.
66
@@ -140,7 +140,7 @@ code2docs can update only specific sections of an existing README using markers:
140140
```markdown
141141
<!-- code2docs:start --># code2docs
142142

143-
![version](https://img.shields.io/badge/version-0.2.6-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![coverage](https://img.shields.io/badge/coverage-unknown-lightgrey) ![functions](https://img.shields.io/badge/functions-153-green)
143+
![version](https://img.shields.io/badge/version-0.2.7-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![coverage](https://img.shields.io/badge/coverage-unknown-lightgrey) ![functions](https://img.shields.io/badge/functions-153-green)
144144
> **153** functions | **30** classes | **28** files | CC̄ = 0.0
145145

146146
## Installation

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.6
1+
0.2.7

code2docs/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
> Auto-generated project documentation from source code analysis.
77
88
**Author:** Tom Softreck <tom@sapletta.com>
9-
**License:** Not specified
9+
**License:** MIT[(LICENSE)](./LICENSE)
1010
**Repository:** [https://github.com/wronai/code2docs](https://github.com/wronai/code2docs)
1111

1212
## Installation
@@ -124,6 +124,25 @@ sync:
124124
- "__pycache__"
125125
```
126126
127+
## Sync Markers
128+
129+
code2docs can update only specific sections of an existing README using HTML comment markers:
130+
131+
```markdown
132+
<!-- code2docs:start -->
133+
# Project Title
134+
... auto-generated content ...
135+
<!-- code2docs:end -->
136+
```
137+
138+
Content outside the markers is preserved when regenerating. Enable this with `sync_markers: true` in your configuration.
139+
140+
## Architecture
141+
142+
```
143+
code2docs/
144+
├── registry├── llm_helper├── code2docs/ ├── updater├── sync/ ├── watcher ├── differ ├── quickstart ├── advanced_usage ├── markdown ├── badges ├── toc├── formatters/ ├── readme_gen├── base ├── coverage_gen ├── _source_links ├── depgraph_gen ├── getting_started_gen ├── config_docs_gen ├── changelog_gen├── generators/ ├── module_docs_gen ├── api_reference_gen ├── mkdocs_gen ├── examples_gen ├── _registry_adapters├── cli ├── api_changelog_gen ├── contributing_gen├── analyzers/ ├── architecture_gen├── config ├── project_scanner ├── dependency_scanner ├── endpoint_detector ├── docstring_extractor```
145+
127146
## API Overview
128147
129148
### Classes
@@ -134,10 +153,10 @@ sync:
134153
- **`ChangeInfo`** — Describes a detected change.
135154
- **`Differ`** — Detect changes between current source and previous state.
136155
- **`MarkdownFormatter`** — Helper for constructing Markdown documents.
156+
- **`ReadmeGenerator`** — Generate README.md from AnalysisResult.
137157
- **`GenerateContext`** — Shared context passed to all generators during a run.
138158
- **`BaseGenerator`** — Abstract base for all documentation generators.
139159
- **`CoverageGenerator`** — Generate docs/coverage.md — docstring coverage report.
140-
- **`ReadmeGenerator`** — Generate README.md from AnalysisResult.
141160
- **`SourceLinker`** — Build source-code links (relative paths + optional GitHub/GitLab URLs).
142161
- **`DepGraphGenerator`** — Generate docs/dependency-graph.md with Mermaid diagrams.
143162
- **`GettingStartedGenerator`** — Generate docs/getting-started.md from entry points and dependencies.
@@ -160,11 +179,11 @@ sync:
160179
- **`GettingStartedAdapter`** — —
161180
- **`ConfigDocsAdapter`** — —
162181
- **`ContributingAdapter`** — —
182+
- **`DefaultGroup`** — Click Group that routes unknown subcommands to 'generate'.
163183
- **`ApiChange`** — A single API change between two analysis snapshots.
164184
- **`ApiChangelogGenerator`** — Generate API changelog by diffing current analysis with a saved snapshot.
165185
- **`ContributingGenerator`** — Generate CONTRIBUTING.md by detecting dev tools from pyproject.toml.
166186
- **`ArchitectureGenerator`** — Generate docs/architecture.md — architecture overview with diagrams.
167-
- **`DefaultGroup`** — Click Group that routes unknown subcommands to 'generate'.
168187
- **`ReadmeConfig`** — Configuration for README generation.
169188
- **`DocsConfig`** — Configuration for docs/ generation.
170189
- **`ExamplesConfig`** — Configuration for examples/ generation.
@@ -175,10 +194,10 @@ sync:
175194
- **`DependencyInfo`** — Information about a project dependency.
176195
- **`ProjectDependencies`** — All detected project dependencies.
177196
- **`DependencyScanner`** — Scan and parse project dependency files.
178-
- **`DocstringInfo`** — Parsed docstring with sections.
179-
- **`DocstringExtractor`** — Extract and parse docstrings from AnalysisResult.
180197
- **`Endpoint`** — Represents a detected web endpoint.
181198
- **`EndpointDetector`** — Detects web endpoints from decorator patterns in source code.
199+
- **`DocstringInfo`** — Parsed docstring with sections.
200+
- **`DocstringExtractor`** — Extract and parse docstrings from AnalysisResult.
182201
183202
### Functions
184203

code2docs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
README.md, API references, module docs, examples, and architecture diagrams.
66
"""
77

8-
__version__ = "0.2.6"
8+
__version__ = "0.2.7"
99
__author__ = "Tom Sapletta"
1010

1111
from .config import Code2DocsConfig

code2docs/docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
| Function | Signature | CC | Description | Source |
228228
|----------|-----------|----|----------- |--------|
229229
| `generate_docs` | `generate_docs(project_path, config)` | 5 | High-level function to generate all documentation. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/__init__.py#L35) |
230-
| `generate_readme` | `generate_readme(project_path, output, sections, sync_markers, ...)` | 3 | Convenience function to generate a README. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L428) |
230+
| `generate_readme` | `generate_readme(project_path, output, sections, sync_markers, ...)` | 3 | Convenience function to generate a README. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L439) |
231231

232232
### `llm_helper` [source](https://github.com/wronai/code2docs/blob/main/code2docs/llm_helper.py)
233233

@@ -540,7 +540,7 @@
540540

541541
| Function | Signature | CC | Description | Source |
542542
|----------|-----------|----|----------- |--------|
543-
| `generate_readme` | `generate_readme(project_path, output, sections, sync_markers, ...)` | 3 | Convenience function to generate a README. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L428) |
543+
| `generate_readme` | `generate_readme(project_path, output, sections, sync_markers, ...)` | 3 | Convenience function to generate a README. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L439) |
544544

545545
## sync
546546

code2docs/docs/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ classDiagram
297297
| Modules | 38 |
298298
| Functions | 229 |
299299
| Classes | 51 |
300-
| CFG Nodes | 1344 |
300+
| CFG Nodes | 1346 |
301301
| Patterns | 2 |
302302
| Avg Complexity | 4.0 |
303-
| Analysis Time | 1.31s |
303+
| Analysis Time | 1.92s |

code2docs/docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
| Option | Type | Default | Description |
2626
|--------|------|---------|-------------|
27-
| `sections` | `List` | overview, install, quickstart, generated_output, config, api, structure, requirements, contributing, docs_nav | README sections to include |
27+
| `sections` | `List` | overview, install, quickstart, generated_output, config, sync_markers, architecture, api, structure, requirements, contributing, docs_nav | README sections to include |
2828
| `badges` | `List` | version, python, coverage, complexity | Badge types to show in README header |
2929
| `sync_markers` | `bool` | true | Wrap generated content in `<!-- code2docs:start/end -->` markers |
3030

code2docs/docs/modules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| `generators.getting_started_gen` | 166 | 0 | 1 | 5.8 | Getting Started guide generator. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/getting_started_gen.py) |
3333
| `generators.mkdocs_gen` | 70 | 0 | 1 | 2.2 | MkDocs configuration generator — auto-generate mkdocs.yml fr | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/mkdocs_gen.py) |
3434
| `generators.module_docs_gen` | 198 | 0 | 1 | 8.0 | Module documentation generator — single consolidated modules | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/module_docs_gen.py) |
35-
| `generators.readme_gen` | 445 | 1 | 1 | 5.5 | README.md generator from AnalysisResult. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py) |
35+
| `generators.readme_gen` | 456 | 1 | 1 | 5.7 | README.md generator from AnalysisResult. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py) |
3636
| `llm_helper` | 161 | 1 | 1 | 2.3 | LLM helper — optional LLM-assisted documentation generation | [source](https://github.com/wronai/code2docs/blob/main/code2docs/llm_helper.py) |
3737
| `registry` | 39 | 0 | 1 | 2.5 | Generator registry — pluggable generator system. | [source](https://github.com/wronai/code2docs/blob/main/code2docs/registry.py) |
3838
| `sync.differ` | 125 | 0 | 2 | 3.6 | Detect changes in source code for selective documentation re | [source](https://github.com/wronai/code2docs/blob/main/code2docs/sync/differ.py) |
@@ -494,7 +494,7 @@ README.md generator from AnalysisResult.
494494
| `generate` | `` | `` | 3 |
495495
| `write` | `path, content` | `` | 4 |
496496

497-
- `generate_readme(project_path, output, sections, sync_markers, config)` — Convenience function to generate a README. [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L428)
497+
- `generate_readme(project_path, output, sections, sync_markers, config)` — Convenience function to generate a README. [source](https://github.com/wronai/code2docs/blob/main/code2docs/generators/readme_gen.py#L439)
498498

499499
## sync
500500

code2docs/generators/readme_gen.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,34 @@ def _extract_project_metadata(self) -> Dict:
192192
# Try pyproject.toml
193193
try:
194194
import tomllib
195-
pyproject_path = Path(self.result.project_path) / "pyproject.toml"
196-
if pyproject_path.exists():
197-
with open(pyproject_path, "rb") as f:
198-
data = tomllib.load(f)
199-
200-
project = data.get("project", {})
201-
metadata["version"] = project.get("version", metadata["version"])
202-
203-
# Authors
204-
authors = project.get("authors", [])
205-
if authors:
206-
if isinstance(authors[0], dict):
207-
metadata["author"] = authors[0].get("name", "")
208-
metadata["contributors"] = [a.get("name", "") for a in authors[1:] if a.get("name")]
195+
pyproject_paths = [
196+
Path(self.result.project_path) / "pyproject.toml",
197+
Path(self.result.project_path).parent / "pyproject.toml",
198+
]
199+
for pyproject_path in pyproject_paths:
200+
if pyproject_path.exists():
201+
with open(pyproject_path, "rb") as f:
202+
data = tomllib.load(f)
203+
204+
project = data.get("project", {})
205+
metadata["version"] = project.get("version", metadata["version"])
206+
207+
# Authors
208+
authors = project.get("authors", [])
209+
if authors:
210+
if isinstance(authors[0], dict):
211+
metadata["author"] = authors[0].get("name", "")
212+
metadata["contributors"] = [a.get("name", "") for a in authors[1:] if a.get("name")]
213+
else:
214+
metadata["author"] = str(authors[0])
215+
216+
# License
217+
lic = project.get("license", {})
218+
if isinstance(lic, dict):
219+
metadata["license"] = lic.get("text", "")
209220
else:
210-
metadata["author"] = str(authors[0])
211-
212-
# License
213-
metadata["license"] = project.get("license", {}).get("text", "")
214-
if not metadata["license"]:
215-
metadata["license"] = project.get("license", "")
221+
metadata["license"] = lic
222+
break
216223
except Exception:
217224
pass
218225

0 commit comments

Comments
 (0)