cleder / fastkml

Fast ๐ŸŒ๏ธ <KML /> processing for python
https://fastkml.readthedocs.io
229 stars 92 forks source link

18 add screenoverlay support #393

Closed cleder closed 1 week ago

cleder commented 1 week ago

User description

workerB


PR Type

enhancement, tests


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
containers.py
Add ScreenOverlay support to containers module                     

fastkml/containers.py
  • Added import for ScreenOverlay.
  • Updated __all__ to include ScreenOverlay.
  • Registered ScreenOverlay in the registry.
  • +16/-2   
    overlays.py
    Implement ScreenOverlay and related classes for KML overlays

    fastkml/overlays.py
  • Introduced _XY class for screen positioning.
  • Added OverlayXY, ScreenXY, RotationXY, and Size classes.
  • Implemented ScreenOverlay class with detailed initialization.
  • Registered new classes in the registry.
  • +412/-0 
    Tests
    overlay_test.py
    Add hypothesis tests for ScreenOverlay and related classes

    tests/hypothesis/overlay_test.py
  • Added tests for OverlayXY, RotationXY, ScreenXY, and Size.
  • Introduced hypothesis tests for ScreenOverlay.
  • +67/-0   
    strategies.py
    Add hypothesis strategy for OverlayXY related classes       

    tests/hypothesis/strategies.py - Added `xy` strategy for generating `OverlayXY` related test data.
    +8/-0     
    overlays_test.py
    Add tests for ScreenOverlay functionality                               

    tests/overlays_test.py
  • Added test for ScreenOverlay creation from string.
  • Updated test classes to include ScreenOverlay.
  • +66/-5   
    Documentation
    HISTORY.rst
    Update changelog for ScreenOverlay support                             

    docs/HISTORY.rst - Updated changelog to include ScreenOverlay support.
    +2/-0     

    ๐Ÿ’ก PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Summary by CodeRabbit


    [!IMPORTANT] Add ScreenOverlay support to fastkml, including new classes for screen positioning and comprehensive tests.

    • Behavior:
      • Implemented ScreenOverlay class in overlays.py for screen-fixed image overlays.
      • Added _XY class and derivatives (OverlayXY, ScreenXY, RotationXY, Size) for screen positioning.
      • Registered ScreenOverlay and related classes in the registry.
    • Integration:
      • Updated containers.py to import and register ScreenOverlay.
      • Added ScreenOverlay to __all__ in __init__.py.
    • Tests:
      • Added hypothesis tests for ScreenOverlay and related classes in overlay_test.py.
      • Introduced xy strategy in strategies.py for generating test data.
    • Documentation:
      • Updated HISTORY.rst to include ScreenOverlay support.

    This description was created by Ellipsis for d836ecfad424552bed2dadc6e590f6e24737e046. It will automatically update as commits are pushed.

    semanticdiff-com[bot] commented 1 week ago

    Review changes with  SemanticDiff

    Changed Files
    | File | Status | | :--- | :--- | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/containers.py)  [fastkml/containers\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/containers.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/containers.py)  75% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/overlays_test.py)  [tests/overlays\_test\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/overlays_test.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/overlays_test.py)  2% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#docs/HISTORY.rst)  [docs/HISTORY\.rst](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#docs/HISTORY.rst) | Unsupported file format | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/__init__.py)  [fastkml/\_\_init\_\_\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/__init__.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/__init__.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/overlays.py)  [fastkml/overlays\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/overlays.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#fastkml/overlays.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/overlay_test.py)  [tests/hypothesis/overlay\_test\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/overlay_test.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/overlay_test.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/strategies.py)  [tests/hypothesis/strategies\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/strategies.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/393/changes#tests/hypothesis/strategies.py)  0% smaller |
    sourcery-ai[bot] commented 1 week ago

    Reviewer's Guide by Sourcery

    This PR adds support for ScreenOverlay in the fastkml library. The implementation includes new classes for handling screen coordinates and overlay positioning, along with comprehensive test coverage. The changes follow the existing patterns in the codebase for KML element handling.

    Class diagram for new ScreenOverlay support

    classDiagram
        class _XMLObject {
        }
        class _XY {
            +Optional~float~ x
            +Optional~float~ y
            +Optional~Units~ x_units
            +Optional~Units~ y_units
            +__init__(Optional~str~ ns, Optional~Dict~ name_spaces, Optional~float~ x, Optional~float~ y, Optional~Units~ x_units, Optional~Units~ y_units)
            +__repr__() str
            +__bool__() bool
        }
        _XY --|> _XMLObject
        class OverlayXY {
            +get_tag_name() str
        }
        OverlayXY --|> _XY
        class ScreenXY {
            +get_tag_name() str
        }
        ScreenXY --|> _XY
        class RotationXY {
            +get_tag_name() str
        }
        RotationXY --|> _XY
        class Size {
            +get_tag_name() str
        }
        Size --|> _XY
        class _Overlay {
        }
        class ScreenOverlay {
            +Optional~OverlayXY~ overlay_xy
            +Optional~ScreenXY~ screen_xy
            +Optional~RotationXY~ rotation_xy
            +Optional~Size~ size
            +Optional~float~ rotation
            +__init__(Optional~str~ ns, Optional~Dict~ name_spaces, Optional~str~ id, Optional~str~ target_id, Optional~str~ name, Optional~bool~ visibility, Optional~bool~ isopen, Optional~atom.Link~ atom_link, Optional~atom.Author~ atom_author, Optional~str~ address, Optional~str~ phone_number, Optional~Snippet~ snippet, Optional~str~ description, Optional~Union~ view, Optional~Union~ times, Optional~StyleUrl~ style_url, Optional~Iterable~ styles, Optional~Region~ region, Optional~ExtendedData~ extended_data, Optional~str~ color, Optional~int~ draw_order, Optional~Icon~ icon, Optional~OverlayXY~ overlay_xy, Optional~ScreenXY~ screen_xy, Optional~RotationXY~ rotation_xy, Optional~Size~ size, Optional~float~ rotation)
            +__repr__() str
        }
        ScreenOverlay --|> _Overlay
        _Overlay <|-- ScreenOverlay
        note for ScreenOverlay "Handles screen overlay elements in KML"

    File-Level Changes

    Change Details Files
    Added new base class for handling screen coordinates
    • Created _XY base class to handle x/y coordinates with units
    • Implemented coordinate validation and string representation
    • Added registry entries for x, y, xunits, and yunits attributes
    fastkml/overlays.py
    Implemented ScreenOverlay and related positioning classes
    • Added OverlayXY, ScreenXY, RotationXY, and Size classes for overlay positioning
    • Created ScreenOverlay class with support for all KML attributes
    • Added registry entries for all new overlay-related elements
    fastkml/overlays.py
    Added test coverage for new overlay functionality
    • Created TestScreenOverlay class with XML parsing tests
    • Added property-based tests using Hypothesis for XY coordinates
    • Implemented fuzz testing for ScreenOverlay and positioning classes
    tests/overlays_test.py
    tests/hypothesis/overlay_test.py
    tests/hypothesis/strategies.py
    Updated container support for ScreenOverlay
    • Added ScreenOverlay to the list of supported feature types
    • Updated registry entries to include ScreenOverlay in containers
    fastkml/containers.py

    Possibly linked issues


    Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
    coderabbitai[bot] commented 1 week ago

    Walkthrough

    The pull request introduces significant updates to the fastkml library, including the addition of support for ScreenOverlay. Version 1.0.0dev0 is noted in the changelog, followed by version 1.0, which drops Python 2 support, mandates pygeoif version 1.0 or higher, and removes native support for shapely. The codebase has been refactored with added type annotations, replaced the dateutil library with arrow, and introduced an informative __repr__ method. New classes related to overlays are defined, and tests for these functionalities are enhanced.

    Changes

    File Path Change Summary
    docs/HISTORY.rst Updated changelog for version 1.0.0dev0 (added support for ScreenOverlay) and version 1.0 (dropped Python 2, etc.).
    fastkml/containers.py Added import for ScreenOverlay, updated __all__, modified _Container registration to include ScreenOverlay.
    fastkml/overlays.py Introduced classes _XY, OverlayXY, ScreenXY, RotationXY, Size, and ScreenOverlay, with updated constructors.
    tests/hypothesis/overlay_test.py Added parameterized tests for overlay classes and a test for ScreenOverlay.
    tests/hypothesis/strategies.py Introduced new partial strategy xy for generating coordinate pairs with units.
    tests/overlays_test.py Created TestScreenOverlay class with a method for testing ScreenOverlay creation from KML string; renamed existing classes.

    Possibly related PRs

    Suggested labels

    enhancement, Tests, documentation

    Poem

    In the land of KML, a new feature's born,
    With ScreenOverlay, our hearts are worn.
    Python 2's gone, we embrace the new,
    Type annotations shine, like morning dew.
    With tests all ready, our code's set to play,
    Hopping into version 1.0, hip-hip-hooray! ๐Ÿ‡โœจ


    ๐Ÿ“œ Recent review details **Configuration used: .coderabbit.yaml** **Review profile: CHILL**
    ๐Ÿ“ฅ Commits Reviewing files that changed from the base of the PR and between 0d641e11aeb1e62a56b550bf3d83e43ee69b3e87 and d836ecfad424552bed2dadc6e590f6e24737e046.
    ๐Ÿ“’ Files selected for processing (1) * `fastkml/__init__.py` (2 hunks)
    ๐Ÿ”‡ Additional comments (1)
    fastkml/__init__.py (1) `49-49`: **LGTM! Clean implementation of ScreenOverlay exports.** The changes properly expose the new `ScreenOverlay` functionality by: 1. Importing it from the correct module 2. Adding it to `__all__` in the appropriate location The implementation maintains consistency with the existing codebase structure and follows Python best practices for module exports. Also applies to: 76-76

    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    โค๏ธ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
    ๐Ÿชง Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
    codiumai-pr-agent-free[bot] commented 1 week ago

    PR Reviewer Guide ๐Ÿ”

    Here are some key observations to aid the review process:

    โฑ๏ธ Estimated effort to review: 4 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšช
    ๐Ÿงช PR contains tests
    ๐Ÿ”’ No security concerns identified
    โšก Recommended focus areas for review

    Input Validation
    The _XY class and its derivatives (OverlayXY, ScreenXY, etc.) accept any float values for x and y coordinates without validation. Should validate that values are within reasonable bounds. Default Values
    The ScreenOverlay class has many optional parameters but lacks default values for key positioning attributes like overlay_xy and screen_xy. Consider adding sensible defaults. Error Handling
    The __bool__ method in _XY class only checks if x and y are not None, but doesn't validate units. Should handle invalid unit combinations.
    github-actions[bot] commented 1 week ago

    Preparing review...

    codiumai-pr-agent-free[bot] commented 1 week ago

    PR Code Suggestions โœจ

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add validation for coordinate values when using fractional units ___ **Add validation in _XY class to ensure x and y coordinates are valid when units are
    set to 'fraction' (must be between 0 and 1).** [fastkml/overlays.py [1290-1299]](https://github.com/cleder/fastkml/pull/393/files#diff-53d4a4402d4b36ba24c38b2494214f2940433d433946065052596dbd37cc3565R1290-R1299) ```diff def __init__( self, ns: Optional[str] = None, name_spaces: Optional[Dict[str, str]] = None, x: Optional[float] = None, y: Optional[float] = None, x_units: Optional[Units] = None, y_units: Optional[Units] = None, **kwargs: Any, ) -> None: + if x is not None and x_units == Units.fraction and not 0 <= x <= 1: + raise ValueError("x must be between 0 and 1 when units is fraction") + if y is not None and y_units == Units.fraction and not 0 <= y <= 1: + raise ValueError("y must be between 0 and 1 when units is fraction") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This validation is critical for preventing invalid coordinate values when using fractional units, which must be between 0 and 1. Missing this validation could lead to incorrect overlay positioning and rendering errors.
    9
    Add validation to ensure rotation values stay within valid bounds ___ **Add validation for rotation value to ensure it stays within valid range of -180 to
    180 degrees. Currently the rotation parameter can accept any float value.** [fastkml/overlays.py [1451-1458]](https://github.com/cleder/fastkml/pull/393/files#diff-53d4a4402d4b36ba24c38b2494214f2940433d433946065052596dbd37cc3565R1451-R1458) ```diff def __init__( self, ns: Optional[str] = None, name_spaces: Optional[Dict[str, str]] = None, ... rotation: Optional[float] = None, **kwargs: Any, ) -> None: + if rotation is not None and not -180 <= rotation <= 180: + raise ValueError("rotation must be between -180 and 180 degrees") ```
    Suggestion importance[1-10]: 8 Why: The suggestion adds important validation to prevent invalid rotation values that could cause rendering issues or unexpected behavior. The -180 to 180 degree constraint is a standard range for rotation angles.
    8

    ๐Ÿ’ก Need additional feedback ? start a PR chat

    github-actions[bot] commented 1 week ago

    Failed to generate code suggestions for PR

    codiumai-pr-agent-free[bot] commented 1 week ago

    CI Failure Feedback ๐Ÿง

    (Checks updated until commit https://github.com/cleder/fastkml/commit/d836ecfad424552bed2dadc6e590f6e24737e046)

    **Action:** SonarCloud
    **Failed stage:** [SonarCloud Scan](https://github.com/cleder/fastkml/actions/runs/11996447472/job/33440897512) [โŒ]
    **Failure summary:** The action failed because there was an error while trying to retrieve the pull request with key
    '393'. This error occurred during the auto-configuration process for the pull request.
    Relevant error logs: ```yaml 1: ##[group]Operating System 2: Ubuntu ... 260: 13:13:12.052 INFO Check ALM binding of project 'cleder_fastkml' 261: 13:13:12.525 INFO Detected project binding: BOUND 262: 13:13:12.525 INFO Check ALM binding of project 'cleder_fastkml' (done) | time=472ms 263: 13:13:12.526 INFO Load project pull requests 264: 13:13:13.000 INFO Load project pull requests (done) | time=473ms 265: 13:13:13.001 INFO Load branch configuration 266: 13:13:13.002 INFO Github event: pull_request 267: 13:13:13.009 INFO Auto-configuring pull request 393 268: 13:13:13.526 ERROR Something went wrong while trying to get the pullrequest with key '393' 269: 13:13:13.850 INFO EXECUTION FAILURE ```

    โœจ CI feedback usage guide:
    The CI feedback tool (`/checks)` automatically triggers when a PR has a failed check. The tool analyzes the failed checks and provides several feedbacks: - Failed stage - Failed test name - Failure summary - Relevant error logs In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR: ``` /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}" ``` where `{repo_name}` is the name of the repository, `{run_number}` is the run number of the failed check, and `{job_number}` is the job number of the failed check. #### Configuration options - `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true. - `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list. - `enable_help_text` - if set to true, the tool will provide a help message with the feedback. Default is true. - `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true. - `final_update_message` - if `persistent_comment` is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true. See more information about the `checks` tool in the [docs](https://pr-agent-docs.codium.ai/tools/ci_feedback/).
    github-actions[bot] commented 1 week ago

    Preparing review...

    codecov[bot] commented 1 week ago

    Codecov Report

    All modified and coverable lines are covered by tests :white_check_mark:

    Project coverage is 100.00%. Comparing base (a6b5087) to head (d836ecf). Report is 6 commits behind head on develop.

    Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #393 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 68 68 Lines 5661 5745 +84 Branches 149 149 ========================================= + Hits 5661 5745 +84 ```

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.


    ๐Ÿšจ Try these New Features:

    github-actions[bot] commented 1 week ago

    Preparing review...