code2docs 3.0.3__tar.gz → 3.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {code2docs-3.0.3 → code2docs-3.0.5}/PKG-INFO +3 -3
- {code2docs-3.0.3 → code2docs-3.0.5}/README.md +2 -2
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/__init__.py +1 -1
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/cli.py +4 -1
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/config.py +1 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/_registry_adapters.py +30 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/examples_gen.py +21 -15
- code2docs-3.0.5/code2docs/generators/org_readme_gen.py +227 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/PKG-INFO +3 -3
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/SOURCES.txt +1 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/pyproject.toml +1 -1
- {code2docs-3.0.3 → code2docs-3.0.5}/LICENSE +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/__main__.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/analyzers/__init__.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/analyzers/dependency_scanner.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/analyzers/docstring_extractor.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/analyzers/endpoint_detector.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/analyzers/project_scanner.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/base.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/examples/advanced_usage.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/examples/quickstart.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/formatters/__init__.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/formatters/badges.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/formatters/markdown.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/formatters/toc.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/__init__.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/_source_links.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/api_changelog_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/api_reference_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/architecture_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/changelog_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/code2llm_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/config_docs_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/contributing_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/coverage_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/depgraph_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/getting_started_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/mkdocs_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/module_docs_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/generators/readme_gen.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/llm_helper.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/registry.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/sync/__init__.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/sync/differ.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/sync/updater.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/sync/watcher.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/api_module.md.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/architecture.md.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/example_usage.py.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/index.md.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/module_doc.md.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs/templates/readme.md.j2 +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/dependency_links.txt +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/entry_points.txt +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/requires.txt +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/code2docs.egg-info/top_level.txt +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/setup.cfg +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_analyzers.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_cli.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_code2docs.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_config.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_formatters.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_generators.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_llm_helper.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_registry.py +0 -0
- {code2docs-3.0.3 → code2docs-3.0.5}/tests/test_sync.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code2docs
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.5
|
|
4
4
|
Summary: Auto-generate and sync project documentation from source code analysis
|
|
5
5
|
Author-email: Tom Sapletta <tom@sapletta.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -50,7 +50,7 @@ Dynamic: license-file
|
|
|
50
50
|
|
|
51
51
|
# code2docs
|
|
52
52
|
|
|
53
|
-
  
|
|
54
54
|
|
|
55
55
|
> Auto-generate and sync project documentation from source code analysis.
|
|
56
56
|
|
|
@@ -190,7 +190,7 @@ code2docs can update only specific sections of an existing README using markers:
|
|
|
190
190
|
```markdown
|
|
191
191
|
<!-- code2docs:start --># code2docs
|
|
192
192
|
|
|
193
|
-
   
|
|
194
194
|
> **276** functions | **57** classes | **51** files | CC̄ = 3.8
|
|
195
195
|
|
|
196
196
|
> Auto-generated project documentation from source code analysis.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# code2docs
|
|
2
2
|
|
|
3
|
-
  
|
|
4
4
|
|
|
5
5
|
> Auto-generate and sync project documentation from source code analysis.
|
|
6
6
|
|
|
@@ -140,7 +140,7 @@ code2docs can update only specific sections of an existing README using markers:
|
|
|
140
140
|
```markdown
|
|
141
141
|
<!-- code2docs:start --># code2docs
|
|
142
142
|
|
|
143
|
-
   
