Skip to content

feat: add dynamic V1 programmatic API and schema subcommand#525

Merged
ssbarnea merged 2 commits intoansible:mainfrom
cidrblock:v1_api
Feb 23, 2026
Merged

feat: add dynamic V1 programmatic API and schema subcommand#525
ssbarnea merged 2 commits intoansible:mainfrom
cidrblock:v1_api

Conversation

@cidrblock
Copy link
Copy Markdown
Collaborator

@cidrblock cidrblock commented Feb 13, 2026

Summary

Adds a schema-driven Python API (V1 class in ansible_creator.api) for programmatic interaction with ansible-creator, intended for internal Ansible ecosystem tooling (ansible-dev-tools server, VS Code extension, MCP servers). Also adds a schema CLI subcommand and supporting documentation.

V1 API

  • Dynamic command discovery via argparse introspection -- no maintenance required when new subcommands are added
  • schema() / schema_for() for capability introspection
  • run(*command_path, **kwargs) constructs argv and feeds real argparse for validation and dispatch
  • build_command(*command_path, **kwargs) returns the constructed argv without executing
  • CreatorResult dataclass with status, path, logs, and message
  • Output capture via captured_messages parameter on Output class
  • Explicit path support (init_path/path) or auto temporary directory for init/add
  • CLI output options (log_file, verbose, json, etc.) supported through argv construction
  • Routing key conflict detection and unknown kwarg validation
  • Proper action="count" handling (verbose=2 produces -v -v)

Architecture

  • ansible_creator.schema -- root-level module for schema introspection; subcommands/schema.py is a thin CLI wrapper
  • Parser.build_parser() -- shared parser tree construction used by CLI, Schema, and API
  • Helper extractions (_build_output, _walk_to_leaf, _action_to_argv) keep method complexity under linter thresholds

Additional changes

  • Normalized add resource ai subparser to accept a path positional and --overwrite/--no-overwrite flags, matching all other resource subparsers
  • Output.critical() in capture mode now routes through self.log() for consistent file logging
  • docs/api.md documents the internal API

Relates: https://issues.redhat.com/browse/AAP-62949

Test plan

  • 47 unit tests in test_api.py covering build_command, schema, init, add, error handling, verbosity, output capture, explicit paths, count actions, and unknown kwargs
  • Full unit test suite passes
  • Pre-commit passes (ruff, mypy, pydoclint, pylint, cspell, markdownlint, ansible-lint)

Made with Cursor

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add a schema-driven Python API (V1 class) for programmatic interaction
with ansible-creator, intended for internal Ansible ecosystem tooling
(ansible-dev-tools server, VS Code extension, MCP servers).

Key features:
- Dynamic command discovery via argparse introspection (no maintenance)
- schema()/schema_for() for capability introspection
- run() constructs argv and feeds real argparse for validation
- build_command() returns constructed argv without executing
- Output capture via captured_messages parameter on Output class
- CreatorResult dataclass with status, path, logs, and message
- Explicit path support (init_path/path) or auto temp directory
- CLI options (log_file, verbose, etc.) supported through argv
- 100% branch coverage on api.py, output.py, schema.py

Also adds:
- Schema subcommand for CLI schema emission (JSON)
- docs/api.md internal API documentation

Relates: https://issues.redhat.com/browse/AAP-62949
Co-authored-by: Cursor <[email protected]>
@ssbarnea ssbarnea enabled auto-merge (squash) February 23, 2026 14:54
@github-actions github-actions bot added feat and removed feat labels Feb 23, 2026
@ssbarnea ssbarnea merged commit 18086b1 into ansible:main Feb 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants