Fix: src layout without package#42
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds a CodeRabbit config, bumps package version to 0.7.2, generalizes many examples/docs to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
holm/_model.py (1)
142-159: Update or remove the outdated comment.The comment at Lines 142-144 states that catching import exceptions is "undesired because it would be hard for users to find why an API is not registered." However, the new code at Lines 152-159 now catches all exceptions and logs a warning instead of propagating them.
This creates a documentation inconsistency. Consider either:
- Updating the comment to explain the trade-off and why the new approach is preferred for src layout support
- Making the exception handling more specific (e.g., only catch
ImportErrororModuleNotFoundErrorrelated to configuration issues)The current approach of catching all exceptions (including
SyntaxError,AttributeError, etc.) and logging warnings could hide legitimate bugs in user code. While the full traceback is logged, warnings are easier to miss than exceptions during development.🔎 Suggested comment update
- # Check if the module exists. Trying to import it and catching the exception would hide possible - # import error that occur in within the module, which is undesired because it would be hard for - # users to find why an API is not registered. + # Check if the module file exists before attempting import. if not (self.package_dir / f"{name}.py").is_file(): return None # Support applications that are not wrapped in a Python package. import_name = name if self.package_name in _no_app_package_roots else f"{self.package_name}.{name}" try: module = import_module(import_name) except Exception: import traceback - # Handle potential misconfigurations with a simple warning, instead of an exception. + # For src/flat layouts, import path misconfigurations are possible. Log the full + # traceback as a warning rather than crashing, allowing the application to continue + # with other modules. Users should monitor logs for these warnings during development. logger = logging.getLogger("holm") logger.warning(f"Failed to import module {name} at: {import_name}") logger.warning(traceback.format_exc()) return None
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.coderabbit.yamlholm/__init__.pyholm/_model.py
🔇 Additional comments (4)
.coderabbit.yaml (1)
1-3: LGTM!The configuration correctly disables automatic issue enrichment per the schema. This is a valid preference setting with no impact on the codebase functionality.
holm/__init__.py (1)
1-1: LGTM!Appropriate version bump to reflect the src layout support feature.
holm/_model.py (2)
149-149: LGTM!The change from equality check to membership test correctly extends support to both "" (src layout) and "." (flat layout), aligning with the PR objectives.
88-94: Constant definition looks good, but layout mapping needs confirmation.The flat layout organizes configuration and import packages in the top-level directory, while the src layout moves importable code into a subdirectory typically named src/. The constant uses a set for efficient membership testing, which is appropriate.
However, the docstring's mapping of
""to src layout and"."to flat layout should be verified against the actual import_name values that Flask/Werkzeug assigns in these scenarios, as this specific detail is not documented in standard Python packaging guidance.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
docs/guides/forms.mddocs/guides/path-parameters.mddocs/in-a-hurry.mdexamples/forms/layout.pyexamples/forms/page.pyexamples/path-parameters/user/_id_/page.pytest_app/user/_user_id_/api.py
🧰 Additional context used
🧬 Code graph analysis (2)
test_app/user/_user_id_/api.py (1)
test_app/user/_user_id_/page.py (1)
htmy(19-24)
examples/path-parameters/user/_id_/page.py (3)
examples/forms/page.py (1)
page(70-72)examples/path-parameters/user/page.py (1)
page(8-19)examples/path-parameters/page.py (1)
page(7-17)
🔇 Additional comments (7)
examples/forms/page.py (1)
4-4: Import addition looks good.ComponentType is imported to support the generalized return type annotation.
docs/guides/path-parameters.md (1)
206-206: Documentation accurately reflects the ComponentType refactoring.The updated import and return type annotation in the documentation example align with the actual code changes in
examples/path-parameters/user/_id_/page.py.Also applies to: 238-238
examples/forms/layout.py (1)
8-8: Public API return types appropriately generalized.Both
head()andsearch_form()return types have been updated toComponentType, making these helper components more flexible. The implementations still return concrete html elements (html.headandhtml.form), which should be compatible with the generic type.Also applies to: 28-28
test_app/user/_user_id_/api.py (1)
3-3: Test app updated consistently with examples.The
user_cardfunction return type has been generalized toComponentType, matching the pattern applied across examples and maintaining consistency in the codebase.Also applies to: 25-25
examples/path-parameters/user/_id_/page.py (1)
4-4: Example updated with generalized return type.The
page()function now returnsComponentTypeinstead of a specific HTML element type, aligning with the broader refactoring effort across the codebase.Also applies to: 36-36
docs/guides/forms.md (1)
109-109: Documentation examples updated to reflect ComponentType refactoring.All function signatures in the guide now use
ComponentTypefor return types, accurately reflecting the changes made to the corresponding example code inexamples/forms/.Also applies to: 133-133, 203-214
docs/in-a-hurry.md (1)
47-61: Introduction guide updated with ComponentType pattern.The documentation examples now consistently demonstrate using
ComponentTypefor function parameters and return types, providing clear guidance for users on the recommended approach for building holm applications.Also applies to: 72-100
enabled by default
Fixes #41
Summary by CodeRabbit
New Features
Bug Fixes
Chores
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.