-
Notifications
You must be signed in to change notification settings - Fork 0
Split generated runtime fallback #17
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
Open
leynos
wants to merge
7
commits into
main
Choose a base branch
from
sync-prosidy-darn-init-runtime-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f50274
Sync Python template runtime fallback
leynos c78ef55
Add complexity-antipatterns-and-refactoring-strategies.md
leynos 0259872
Clean up branch documentation formatting
leynos f844906
Address runtime fallback review findings
leynos 95eb3ae
Address public API documentation review findings
leynos e610903
Make generated runtime documentation discoverable
leynos 6be8939
Update generated PyO3 dependency for audit safety
leynos 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "config": { | ||
| "MD004": { "style": "dash" }, | ||
| "MD010": { "code_blocks": false }, | ||
| "MD013": { | ||
| "line_length": 80, | ||
| "code_block_line_length": 120, | ||
| "tables": false, | ||
| "headings": false | ||
| }, | ||
| "MD029": { "style": "ordered" } | ||
| }, | ||
| "ignores": [ | ||
| "**/.venv/**", | ||
| ".node_modules/**", | ||
| "**/node_modules/**", | ||
| "**/target/**", | ||
| ".terraform/**", | ||
| ".uv-cache/**", | ||
| "CRUSH.md" | ||
| ] | ||
| } |
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,13 @@ | ||
| """Tests for the public package API.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import {{ package_name }} | ||
|
|
||
|
|
||
| def test_hello_uses_configured_backend() -> None: | ||
| """Verify the expected greeting for this generated project.""" | ||
| expected_greeting = "{% if use_rust %}hello from Rust{% else %}hello from Python{% endif %}" | ||
| assert {{ package_name }}.hello() == expected_greeting, ( | ||
| "expected public hello() to return the configured backend greeting" | ||
| ) |
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 |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| """{{ project_name }} package.""" | ||
| """Public package entry point for {{ project_name }}. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| import typing as typ | ||
| The package exposes the supported public API for generated projects. Import | ||
| from this module when application code needs the package's main functionality; | ||
| the package selects the configured backend internally and exports `hello` as | ||
| the stable greeting function. | ||
|
|
||
| if typ.TYPE_CHECKING: | ||
| import collections.abc as cabc | ||
| Examples | ||
| -------- | ||
| >>> import {{ package_name }} | ||
| >>> {{ package_name }}.hello() | ||
| "{% if use_rust %}hello from Rust{% else %}hello from Python{% endif %}" | ||
| """ | ||
|
|
||
| PACKAGE_NAME = "{{ package_name }}" | ||
| from __future__ import annotations | ||
|
|
||
| try: # pragma: no cover - Rust optional | ||
| rust = importlib.import_module(f"._{PACKAGE_NAME}_rs", package=__name__) | ||
| hello = typ.cast("cabc.Callable[[], str]", rust.hello) | ||
| except ModuleNotFoundError: # pragma: no cover - Python fallback | ||
| from .pure import hello | ||
| from ._runtime import hello | ||
|
|
||
| __all__ = ["hello"] |
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,37 @@ | ||
| """Select the generated package implementation backend. | ||
|
|
||
| This module keeps `__init__.py` as a stable public re-export while isolating | ||
| the logic that chooses between the optional Rust extension and the pure Python | ||
| implementation. External callers should import the package root and call | ||
| `{{ package_name }}.hello()`. Internal generated code may import `hello` from | ||
| `._runtime` when it needs the already-selected backend function. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import {{ package_name }} | ||
| >>> {{ package_name }}.hello() | ||
| "{% if use_rust %}hello from Rust{% else %}hello from Python{% endif %}" | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
| {% if use_rust %} | ||
| import importlib | ||
| import typing as typ | ||
|
|
||
| if typ.TYPE_CHECKING: | ||
| import collections.abc as cabc | ||
|
|
||
| PACKAGE_NAME = "{{ package_name }}" | ||
| RUST_MODULE_NAME = f"_{PACKAGE_NAME}_rs" | ||
| EXPECTED_RUST_MODULE_NAME = f"{PACKAGE_NAME}.{RUST_MODULE_NAME}" | ||
|
|
||
| try: # pragma: no cover - Rust optional | ||
| rust = importlib.import_module(f".{RUST_MODULE_NAME}", package=__package__) | ||
| hello = typ.cast("cabc.Callable[[], str]", rust.hello) | ||
| except ModuleNotFoundError as exc: # pragma: no cover - Python fallback | ||
| if exc.name != EXPECTED_RUST_MODULE_NAME: | ||
| raise | ||
| from .pure import hello as hello | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| {%- else %} | ||
| from .pure import hello as hello | ||
| {%- endif %} | ||
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
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.