-
Notifications
You must be signed in to change notification settings - Fork 4
Add dynamic API parity validation and switch to mypy #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Discovery module for API parity checking.""" | ||
|
|
||
| from .go_parser import parse_go_interface, GoMethod | ||
| from .python_introspector import introspect_python_service, PythonMethod | ||
| from .name_mapping import go_to_python, python_to_go | ||
|
|
||
| __all__ = [ | ||
| "parse_go_interface", | ||
| "GoMethod", | ||
| "introspect_python_service", | ||
| "PythonMethod", | ||
| "go_to_python", | ||
| "python_to_go", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Parse Go interface.go to extract method signatures.""" | ||
|
|
||
| import re | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| @dataclass | ||
| class GoMethod: | ||
| """Represents a Go method signature.""" | ||
|
|
||
| name: str | ||
| params: list[tuple[str, str]] # [(param_name, param_type), ...] | ||
| return_type: str | ||
|
|
||
|
|
||
| def parse_go_interface(interface_path: Path) -> list[GoMethod]: | ||
| """Parse Go interface.go and extract public methods from ServiceInterface. | ||
|
|
||
| Args: | ||
| interface_path: Path to go/interface.go | ||
|
|
||
| Returns: | ||
| List of GoMethod objects representing the interface methods. | ||
| """ | ||
| content = interface_path.read_text() | ||
|
|
||
| # Find the ServiceInterface block | ||
| interface_match = re.search( | ||
| r'type\s+ServiceInterface\s+interface\s*\{([^}]+)\}', | ||
| content, | ||
| re.DOTALL | ||
| ) | ||
|
|
||
| if not interface_match: | ||
| raise ValueError("Could not find ServiceInterface in interface.go") | ||
|
|
||
| interface_body = interface_match.group(1) | ||
|
|
||
| methods = [] | ||
| method_pattern = re.compile( | ||
| r'^\s*(\w+)\s*\(([^)]*)\)\s*(.+?)\s*$', | ||
| re.MULTILINE | ||
| ) | ||
|
|
||
| for match in method_pattern.finditer(interface_body): | ||
| name = match.group(1) | ||
| params_str = match.group(2).strip() | ||
| return_type = match.group(3).strip() | ||
|
|
||
| # Skip comments | ||
| if name.startswith('//'): | ||
| continue | ||
|
|
||
| params = parse_params(params_str) | ||
| methods.append(GoMethod(name=name, params=params, return_type=return_type)) | ||
|
|
||
| return methods | ||
|
|
||
|
|
||
| def parse_params(params_str: str) -> list[tuple[str, str]]: | ||
| """Parse Go parameter string into list of (name, type) tuples. | ||
|
|
||
| Examples: | ||
| "uid string" -> [("uid", "string")] | ||
| "uid string, teamName string" -> [("uid", "string"), ("teamName", "string")] | ||
| "" -> [] | ||
| "ctx context.Context, source DataSource" -> [("ctx", "context.Context"), ("source", "DataSource")] | ||
| """ | ||
| if not params_str: | ||
| return [] | ||
|
|
||
| params = [] | ||
| for param in params_str.split(','): | ||
| param = param.strip() | ||
| if not param: | ||
| continue | ||
|
|
||
| # Split on last space to handle types like "context.Context" | ||
| parts = param.rsplit(' ', 1) | ||
| if len(parts) == 2: | ||
| params.append((parts[0].strip(), parts[1].strip())) | ||
| else: | ||
| # Handle case where type is implied from previous param | ||
| params.append(("", parts[0].strip())) | ||
|
|
||
| return params | ||
|
|
||
|
|
||
| def get_return_type_category(return_type: str) -> str: | ||
| """Categorize Go return type for serialization. | ||
|
|
||
| Args: | ||
| return_type: Go return type string like "*Employee" or "[]string" | ||
|
|
||
| Returns: | ||
| Category string like "entity_pointer", "string_list", "bool" | ||
| """ | ||
| return_type = return_type.strip() | ||
|
|
||
| if return_type == "bool": | ||
| return "bool" | ||
| if return_type == "error": | ||
| return "error" | ||
| if return_type.startswith("[]string"): | ||
| return "string_list" | ||
| if return_type.startswith("[]"): | ||
| return "entity_list" | ||
| if return_type.startswith("*"): | ||
| return "entity_pointer" | ||
| if return_type == "time.Duration": | ||
| return "duration" | ||
| if return_type == "DataVersion": | ||
| return "data_version" | ||
|
|
||
| return "unknown" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.