Production-ready shared utilities and interfaces for the AST ecosystem
ast-common-core
provides the foundational components shared across all AST (Abstract Syntax Tree) analysis and refactoring tools. This production-ready library (v2.0.0) features 92% test coverage, comprehensive type safety, and professional-grade implementations.
Ecosystem Integration:
- ast-dependency-analyzer: Dependency graph analysis and visualization
- ast-refactor-agent: Intelligent code refactoring tools
- Other AST ecosystem tools
π Complete Documentation | π Quickstart Guide | π API Reference | ποΈ Architecture
Define contracts for extensible components (API Docs):
- ILogger: Logging interface with debug/info/warning/error/critical levels
- IParser: Parser interface for different programming languages
- IPerformanceTracker: Performance monitoring and metrics collection
Pydantic-based models with comprehensive validation (API Docs):
- Package: Software package representation with dependencies, versions, and metadata
- Vulnerability: Security vulnerability information with CVSS scoring, CWE IDs, and remediation
- Severity: Standardized severity levels (CRITICAL, HIGH, MEDIUM, LOW, INFO)
- PackageType: Support for 12 package ecosystems (Python, JavaScript, Rust, Go, Java, Ruby, PHP, C#, etc.)
Lightweight DI framework for loose coupling (API Docs):
- Container: Service registration and resolution
- Lifecycle Management: Singleton, Transient, and Scoped lifecycles
- Type-Safe: Full type hint support
- Thread-Safe: Production-ready concurrency handling
Comprehensive exception system with context (API Docs):
DependencyGraphError
- Base exception with context preservationPackageError
,VulnerabilityError
,DependencyError
- Domain-specific errorsCircularDependencyError
,VersionConflictError
- Specialized errors- Smart Default Messages: Automatic context-aware error message generation
- 16 total exceptions covering all use cases
pip install ast-common-core
# Clone repository
git clone https://github.com/username/ast-common-core.git
cd ast-common-core
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
π Complete Installation Guide - Includes Docker, CI/CD, troubleshooting
from ast_common.models import Package, Severity, Vulnerability
# Create a package
package = Package(
name="example-package",
version="1.0.0",
dependencies={"dep1", "dep2"}
)
# Create a vulnerability
vuln = Vulnerability(
id="CVE-2024-1234",
package="example-package",
severity=Severity.HIGH,
cvss_score=7.5,
description="Example vulnerability"
)
# Derive severity from CVSS score
severity = Severity.from_cvss_score(8.5) # Returns Severity.HIGH
from ast_common.di import Container, inject
from ast_common.interfaces import ILogger
# Create and configure container
container = Container()
container.register_singleton(ILogger, MyLoggerImplementation)
# Use inject decorator
@inject(container)
def my_function(logger: ILogger):
logger.info("Dependency injected automatically!")
my_function() # Logger is injected automatically
from ast_common.exceptions import CircularDependencyError
# Detect and report circular dependencies
cycle = ["pkg-a", "pkg-b", "pkg-c"]
raise CircularDependencyError(cycle=cycle)
# Output: "Circular dependency detected: pkg-a -> pkg-b -> pkg-c -> pkg-a"
ast-common-core/
βββ src/ast_common/
β βββ __init__.py # Main package exports
β βββ interfaces/ # Core interfaces (ILogger, IParser, IPerformanceTracker)
β βββ models/ # Pydantic data models (Package, Vulnerability)
β βββ exceptions/ # Exception hierarchy (16 exceptions)
β βββ di/ # Dependency injection framework
β βββ core/ # Core implementations (Logger)
β βββ py.typed # PEP 561 type checking marker
βββ docs/ # Comprehensive documentation
β βββ api/ # API reference documentation
β βββ architecture/ # System architecture docs
β βββ user-guides/ # User tutorials and guides
β βββ operations/ # Installation and deployment
βββ tests/ # Test suite (181 tests, 92% coverage)
β βββ test_logging.py # Logger tests (43 tests, 100% coverage)
β βββ test_models.py # Model tests (62 tests)
β βββ test_interfaces.py # Interface tests
β βββ test_exceptions.py # Exception tests
βββ pyproject.toml # Package configuration
ποΈ Architecture Documentation - Design principles, patterns, and diagrams
# Run all tests with coverage
pytest tests/ -v --cov=ast_common --cov-report=term-missing
# Run specific test file
pytest tests/test_models.py -v
# Current coverage: 92% (181 tests passing)
# Lint and format
ruff check src/ tests/
ruff format src/ tests/
# Type checking
mypy src/ast_common --ignore-missing-imports
# All checks should pass before committing
π Development Guide | π€ Contributing Guidelines
- Python: 3.10+ (tested on 3.10, 3.11, 3.12)
- Required Dependencies:
- pydantic >= 2.0.0, < 3.0.0
- Development Dependencies (optional):
- pytest >= 7.0.0
- pytest-cov >= 4.0.0
- pytest-asyncio >= 0.21.0
- mypy >= 1.0.0
- ruff >= 0.1.0
β¨ Major Production Release:
- Enhanced Models: Added 5 new Vulnerability fields (affected_versions, fixed_version, cwe_ids, etc.)
- Expanded Package Types: Support for 9 additional ecosystems (Rust, Go, Java, Ruby, PHP, C#, etc.)
- Improved Exceptions: 7 exceptions enhanced with smart default messages and better context
- Complete Testing: 92% coverage with 181 professional-grade tests
- Type Safety: Added py.typed marker for full type checking support
- Production Quality: Zero shortcuts, comprehensive validation, professional implementations
π Complete Changelog | π Migration Guide
MIT License - see LICENSE file for details
Complete documentation is available in the docs/ directory:
- π Quickstart Guide - Get started in 5 minutes
- π§ API Reference - Complete API documentation
- ποΈ Architecture - System design and patterns
- π¦ Installation Guide - All installation methods
- π€ Contributing - Contribution guidelines and standards
- π Changelog - Version history and migration guides
Contributions are welcome! Please read our Contributing Guidelines for:
- Development environment setup
- Code style and quality standards (PEP 8, type hints, 85%+ test coverage)
- Pull request process and review guidelines
- Testing requirements and best practices
Key Requirements:
- All code must have type hints
- Test coverage must be 85%+ for new code
- Follow PEP 8 with 100-character line limit
- Write comprehensive docstrings (Google style)
- ast-dependency-analyzer: Dependency graph analysis tool
- ast-refactor-agent: Intelligent refactoring assistant
- PDF-Preprocessing (document-ai-pipeline): Document processing pipeline
- π Documentation: docs/
- π Bug Reports: GitHub Issues
- π¬ Discussions: GitHub Discussions
- β FAQ: docs/user-guides/faq.md
Version: 2.0.0 (Changelog) Status: Production Ready (92% Test Coverage) License: MIT (LICENSE) Maintainer: PredX007
Quality Metrics:
- β 181 tests passing
- β 92% code coverage
- β 100% type hint coverage
- β Zero known bugs
- β Production-ready code quality