|
|
144
144
|
> **276** functions | **57** classes | **51** files | CC̄ = 3.8
|
|
145
145
|
|
|
146
146
|
> Auto-generated project documentation from source code analysis.
|
|
@@ -5,7 +5,7 @@ Uses code2llm's AnalysisResult to produce human-readable documentation:
|
|
|
5
5
|
README.md, API references, module docs, examples, and architecture diagrams.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "3.0.
|
|
8
|
+
__version__ = "3.0.5"
|
|
9
9
|
__author__ = "Tom Sapletta"
|
|
10
10
|
|
|
11
11
|
from .config import Code2DocsConfig
|
|
@@ -40,8 +40,9 @@ def main():
|
|
|
40
40
|
@click.option("--dry-run", is_flag=True, help="Show what would be generated without writing")
|
|
41
41
|
@click.option("--llm", "llm_model", default=None,
|
|
42
42
|
help="Enable LLM-assisted generation (e.g. openai/gpt-4o-mini, ollama/llama3)")
|
|
43
|
+
@click.option("--org-name", default=None, help="Organization name for org-mode README generation")
|
|
43
44
|
def generate(project_path, config_path, readme_only, sections, output, verbose, dry_run,
|
|
44
|
-
llm_model):
|
|
45
|
+
llm_model, org_name):
|
|
45
46
|
"""Generate documentation (default command)."""
|
|
46
47
|
config = _load_config(project_path, config_path)
|
|
47
48
|
if verbose:
|
|
@@ -53,6 +54,8 @@ def generate(project_path, config_path, readme_only, sections, output, verbose,
|
|
|
53
54
|
if llm_model:
|
|
54
55
|
config.llm.enabled = True
|
|
55
56
|
config.llm.model = llm_model
|
|
57
|
+
if org_name:
|
|
58
|
+
config.org_name = org_name
|
|
56
59
|
|
|
57
60
|
_run_generate(project_path, config, readme_only=readme_only, dry_run=dry_run)
|
|
58
61
|
|
|
@@ -108,6 +108,7 @@ class Code2DocsConfig:
|
|
|
108
108
|
output: str = "./docs/"
|
|
109
109
|
readme_output: str = "./README.md"
|
|
110
110
|
repo_url: str = "" # GitHub/GitLab URL for source links (auto-detected from git)
|
|
111
|
+
org_name: str = "" # Organization name for org-mode README generation
|
|
111
112
|
|
|
112
113
|
readme: ReadmeConfig = field(default_factory=ReadmeConfig)
|
|
113
114
|
docs: DocsConfig = field(default_factory=DocsConfig)
|
|
@@ -240,6 +240,35 @@ class Code2LlmAdapter(BaseGenerator):
|
|
|
240
240
|
return "⚠️ project/ (no files generated)"
|
|
241
241
|
|
|
242
242
|
|
|
243
|
+
class OrgReadmeAdapter(BaseGenerator):
|
|
244
|
+
"""Adapter for organization README generation."""
|
|
245
|
+
name = "org_readme"
|
|
246
|
+
|
|
247
|
+
def should_run(self, *, readme_only: bool = False) -> bool:
|
|
248
|
+
# Only run if org_name is set in config
|
|
249
|
+
return hasattr(self.config, 'org_name') and bool(self.config.org_name)
|
|
250
|
+
|
|
251
|
+
def run(self, ctx: GenerateContext) -> Optional[str]:
|
|
252
|
+
from .org_readme_gen import OrgReadmeGenerator
|
|
253
|
+
|
|
254
|
+
org_name = getattr(self.config, 'org_name', '')
|
|
255
|
+
if not org_name:
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
gen = OrgReadmeGenerator(self.config, str(ctx.project), org_name)
|
|
259
|
+
content = gen.generate()
|
|
260
|
+
|
|
261
|
+
if ctx.dry_run:
|
|
262
|
+
click.echo(f"\n--- {org_name} README ({len(content)} chars) ---")
|
|
263
|
+
preview = content[:500] + "..." if len(content) > 500 else content
|
|
264
|
+
click.echo(preview)
|
|
265
|
+
return None
|
|
266
|
+
|
|
267
|
+
readme_path = ctx.docs_dir / "README.md"
|
|
268
|
+
gen.write(str(readme_path), content)
|
|
269
|
+
return f"✅ {readme_path.relative_to(ctx.project)}"
|
|
270
|
+
|
|
271
|
+
|
|
243
272
|
ALL_ADAPTERS = [
|
|
244
273
|
ReadmeGeneratorAdapter,
|
|
245
274
|
ApiReferenceAdapter,
|
|
@@ -254,4 +283,5 @@ ALL_ADAPTERS = [
|
|
|
254
283
|
ContributingAdapter,
|
|
255
284
|
MkDocsAdapter,
|
|
256
285
|
Code2LlmAdapter,
|
|
286
|
+
OrgReadmeAdapter,
|
|
257
287
|
]
|
|
@@ -138,15 +138,18 @@ class ExamplesGenerator:
|
|
|
138
138
|
|
|
139
139
|
# --- Example 1: Config (define first so later examples can use it) ---
|
|
140
140
|
config_cls = self._find_class_by_name("Code2DocsConfig")
|
|
141
|
+
project_name = self.config.project_name or Path(self.result.project_path).name
|
|
142
|
+
source = self.config.source or "./"
|
|
143
|
+
output = self.config.output or "./docs"
|
|
141
144
|
if config_cls:
|
|
142
145
|
lines.append('# ' + '=' * 50)
|
|
143
146
|
lines.append("# Example 1: Configuration")
|
|
144
147
|
lines.append('# ' + '=' * 50)
|
|
145
148
|
lines.append("")
|
|
146
149
|
lines.append(f"config = {config_cls.name}(")
|
|
147
|
-
lines.append(' project_name="
|
|
148
|
-
lines.append(' source="
|
|
149
|
-
lines.append(' output="
|
|
150
|
+
lines.append(f' project_name="{project_name}",')
|
|
151
|
+
lines.append(f' source="{source}",')
|
|
152
|
+
lines.append(f' output="{output}",')
|
|
150
153
|
lines.append(" verbose=True,")
|
|
151
154
|
lines.append(")")
|
|
152
155
|
lines.append("")
|
|
@@ -157,20 +160,22 @@ class ExamplesGenerator:
|
|
|
157
160
|
lines.append("# Example 2: Generate documentation")
|
|
158
161
|
lines.append('# ' + '=' * 50)
|
|
159
162
|
lines.append("")
|
|
163
|
+
|
|
164
|
+
project_path = f'"./{project_name}"' if project_name != "." else '"./"'
|
|
160
165
|
|
|
161
166
|
gen_func = self._find_function_by_name("generate_readme")
|
|
162
167
|
if gen_func:
|
|
163
168
|
lines.append("# Generate a README for your project")
|
|
164
|
-
lines.append('generate_readme(
|
|
169
|
+
lines.append(f'generate_readme({project_path}, output="README.md")')
|
|
165
170
|
lines.append("")
|
|
166
171
|
|
|
167
172
|
docs_func = self._find_function_by_name("generate_docs")
|
|
168
173
|
if docs_func:
|
|
169
174
|
lines.append("# Generate all documentation")
|
|
170
175
|
if config_cls:
|
|
171
|
-
lines.append('docs = generate_docs(
|
|
176
|
+
lines.append(f'docs = generate_docs({project_path}, config=config)')
|
|
172
177
|
else:
|
|
173
|
-
lines.append('docs = generate_docs(
|
|
178
|
+
lines.append(f'docs = generate_docs({project_path})')
|
|
174
179
|
lines.append('print(f"Generated {len(docs)} documentation sections")')
|
|
175
180
|
lines.append("")
|
|
176
181
|
|
|
@@ -185,7 +190,7 @@ class ExamplesGenerator:
|
|
|
185
190
|
lines.append(f"from {pkg}.analyzers.project_scanner import ProjectScanner")
|
|
186
191
|
lines.append("")
|
|
187
192
|
lines.append("scanner = ProjectScanner(config)")
|
|
188
|
-
lines.append('result = scanner.analyze(
|
|
193
|
+
lines.append(f'result = scanner.analyze({project_path})')
|
|
189
194
|
lines.append("")
|
|
190
195
|
lines.append('print(f"Found {len(result.functions)} functions")')
|
|
191
196
|
lines.append('print(f"Found {len(result.classes)} classes")')
|
|
@@ -229,7 +234,7 @@ class ExamplesGenerator:
|
|
|
229
234
|
lines.append("# Step 1: Analyze the project")
|
|
230
235
|
lines.append("config = Code2DocsConfig(project_name=\"my-project\")")
|
|
231
236
|
lines.append("scanner = ProjectScanner(config)")
|
|
232
|
-
lines.append('result = scanner.analyze("./
|
|
237
|
+
lines.append('result = scanner.analyze(f"./${project_name_adv}") if project_name_adv != "." else result = scanner.analyze("./")')
|
|
233
238
|
lines.append("")
|
|
234
239
|
|
|
235
240
|
for i, cls in enumerate(gen_classes[:4], start=2):
|
|
@@ -389,8 +394,8 @@ class ExamplesGenerator:
|
|
|
389
394
|
args = [a for a in func.args if a not in ("self", "cls")]
|
|
390
395
|
parts = []
|
|
391
396
|
for arg in args[:5]:
|
|
392
|
-
val =
|
|
393
|
-
if not val:
|
|
397
|
+
val = self._get_example_value(arg)
|
|
398
|
+
if not val or val == '"..."':
|
|
394
399
|
# Try type hint
|
|
395
400
|
val = self._example_from_type(func, arg)
|
|
396
401
|
if not val:
|
|
@@ -398,17 +403,18 @@ class ExamplesGenerator:
|
|
|
398
403
|
parts.append(f"{arg}={val}" if len(args) > 1 else val)
|
|
399
404
|
return ", ".join(parts)
|
|
400
405
|
|
|
401
|
-
|
|
402
|
-
def _example_from_type(func: FunctionInfo, arg: str) -> Optional[str]:
|
|
406
|
+
def _example_from_type(self, func: FunctionInfo, arg: str) -> Optional[str]:
|
|
403
407
|
"""Try to infer example value from type annotation."""
|
|
408
|
+
project_name = self.config.project_name or Path(self.result.project_path).name
|
|
409
|
+
|
|
404
410
|
# FunctionInfo.returns gives return type, but arg types
|
|
405
411
|
# are not always available; use naming heuristics
|
|
406
412
|
if "path" in arg.lower():
|
|
407
|
-
return '"./
|
|
413
|
+
return f'"./{project_name}"'
|
|
408
414
|
if "name" in arg.lower():
|
|
409
|
-
return '"
|
|
415
|
+
return f'"{project_name}"'
|
|
410
416
|
if "dir" in arg.lower():
|
|
411
|
-
return '"./docs"'
|
|
417
|
+
return f'"{self.config.output}"' if self.config.output else '"./docs"'
|
|
412
418
|
if arg.startswith("is_") or arg.startswith("enable"):
|
|
413
419
|
return "True"
|
|
414
420
|
if "count" in arg.lower() or "max" in arg.lower() or "min" in arg.lower():
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"""Organization README generator - generates overview of multiple projects."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
from code2llm.api import AnalysisResult
|
|
7
|
+
|
|
8
|
+
from ..config import Code2DocsConfig
|
|
9
|
+
from ..analyzers.project_scanner import ProjectScanner
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OrgReadmeGenerator:
|
|
13
|
+
"""Generate organization README with list of projects and brief descriptions."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, config: Code2DocsConfig, org_path: str, org_name: str = ""):
|
|
16
|
+
self.config = config
|
|
17
|
+
self.org_path = Path(org_path).resolve()
|
|
18
|
+
self.org_name = org_name or self.org_path.name
|
|
19
|
+
self.scanner = ProjectScanner(config)
|
|
20
|
+
|
|
21
|
+
def generate(self) -> str:
|
|
22
|
+
"""Generate organization README content."""
|
|
23
|
+
projects = self._discover_projects()
|
|
24
|
+
|
|
25
|
+
lines = [
|
|
26
|
+
f"# {self.org_name}\n",
|
|
27
|
+
f"Projects in the {self.org_name} organization.\n",
|
|
28
|
+
f"**{len(projects)}** projects discovered.\n",
|
|
29
|
+
"## Projects\n",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
for project_name, project_info in sorted(projects.items()):
|
|
33
|
+
lines.append(self._render_project_section(project_name, project_info))
|
|
34
|
+
lines.append("")
|
|
35
|
+
|
|
36
|
+
return "\n".join(lines)
|
|
37
|
+
|
|
38
|
+
def _discover_projects(self) -> Dict[str, Dict]:
|
|
39
|
+
"""Discover all projects in organization directory."""
|
|
40
|
+
projects = {}
|
|
41
|
+
|
|
42
|
+
for item in self.org_path.iterdir():
|
|
43
|
+
if not item.is_dir():
|
|
44
|
+
continue
|
|
45
|
+
if item.name.startswith(".") or item.name.startswith("__"):
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
project_info = self._analyze_project(item)
|
|
49
|
+
if project_info:
|
|
50
|
+
projects[item.name] = project_info
|
|
51
|
+
|
|
52
|
+
return projects
|
|
53
|
+
|
|
54
|
+
def _analyze_project(self, project_path: Path) -> Optional[Dict]:
|
|
55
|
+
"""Analyze a single project and return summary info."""
|
|
56
|
+
try:
|
|
57
|
+
result = self.scanner.analyze(str(project_path))
|
|
58
|
+
|
|
59
|
+
# Extract description from first module docstring or pyproject.toml
|
|
60
|
+
description = self._extract_description(project_path, result)
|
|
61
|
+
|
|
62
|
+
# Count functions, classes, modules
|
|
63
|
+
func_count = len(result.functions)
|
|
64
|
+
class_count = len(result.classes)
|
|
65
|
+
module_count = len(result.modules)
|
|
66
|
+
|
|
67
|
+
# Get version from pyproject.toml if available
|
|
68
|
+
version = self._get_version(project_path)
|
|
69
|
+
|
|
70
|
+
# Get repo URL from git or config
|
|
71
|
+
repo_url = self._get_repo_url(project_path)
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
"name": project_path.name,
|
|
75
|
+
"description": description,
|
|
76
|
+
"version": version,
|
|
77
|
+
"stats": {
|
|
78
|
+
"functions": func_count,
|
|
79
|
+
"classes": class_count,
|
|
80
|
+
"modules": module_count,
|
|
81
|
+
},
|
|
82
|
+
"repo_url": repo_url,
|
|
83
|
+
"path": str(project_path),
|
|
84
|
+
}
|
|
85
|
+
except Exception:
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
def _extract_description(self, project_path: Path, result: AnalysisResult) -> str:
|
|
89
|
+
"""Extract short description from project (max 5 lines)."""
|
|
90
|
+
# Try pyproject.toml first
|
|
91
|
+
try:
|
|
92
|
+
import tomllib
|
|
93
|
+
pyproject = project_path / "pyproject.toml"
|
|
94
|
+
if pyproject.exists():
|
|
95
|
+
with open(pyproject, "rb") as f:
|
|
96
|
+
data = tomllib.load(f)
|
|
97
|
+
desc = data.get("project", {}).get("description", "")
|
|
98
|
+
if desc:
|
|
99
|
+
# Limit to ~5 lines worth of content
|
|
100
|
+
return self._truncate_description(desc)
|
|
101
|
+
except Exception:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
# Try first package docstring
|
|
105
|
+
for mod in result.modules.values():
|
|
106
|
+
if mod.is_package and hasattr(mod, "docstring") and mod.docstring:
|
|
107
|
+
return self._truncate_description(mod.docstring)
|
|
108
|
+
|
|
109
|
+
# Try README.md first paragraph
|
|
110
|
+
readme = project_path / "README.md"
|
|
111
|
+
if readme.exists():
|
|
112
|
+
try:
|
|
113
|
+
content = readme.read_text(encoding="utf-8")
|
|
114
|
+
# Find first paragraph after title
|
|
115
|
+
lines = content.split("\n")
|
|
116
|
+
for i, line in enumerate(lines):
|
|
117
|
+
if line.startswith("# "):
|
|
118
|
+
# Get next non-empty lines
|
|
119
|
+
desc_lines = []
|
|
120
|
+
for j in range(i + 1, min(i + 10, len(lines))):
|
|
121
|
+
if lines[j].strip() and not lines[j].startswith("#"):
|
|
122
|
+
desc_lines.append(lines[j].strip())
|
|
123
|
+
if len(desc_lines) >= 5:
|
|
124
|
+
break
|
|
125
|
+
if desc_lines:
|
|
126
|
+
return " ".join(desc_lines)
|
|
127
|
+
except Exception:
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
return "No description available."
|
|
131
|
+
|
|
132
|
+
def _truncate_description(self, desc: str, max_chars: int = 300) -> str:
|
|
133
|
+
"""Truncate description to ~5 lines of content."""
|
|
134
|
+
lines = desc.strip().split("\n")
|
|
135
|
+
# Filter out empty lines and headers
|
|
136
|
+
content_lines = [l.strip() for l in lines if l.strip() and not l.startswith("#")]
|
|
137
|
+
|
|
138
|
+
result = []
|
|
139
|
+
char_count = 0
|
|
140
|
+
for line in content_lines[:5]:
|
|
141
|
+
if char_count + len(line) > max_chars:
|
|
142
|
+
remaining = max_chars - char_count
|
|
143
|
+
if remaining > 20:
|
|
144
|
+
result.append(line[:remaining] + "...")
|
|
145
|
+
break
|
|
146
|
+
result.append(line)
|
|
147
|
+
char_count += len(line)
|
|
148
|
+
|
|
149
|
+
return " ".join(result) if result else "No description available."
|
|
150
|
+
|
|
151
|
+
def _get_version(self, project_path: Path) -> str:
|
|
152
|
+
"""Get version from pyproject.toml or VERSION file."""
|
|
153
|
+
try:
|
|
154
|
+
import tomllib
|
|
155
|
+
pyproject = project_path / "pyproject.toml"
|
|
156
|
+
if pyproject.exists():
|
|
157
|
+
with open(pyproject, "rb") as f:
|
|
158
|
+
data = tomllib.load(f)
|
|
159
|
+
return data.get("project", {}).get("version", "")
|
|
160
|
+
except Exception:
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
version_file = project_path / "VERSION"
|
|
164
|
+
if version_file.exists():
|
|
165
|
+
return version_file.read_text(encoding="utf-8").strip()
|
|
166
|
+
|
|
167
|
+
return ""
|
|
168
|
+
|
|
169
|
+
def _get_repo_url(self, project_path: Path) -> str:
|
|
170
|
+
"""Get repository URL from git or pyproject.toml."""
|
|
171
|
+
# Try pyproject.toml
|
|
172
|
+
try:
|
|
173
|
+
import tomllib
|
|
174
|
+
pyproject = project_path / "pyproject.toml"
|
|
175
|
+
if pyproject.exists():
|
|
176
|
+
with open(pyproject, "rb") as f:
|
|
177
|
+
data = tomllib.load(f)
|
|
178
|
+
urls = data.get("project", {}).get("urls", {})
|
|
179
|
+
if urls:
|
|
180
|
+
return urls.get("Repository", urls.get("Homepage", ""))
|
|
181
|
+
except Exception:
|
|
182
|
+
pass
|
|
183
|
+
|
|
184
|
+
# Try git remote
|
|
185
|
+
try:
|
|
186
|
+
import subprocess
|
|
187
|
+
result = subprocess.run(
|
|
188
|
+
["git", "remote", "get-url", "origin"],
|
|
189
|
+
cwd=str(project_path),
|
|
190
|
+
capture_output=True, text=True, timeout=5,
|
|
191
|
+
)
|
|
192
|
+
if result.returncode == 0:
|
|
193
|
+
url = result.stdout.strip()
|
|
194
|
+
# Convert SSH to HTTPS
|
|
195
|
+
if url.startswith("git@"):
|
|
196
|
+
url = url.replace(":", "/", 1).replace("git@", "https://", 1)
|
|
197
|
+
return url.removesuffix(".git")
|
|
198
|
+
except Exception:
|
|
199
|
+
pass
|
|
200
|
+
|
|
201
|
+
return ""
|
|
202
|
+
|
|
203
|
+
def _render_project_section(self, name: str, info: Dict) -> str:
|
|
204
|
+
"""Render a single project section (5 lines max)."""
|
|
205
|
+
lines = [f"### {name}"]
|
|
206
|
+
|
|
207
|
+
# Line 1: Description
|
|
208
|
+
lines.append(info["description"])
|
|
209
|
+
|
|
210
|
+
# Line 2: Stats
|
|
211
|
+
stats = info["stats"]
|
|
212
|
+
stats_line = f"📊 {stats['functions']} functions | {stats['classes']} classes | {stats['modules']} modules"
|
|
213
|
+
if info["version"]:
|
|
214
|
+
stats_line += f" | v{info['version']}"
|
|
215
|
+
lines.append(stats_line)
|
|
216
|
+
|
|
217
|
+
# Line 3: Repo link if available
|
|
218
|
+
if info["repo_url"]:
|
|
219
|
+
lines.append(f"🔗 [{info['repo_url']}]({info['repo_url']})")
|
|
220
|
+
|
|
221
|
+
return "\n".join(lines)
|
|
222
|
+
|
|
223
|
+
def write(self, output_path: str, content: str) -> None:
|
|
224
|
+
"""Write README to output path."""
|
|
225
|
+
out_path = Path(output_path)
|
|
226
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
227
|
+
out_path.write_text(content, encoding="utf-8")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code2docs
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.5
|
|
4
4
|
Summary: Auto-generate and sync project documentation from source code analysis
|
|
5
5
|
Author-email: Tom Sapletta <tom@sapletta.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -50,7 +50,7 @@ Dynamic: license-file
|
|
|
50
50
|
|
|
51
51
|
# code2docs
|
|
52
52
|
|
|
53
|
-
  
|
|
54
54
|
|
|
55
55
|
> Auto-generate and sync project documentation from source code analysis.
|
|
56
56
|
|
|
@@ -190,7 +190,7 @@ code2docs can update only specific sections of an existing README using markers:
|
|
|
190
190
|
```markdown
|
|
191
191
|
<!-- code2docs:start --># code2docs
|
|
192
192
|
|
|
193
|
-
   
|
|
194
194
|
> **276** functions | **57** classes | **51** files | CC̄ = 3.8
|
|
195
195
|
|
|
196
196
|
> Auto-generated project documentation from source code analysis.
|
|
@@ -41,6 +41,7 @@ code2docs/generators/examples_gen.py
|
|
|
41
41
|
code2docs/generators/getting_started_gen.py
|
|
42
42
|
code2docs/generators/mkdocs_gen.py
|
|
43
43
|
code2docs/generators/module_docs_gen.py
|
|
44
|
+
code2docs/generators/org_readme_gen.py
|
|
44
45
|
code2docs/generators/readme_gen.py
|
|
45
46
|
code2docs/sync/__init__.py
|
|
46
47
|
code2docs/sync/differ.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|