c454a3af10
* feat(skill): replace skill-pack with per-harness conditional compiler
skillbuild compiles the skill tree into per-target harness builds:
- <!-- skill:if omp,!claude --> blocks include text only for matching
targets; name-list conditions only, no else/nesting, fail-loud on
unknown targets and unpaired/nested directives
- fence-aware: directive-looking lines inside code fences are literal
- layout is the filesystem; tree root configured in skillproj.toml
- post-build assertion: zero directive residue, SKILL.md frontmatter
name check
Migration to the new model:
- docs/skill/ becomes the self-contained source root (SKILL.md,
references/, generated api/stdlib/core/guides now under
references/docs/; SDK_OVERVIEW/LICENSE/inspect are ordinary tree
files)
- auto_docs_gen output redirected into the tree (docs/api ->
docs/skill/references/docs/api, likewise stdlib)
- skills/simplecadapi/ is now the compiled omp target output;
dist/generic/simplecadapi the generic target
- dropped skill-pack entry point (plus dangling evolve/make-export
entries and their orphaned test), release workflow builds via
skillbuild + tar; README updated
First real conditional block: harness reading paths in SKILL.md
(skill:// mount on omp vs disk-relative on generic).
Verified: 59 tests pass (skillbuild 31, auto_docs_gen 19, persistence
regression 9); both targets build; outputs residue-clean; full suite
collects (1376 tests).
* refactor(tools): auto_docs_gen moves out of the installed package
tools/ scripts are repo-checkout dev scripts, not packaged CLIs:
- auto_docs_gen.py now lives in tools/ beside the other generators;
auto_tools/ package removed entirely
- path resolution simplifies: repo root = parent of tools/, fail-loud
if pyproject.toml missing; site-packages/cwd fallback branches were
dead code once the script stopped shipping in the wheel
- auto-docs-gen console script dropped from [project.scripts];
release.yml and README invoke python tools/auto_docs_gen.py
- MANIFEST.in stale src/auto_tools include removed; CadQuery-free
runtime scan no longer needs the auto_tools filter
- run_examples.py retired (user removal): README example-runner text
updated to direct examples/ scripts; dangling runner-contract test
(runpy.run_path into the deleted script) removed
Verified: 53 tests pass (auto_docs_gen + skill_build + ocp runtime
scan) and test_example_model_contract passes; regeneration from
tools/ is byte-identical (zero docs drift).
* refactor(skill): strip harness and build-tool content from the skill tree
The skill is plain harness-neutral content again:
- SKILL.md 'Reading skill files' section removed (the omp skill://
mount block and its !omp complement were the only conditional
blocks; the tree compiles identically for every target now)
- references/README.md: build-tool meta removed ('per-harness
conditional compilation', skillbuild packaging/validation claims —
link validation was never implemented, so the claim was false)
- live test now asserts the tree stays harness-neutral (zero blocks)
- skillproj.toml targets aligned with the user's output table
(omp -> skills/simplecadapi-omp, opencode -> skills/simplecadapi-opencode;
leftover 'generic' entry had no output and failed the build)
- compiled outputs are regenerable artifacts: skills/simplecadapi/
untracked from git, skills/simplecadapi-*/ gitignored, release.yml
and README build via skillbuild and tar the omp output directly
(bsdtar has no --transform; inner dir keeps its suffixed name)
Verified: 49 tests pass; both targets build 372 files with zero
conditional blocks; no omp/conditional/directive residue in the tree
or outputs.
* chore(docs): drop stale architecture review and design notes
595 lines
23 KiB
Python
595 lines
23 KiB
Python
import importlib.util
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
MODULE_PATH = (
|
|
Path(__file__).resolve().parents[1] / "tools/auto_docs_gen.py"
|
|
)
|
|
MODULE_SPEC = importlib.util.spec_from_file_location(
|
|
"simplecadapi_auto_docs_gen",
|
|
MODULE_PATH,
|
|
)
|
|
if MODULE_SPEC is None or MODULE_SPEC.loader is None:
|
|
raise RuntimeError(f"Unable to load module spec for {MODULE_PATH}")
|
|
|
|
auto_docs_gen = importlib.util.module_from_spec(MODULE_SPEC)
|
|
sys.modules[MODULE_SPEC.name] = auto_docs_gen
|
|
MODULE_SPEC.loader.exec_module(auto_docs_gen)
|
|
|
|
|
|
class TestAutoDocsGenPathResolution(unittest.TestCase):
|
|
def test_resolve_source_files_from_repo_checkout(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
project_root = Path(tmp_dir)
|
|
(project_root / "pyproject.toml").write_text(
|
|
"[project]\nname = 'demo'\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
module_file = project_root / "tools/auto_docs_gen.py"
|
|
module_file.parent.mkdir(parents=True, exist_ok=True)
|
|
module_file.write_text("", encoding="utf-8")
|
|
|
|
resolved = auto_docs_gen._resolve_source_files(
|
|
None, module_file=module_file
|
|
)
|
|
package_root = project_root / "src/simplecadapi"
|
|
expected = [
|
|
(package_root / name).resolve()
|
|
for name in auto_docs_gen.DEFAULT_SOURCE_FILENAMES
|
|
]
|
|
|
|
self.assertEqual(resolved, expected)
|
|
|
|
def test_resolve_source_files_outside_repo_fails_loud(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
module_file = Path(tmp_dir) / "auto_docs_gen.py"
|
|
module_file.write_text("", encoding="utf-8")
|
|
|
|
with self.assertRaises(FileNotFoundError):
|
|
auto_docs_gen._resolve_source_files(None, module_file=module_file)
|
|
|
|
def test_resolve_output_dirs_from_source_checkout_uses_repo_docs(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
project_root = Path(tmp_dir)
|
|
(project_root / "pyproject.toml").write_text(
|
|
"[project]\nname = 'demo'\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
module_file = project_root / "tools/auto_docs_gen.py"
|
|
module_file.parent.mkdir(parents=True, exist_ok=True)
|
|
module_file.write_text("", encoding="utf-8")
|
|
|
|
resolved = auto_docs_gen._resolve_output_dirs(None, module_file=module_file)
|
|
|
|
self.assertEqual(
|
|
resolved,
|
|
[(project_root / "docs/skill/references/docs/api").resolve()],
|
|
)
|
|
|
|
|
|
def test_default_source_files_include_v2_public_modules(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
package_root = Path(tmp_dir) / "src/simplecadapi"
|
|
package_root.mkdir(parents=True, exist_ok=True)
|
|
backend_root = package_root / "translator/freecad_translator"
|
|
backend_root.mkdir(parents=True)
|
|
(backend_root / "api.py").write_text("", encoding="utf-8")
|
|
(backend_root / "translator.py").write_text("", encoding="utf-8")
|
|
(backend_root / "types.py").write_text("", encoding="utf-8")
|
|
|
|
resolved = auto_docs_gen._default_source_files(package_root)
|
|
|
|
resolved_names = [
|
|
path.relative_to(package_root).as_posix() for path in resolved
|
|
]
|
|
self.assertIn("serializer.py", resolved_names)
|
|
self.assertIn("graph.py", resolved_names)
|
|
self.assertIn("expr.py", resolved_names)
|
|
self.assertIn("tolerance.py", resolved_names)
|
|
self.assertIn("sketch.py", resolved_names)
|
|
self.assertIn("math.py", resolved_names)
|
|
self.assertIn("translator/freecad_translator/api.py", resolved_names)
|
|
self.assertIn(
|
|
"translator/freecad_translator/translator.py",
|
|
resolved_names,
|
|
)
|
|
self.assertIn(
|
|
"translator/freecad_translator/types.py",
|
|
resolved_names,
|
|
)
|
|
self.assertIn("inspect/brep/inspect.py", resolved_names)
|
|
self.assertIn("inspect/brep/queries.py", resolved_names)
|
|
self.assertIn("exporter/mjcf.py", resolved_names)
|
|
|
|
def test_default_source_files_include_cache_build_public_surface(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
package_root = Path(tmp_dir) / "src/simplecadapi"
|
|
package_root.mkdir(parents=True, exist_ok=True)
|
|
resolved = auto_docs_gen._default_source_files(package_root)
|
|
resolved_names = [
|
|
path.relative_to(package_root).as_posix() for path in resolved
|
|
]
|
|
|
|
self.assertIn("build/part_builder.py", resolved_names)
|
|
self.assertIn("build/assembly_builder.py", resolved_names)
|
|
self.assertIn("build/dependencies.py", resolved_names)
|
|
self.assertIn("build/results.py", resolved_names)
|
|
self.assertIn("capture.py", resolved_names)
|
|
self.assertIn("cache/policy.py", resolved_names)
|
|
self.assertIn("cache/store.py", resolved_names)
|
|
|
|
def test_real_cache_build_sources_document_only_top_level_surface(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=auto_docs_gen._default_source_files(
|
|
Path(__file__).resolve().parents[1] / "src/simplecadapi"
|
|
),
|
|
output_dirs=[Path(tmp_dir) / "docs/api"],
|
|
quiet=True,
|
|
)
|
|
names = {api.name for api in generator.extract_apis()}
|
|
for name in (
|
|
"capture",
|
|
"CaptureResult",
|
|
"assemble",
|
|
"file_input",
|
|
"part",
|
|
"AssemblyBuildResult",
|
|
"AssemblySolveReport",
|
|
"CachePolicy",
|
|
"CacheReport",
|
|
"ContentAddressedStore",
|
|
"ProductMJCFExportReport",
|
|
"export_product_package_to_mjcf",
|
|
):
|
|
self.assertIn(name, names)
|
|
self.assertNotIn("snapshot_file_inputs", names)
|
|
self.assertNotIn("OperationCacheReport", names)
|
|
self.assertNotIn("operation_cache_scope", names)
|
|
self.assertNotIn("operation_cache_report", names)
|
|
|
|
def test_inspect_brep_api_docs_use_inspection_namespace(self):
|
|
class InspectionDocGenerator(auto_docs_gen.APIDocumentGenerator):
|
|
def _module_name_for(self, file_path):
|
|
return "inspect/brep/inspect.py"
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
package_root = tmp_path / "simplecadapi"
|
|
source_file = package_root / "inspect/brep/inspect.py"
|
|
source_file.parent.mkdir(parents=True)
|
|
(package_root / "__init__.py").write_text(
|
|
"__all__ = ['inspect']\n",
|
|
encoding="utf-8",
|
|
)
|
|
source_file.write_text(
|
|
"def inspect_step_rsummary(path: str) -> dict:\n"
|
|
' """Inspect one STEP summary."""\n'
|
|
" return {}\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
generator = InspectionDocGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
page = (output_dir / "inspect_step_rsummary.md").read_text(encoding="utf-8")
|
|
self.assertIn("## STEP/BREP Inspection", readme)
|
|
self.assertIn("`inspection namespace`", readme)
|
|
self.assertIn("from simplecadapi.inspect import brep", page)
|
|
self.assertIn("unavailable inside GraphSession", page)
|
|
|
|
def test_evaluator_api_docs_preserve_schemas_units_and_trust_boundaries(self):
|
|
class EvaluationDocGenerator(auto_docs_gen.APIDocumentGenerator):
|
|
def _module_name_for(self, file_path):
|
|
return "inverse_engineer/brep/evaluation.py"
|
|
|
|
project_root = MODULE_PATH.parents[1]
|
|
source_file = (
|
|
project_root / "src/simplecadapi/inverse_engineer/brep/evaluation.py"
|
|
)
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
output_dir = Path(tmp_dir) / "docs/api"
|
|
generator = EvaluationDocGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
bundle = (output_dir / "run_comparison_bundle.md").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
config = (output_dir / "EvaluationConfig.md").read_text(encoding="utf-8")
|
|
classify = (output_dir / "classify_benchmark_result.md").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
section = (output_dir / "SectionEvaluationConfig.md").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
|
|
self.assertIn("## Reconstruction Evaluation", readme)
|
|
self.assertIn("`reverse-engineering evaluator`", readme)
|
|
self.assertIn("from simplecadapi.inverse_engineer.brep import", bundle)
|
|
self.assertNotIn("top-level:", bundle)
|
|
self.assertIn("Report schemas and units", bundle)
|
|
self.assertIn("cubic millimetres", bundle)
|
|
self.assertIn("checks.hard_gate", bundle)
|
|
self.assertIn(
|
|
"diagnostic, never equality proof",
|
|
" ".join(bundle.split()),
|
|
)
|
|
self.assertIn("diagnostics and never affect classification", bundle)
|
|
self.assertIn("status ``completed``", bundle)
|
|
self.assertIn("``gate_passed=None``", bundle)
|
|
self.assertIn("strict bidirectional", bundle)
|
|
self.assertIn("non-fuzzy bidirectional Cut residual volumes", bundle)
|
|
self.assertIn("mass-property comparison", bundle)
|
|
for deprecated in (
|
|
"global_max_bbox_delta",
|
|
"global_max_centroid_distance",
|
|
"global_max_relative_volume_error",
|
|
"global_max_relative_area_error",
|
|
"boundary_max_hausdorff",
|
|
"boundary_max_p95",
|
|
):
|
|
self.assertIn(deprecated, config)
|
|
self.assertIn("deprecated compatibility inputs and are ignored", config)
|
|
self.assertIn("strict_material_tolerance", config)
|
|
self.assertIn("boundary_linear_deflection", config)
|
|
self.assertIn("boundary_max_samples", config)
|
|
self.assertIn("strict_geometric_tolerance", config)
|
|
self.assertIn("unmodified, process-local result", classify)
|
|
self.assertIn("ignored by classification", classify)
|
|
self.assertIn("at least one unique face", classify)
|
|
self.assertIn(
|
|
"not just a claimed stage status",
|
|
" ".join(classify.split()),
|
|
)
|
|
self.assertIn("bounded diagnostic section probe", section)
|
|
self.assertIn("not acceptance gates", section)
|
|
self.assertIn("require_nonempty", section)
|
|
self.assertIn("max_hausdorff", section)
|
|
self.assertIn("max_relative_area_error", section)
|
|
self.assertIn("deprecated compatibility inputs", section)
|
|
self.assertIn("do not affect stage status", section)
|
|
|
|
def test_persistence_api_docs_distinguish_roundtrip_from_target_similarity(self):
|
|
class PersistenceDocGenerator(auto_docs_gen.APIDocumentGenerator):
|
|
def _module_name_for(self, file_path):
|
|
return "inspect/brep/persistence.py"
|
|
|
|
project_root = MODULE_PATH.parents[1]
|
|
source_file = project_root / "src/simplecadapi/inspect/brep/persistence.py"
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
output_dir = Path(tmp_dir) / "docs/api"
|
|
generator = PersistenceDocGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
persistence = (
|
|
output_dir / "validate_step_roundtrip_rdescriptor.md"
|
|
).read_text(encoding="utf-8")
|
|
self.assertIn("candidate-before/after volume and surface-area", persistence)
|
|
self.assertIn("STEP serialization integrity checks", persistence)
|
|
self.assertIn("not candidate-to-target", persistence)
|
|
|
|
def test_default_stdlib_source_files_include_standard_modules(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
package_root = Path(tmp_dir) / "src/simplecadapi"
|
|
package_root.mkdir(parents=True, exist_ok=True)
|
|
|
|
resolved = auto_docs_gen._default_stdlib_source_files(package_root)
|
|
|
|
self.assertEqual(
|
|
resolved,
|
|
[
|
|
package_root / "std/bearing.py",
|
|
package_root / "std/gear.py",
|
|
],
|
|
)
|
|
|
|
def test_resolve_stdlib_output_dirs_from_source_checkout_uses_repo_docs(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
project_root = Path(tmp_dir)
|
|
(project_root / "pyproject.toml").write_text(
|
|
"[project]\nname = 'demo'\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
module_file = project_root / "tools/auto_docs_gen.py"
|
|
module_file.parent.mkdir(parents=True, exist_ok=True)
|
|
module_file.write_text("", encoding="utf-8")
|
|
|
|
resolved = auto_docs_gen._resolve_stdlib_output_dirs(
|
|
None,
|
|
module_file=module_file,
|
|
)
|
|
|
|
self.assertEqual(
|
|
resolved,
|
|
[(project_root / "docs/skill/references/docs/stdlib").resolve()],
|
|
)
|
|
|
|
|
|
class TestAutoDocsGenExtraction(unittest.TestCase):
|
|
def test_extract_apis_from_v2_public_modules(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
source_file = tmp_path / "serializer.py"
|
|
source_file.write_text(
|
|
"""
|
|
def export_model_json(session, indent=2):
|
|
\"\"\"Export the canonical 2.0 model seed JSON.\"\"\"
|
|
return \"{}\"
|
|
|
|
|
|
def _internal_helper():
|
|
\"\"\"Should not be documented.\"\"\"
|
|
return None
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
|
|
apis = generator.extract_apis()
|
|
|
|
self.assertEqual([api.name for api in apis], ["export_model_json"])
|
|
|
|
def test_generate_markdown_includes_v2_model_api_entry(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
source_file = tmp_path / "serializer.py"
|
|
source_file.write_text(
|
|
"""
|
|
def export_model_json(session, indent=2):
|
|
\"\"\"Export the canonical 2.0 model seed JSON.
|
|
|
|
Args:
|
|
session: Recorded graph session.
|
|
indent: JSON indentation level.
|
|
|
|
Returns:
|
|
JSON string representation.
|
|
\"\"\"
|
|
return \"{}\"
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
page = (output_dir / "export_model_json.md").read_text(encoding="utf-8")
|
|
|
|
self.assertIn("[export_model_json](export_model_json.md)", readme)
|
|
self.assertIn("def export_model_json(session, indent = 2)", page)
|
|
self.assertIn("Export the canonical 2.0 model seed JSON.", page)
|
|
|
|
def test_generate_markdown_avoids_case_insensitive_filename_collisions(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
source_file = tmp_path / "expr.py"
|
|
source_file.write_text(
|
|
"""
|
|
class Const:
|
|
\"\"\"Constant node.\"\"\"
|
|
|
|
|
|
def const(value):
|
|
\"\"\"Constant constructor.\"\"\"
|
|
return value
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
|
|
self.assertTrue((output_dir / "Const.md").exists())
|
|
self.assertTrue((output_dir / "const_function.md").exists())
|
|
self.assertIn("[Const](Const.md)", readme)
|
|
self.assertIn("[const](const_function.md)", readme)
|
|
|
|
def test_generate_markdown_includes_math_helper_category(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
init_file = tmp_path / "__init__.py"
|
|
init_file.write_text(
|
|
"__all__ = ['BSplineFitResult', 'fit_cubic_bspline_control_points']\n",
|
|
encoding="utf-8",
|
|
)
|
|
source_file = tmp_path / "math.py"
|
|
source_file.write_text(
|
|
'''
|
|
class BSplineFitResult:
|
|
"""B-spline fitting result."""
|
|
|
|
|
|
def fit_cubic_bspline_control_points(sample_points, *, tolerance=1e-3):
|
|
"""Fit sampled points to cubic B-spline controls."""
|
|
return BSplineFitResult()
|
|
'''.strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
|
|
self.assertIn("## Math Helpers", readme)
|
|
self.assertIn("[BSplineFitResult](BSplineFitResult.md)", readme)
|
|
self.assertIn(
|
|
"[fit_cubic_bspline_control_points](fit_cubic_bspline_control_points.md)",
|
|
readme,
|
|
)
|
|
|
|
def test_generate_markdown_includes_top_level_exported_operations_class(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
(tmp_path / "__init__.py").write_text(
|
|
"__all__ = ['SurfaceSettings']\n", encoding="utf-8"
|
|
)
|
|
source_file = tmp_path / "operations.py"
|
|
source_file.write_text(
|
|
'''
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SurfaceSettings:
|
|
"""Surface construction settings."""
|
|
|
|
degree: int = 3
|
|
'''.strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file], output_dirs=[output_dir], quiet=True
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
page = (output_dir / "SurfaceSettings.md").read_text(encoding="utf-8")
|
|
self.assertIn("[SurfaceSettings](SurfaceSettings.md)", readme)
|
|
self.assertIn("class SurfaceSettings(degree: int = 3)", page)
|
|
self.assertIn("from simplecadapi import SurfaceSettings", page)
|
|
|
|
def test_generate_markdown_includes_physical_units_category(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
init_file = tmp_path / "__init__.py"
|
|
init_file.write_text(
|
|
"__all__ = ['Dimension', 'convert_value']\n", encoding="utf-8"
|
|
)
|
|
source_file = tmp_path / "units.py"
|
|
source_file.write_text(
|
|
'''
|
|
class Dimension:
|
|
"""Physical dimension."""
|
|
|
|
|
|
def convert_value(value, from_unit, to_unit):
|
|
"""Convert compatible units."""
|
|
return value
|
|
'''.strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/api"
|
|
|
|
generator = auto_docs_gen.APIDocumentGenerator(
|
|
source_files=[source_file], output_dirs=[output_dir], quiet=True
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
|
|
self.assertIn("## Physical Units", readme)
|
|
self.assertIn("[Dimension](Dimension.md)", readme)
|
|
self.assertIn("[convert_value](convert_value.md)", readme)
|
|
|
|
def test_generate_stdlib_markdown_uses_stdlib_index_and_import_surface(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
tmp_path = Path(tmp_dir)
|
|
source_dir = tmp_path / "std"
|
|
source_dir.mkdir()
|
|
source_file = source_dir / "gear.py"
|
|
source_file.write_text(
|
|
'''
|
|
def make_spur_gear_rsolid(n_teeth: int, module: float):
|
|
"""Create a test spur gear.
|
|
|
|
Parameters
|
|
----------
|
|
n_teeth : int
|
|
Number of teeth.
|
|
module : float
|
|
Gear module.
|
|
"""
|
|
return None
|
|
|
|
|
|
def _private_helper():
|
|
"""Should not be documented."""
|
|
return None
|
|
'''.strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
output_dir = tmp_path / "docs/stdlib"
|
|
|
|
generator = auto_docs_gen.StdlibDocumentGenerator(
|
|
source_files=[source_file],
|
|
output_dirs=[output_dir],
|
|
quiet=True,
|
|
)
|
|
generator.extract_apis()
|
|
generator.generate_markdown_docs()
|
|
|
|
readme = (output_dir / "README.md").read_text(encoding="utf-8")
|
|
page = (output_dir / "make_spur_gear_rsolid.md").read_text(encoding="utf-8")
|
|
|
|
self.assertIn("# SimpleCAD Standard Library Index", readme)
|
|
self.assertIn("[make_spur_gear_rsolid](make_spur_gear_rsolid.md)", readme)
|
|
self.assertIn("scad.std.gear.make_spur_gear_rsolid", page)
|
|
self.assertIn("**Type**: `int`", page)
|
|
self.assertNotIn("_private_helper", readme)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|