cleder / fastkml

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

1.0.0 release candidate 2 #387

Closed cleder closed 2 weeks ago

cleder commented 2 weeks ago

User description

Last release candidate before 1.0


PR Type

enhancement, tests, dependencies


Description


Changes walkthrough ๐Ÿ“

Relevant files
Configuration changes
2 files
about.py
Update version number for release candidate.                         

fastkml/about.py - Updated version number from `1.0.0rc1` to `1.0.0rc2`.
+1/-1     
tox.ini
Update tox configuration for linting.                                       

tox.ini - Removed per-file ignore for `fastkml/utils.py`.
+0/-1     
Enhancement
4 files
base.py
Refactor XML encoding to use unicode.                                       

fastkml/base.py
  • Changed XML encoding from UTF-8 to unicode.
  • Removed unnecessary decoding steps.
  • +2/-6     
    kml.py
    Add KML and KMZ file writing functionality.                           

    fastkml/kml.py
  • Added write method to handle KML and KMZ file writing.
  • Utilized zipfile for KMZ file creation.
  • +43/-0   
    times.py
    Refactor datetime parsing logic.                                                 

    fastkml/times.py
  • Simplified parse method logic.
  • Improved handling of datetime parsing.
  • +3/-5     
    utils.py
    Add utility function for attribute retrieval.                       

    fastkml/utils.py
  • Added get_all_attrs utility function.
  • Refactored find_all to use get_all_attrs.
  • +29/-11 
    Error handling
    1 files
    helpers.py
    Improve error handling in datetime parsing.                           

    fastkml/helpers.py
  • Changed return type of datetime_subelement_kwarg.
  • Added error handling using try-except.
  • +11/-10 
    Tests
    3 files
    atom_test.py
    Update atom link namespace in tests.                                         

    tests/atom_test.py - Updated test to use `atom` namespace.
    +2/-4     
    kml_test.py
    Enhance KML writing tests with file handling.                       

    tests/kml_test.py
  • Added tests for KML and KMZ file writing.
  • Refactored existing tests for clarity.
  • +122/-48
    times_test.py
    Add tests for datetime parsing exceptions.                             

    tests/times_test.py - Added exception handling tests for datetime parsing.
    +10/-2   
    Dependencies
    1 files
    run-all-tests.yml
    Update Codecov action version in CI workflow.                       

    .github/workflows/run-all-tests.yml - Updated Codecov action version from 4 to 5.
    +1/-1     

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

    Summary by CodeRabbit

    Release Notes

    semanticdiff-com[bot] commented 2 weeks ago

    Review changes with  SemanticDiff

    Changed Files
    | File | Status | | :--- | :--- | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/helpers.py)  [fastkml/helpers\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/helpers.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/helpers.py)  77% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/atom_test.py)  [tests/atom\_test\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/atom_test.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/atom_test.py)  52% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/base.py)  [fastkml/base\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/base.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/base.py)  47% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/times.py)  [fastkml/times\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/times.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/times.py)  42% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/times_test.py)  [tests/times\_test\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/times_test.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/times_test.py)  29% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/utils.py)  [fastkml/utils\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/utils.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/utils.py)  28% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#.github/workflows/run-all-tests.yml)  [\.github/workflows/run\-all\-tests\.yml](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#.github/workflows/run-all-tests.yml) | Unsupported file format | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/about.py)  [fastkml/about\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/about.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/about.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/kml.py)  [fastkml/kml\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/kml.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#fastkml/kml.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/kml_test.py)  [tests/kml\_test\.py](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/kml_test.py) | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tests/kml_test.py)  0% smaller | | [](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tox.ini)  [tox\.ini](https://app.semanticdiff.com/gh/cleder/fastkml/pull/387/changes#tox.ini) | Unsupported file format |
    sourcery-ai[bot] commented 2 weeks ago

    Reviewer's Guide by Sourcery

    This release candidate 2 for version 1.0.0 includes several significant improvements to the KML handling library. The changes focus on enhancing file writing capabilities, refactoring test organization, improving error handling for datetime parsing, and optimizing XML string encoding. The implementation maintains backward compatibility while introducing new features and fixing existing issues.

    Class diagram for KML writing enhancements

    classDiagram
        class KML {
            +write(file_path: Path, prettyprint: bool, precision: Optional[int], verbosity: Verbosity)
        }
        class Path
        class Verbosity
        KML --> Path
        KML --> Verbosity
        note for KML "New method added for writing KML and KMZ files"

    Class diagram for utility function refactoring

    classDiagram
        class Utils {
            +get_all_attrs(obj: object) Generator[object, None, None]
            +find_all(obj: object, of_type: Type, **kwargs) Generator[object, None, None]
        }
        note for Utils "Refactored to use get_all_attrs for attribute iteration"

    Class diagram for datetime parsing improvements

    classDiagram
        class KmlDateTime {
            +parse(datestr: str) Optional[KmlDateTime]
        }
        class DateTimeResolution
        KmlDateTime --> DateTimeResolution
        note for KmlDateTime "Improved error handling and parsing logic"

    File-Level Changes

    Change Details Files
    Added new KML file writing functionality
    • Implemented write method to support both KML and KMZ file formats
    • Added support for pretty printing XML output
    • Implemented ZIP compression for KMZ files
    • Added file encoding handling with UTF-8 support
    fastkml/kml.py
    Improved datetime parsing and error handling
    • Changed datetime parsing to raise ValueError instead of returning None
    • Enhanced error messages for invalid datetime formats
    • Updated regular expression handling for year/month/day parsing
    fastkml/times.py
    tests/times_test.py
    Optimized XML string handling and encoding
    • Switched to unicode encoding for XML string conversion
    • Removed redundant UTF-8 encoding/decoding steps
    • Simplified string conversion process
    fastkml/base.py
    Refactored utility functions and test organization
    • Extracted attribute iteration logic into new get_all_attrs function
    • Reorganized test classes for better structure
    • Added new test cases for KML/KMZ file writing
    fastkml/utils.py
    tests/kml_test.py
    Updated CI/CD and version configurations
    • Upgraded codecov-action from v4 to v5
    • Bumped version to 1.0.0rc2
    • Removed unnecessary code complexity ignore in tox.ini
    .github/workflows/run-all-tests.yml
    fastkml/about.py
    tox.ini

    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 2 weeks ago

    Walkthrough

    The pull request introduces multiple updates primarily to the testing framework and functionality of the fastkml package. Key modifications include enhancements to the GitHub Actions workflow for testing, updates to the version number, changes in method signatures and error handling in various files, and the addition of new methods for KML handling. The testing suite has also been expanded with new classes and methods to ensure comprehensive coverage of KML and KMZ file operations.

    Changes

    File Change Summary
    .github/workflows/run-all-tests.yml Updated cpython-lxml job to use codecov-action@v5, added a new step to doctest-lxml for running Python code examples, expanded static-tests to include various checks, and clarified build-package with a pyroma check.
    fastkml/about.py Updated version number from 1.0.0rc1 to 1.0.0rc2.
    fastkml/base.py Modified to_string method in _XMLObject class to change encoding from "UTF-8" to "unicode" and removed redundant decoding step.
    fastkml/helpers.py Changed return type of datetime_subelement_kwarg from Dict[str, List["KmlDateTime"]] to Dict[str, "KmlDateTime"], adjusting internal logic accordingly.
    fastkml/kml.py Added write method to KML class for writing KML data to files, handling both .kmz and regular KML formats.
    fastkml/times.py Updated regex in KmlDateTime class for date parsing and refactored parse method to return a KmlDateTime instance instead of None on failure.
    fastkml/utils.py Introduced get_all_attrs function for retrieving object attributes, modified find_all to use this new function.
    tests/atom_test.py Modified test_atom_link_ns to instantiate atom.Link without a namespace argument and updated assertions accordingly.
    tests/kml_test.py Added TestWriteKML class with methods for writing KML and KMZ files, restructured existing tests for KML parsing.
    tests/times_test.py Updated error handling in KmlDateTime.parse tests to expect ValueError instead of None.
    tox.ini Removed exclusion for CCR001 error code in flake8 section for fastkml/utils.py.

    Possibly related PRs

    Suggested labels

    Review effort [1-5]: 3, documentation

    ๐Ÿฐ In the meadow, changes bloom,
    With tests and methods to dispel gloom.
    KML and KMZ, now write with ease,
    Our code hops forward, like a breeze!
    Version updated, errors refined,
    In this rabbit's world, all is aligned! ๐ŸŒผ


    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.
    what-the-diff[bot] commented 2 weeks ago

    PR Summary

    codiumai-pr-agent-free[bot] commented 2 weeks ago

    PR Reviewer Guide ๐Ÿ”

    Here are some key observations to aid the review process:

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

    Error Handling
    The parse method now returns a KmlDateTime object instead of Optional[KmlDateTime]. This could cause issues if callers expect None for invalid inputs. File Handling
    The write method should validate the file path and handle file system errors gracefully. Currently missing error handling for file operations. Encoding Change
    Changed XML encoding from UTF-8 to unicode which could affect compatibility with systems expecting UTF-8 encoded output.
    codiumai-pr-agent-free[bot] commented 2 weeks ago

    PR Code Suggestions โœจ

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add error handling for file operations to improve robustness ___ **Add error handling for file writing operations to handle potential IOError,
    PermissionError, or other file-related exceptions.** [fastkml/kml.py [248-289]](https://github.com/cleder/fastkml/pull/387/files#diff-613ee78b8f0776d39e81909e8b514a8053b408d2dc58eb0830deb146a8e12141R248-R289) ```diff def write( self, file_path: Path, *, prettyprint: bool = True, precision: Optional[int] = None, verbosity: Verbosity = Verbosity.normal, ) -> None: element = self.etree_element(precision=precision, verbosity=verbosity) try: xml_content = config.etree.tostring( element, encoding="unicode", pretty_print=prettyprint, ) except TypeError: xml_content = config.etree.tostring( element, encoding="unicode", ) - if file_path.suffix == ".kmz": - with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as kmz: - kmz.writestr("doc.kml", xml_content) - else: - with file_path.open("w", encoding="UTF-8") as file: - file.write(xml_content) + try: + if file_path.suffix == ".kmz": + with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as kmz: + kmz.writestr("doc.kml", xml_content) + else: + with file_path.open("w", encoding="UTF-8") as file: + file.write(xml_content) + except (IOError, PermissionError) as e: + raise IOError(f"Failed to write KML file: {e}") from e ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: The suggestion adds important error handling for file operations, which could prevent silent failures and provide better error messages for common file-related issues like permission errors or disk space problems.
    8
    Possible bug
    Add null check to prevent potential attribute access on None ___ **Add a check for None before accessing node.text to prevent potential AttributeError.** [fastkml/times.py [101]](https://github.com/cleder/fastkml/pull/387/files#diff-d08f0cfb2c0a85d0242f75c5991bd60a29a6b73cf9eaedfe64733b951a5cf162R101-R101) ```diff -node_text = node.text.strip() if node.text else "" +node_text = node.text.strip() if node and node.text else "" ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: The suggestion prevents a potential AttributeError by adding a null check before accessing node.text, making the code more robust against unexpected None values.
    7
    Enhancement
    Improve type checking before iteration to prevent potential errors ___ **Add type checking before attempting to iterate over attribute values to prevent
    potential TypeError.** [fastkml/utils.py [54-56]](https://github.com/cleder/fastkml/pull/387/files#diff-060b770075f2288337b9fc44aa876789980283fc689f1b9d568df336fe39df45R54-R56) ```diff -try: +if isinstance(attr, (list, tuple, set)): yield from attr -except TypeError: +else: yield attr ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 5 Why: The suggestion replaces a try-except block with explicit type checking, making the code more readable and potentially more efficient, though the current implementation using try-except is also valid.
    5

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

    github-actions[bot] commented 2 weeks ago

    Failed to generate code suggestions for PR

    github-actions[bot] commented 2 weeks ago

    Preparing review...

    github-actions[bot] commented 2 weeks ago

    Preparing review...

    codiumai-pr-agent-free[bot] commented 2 weeks ago

    CI Failure Feedback ๐Ÿง

    **Action:** SonarCloud
    **Failed stage:** [SonarCloud Scan](https://github.com/cleder/fastkml/actions/runs/11878226818/job/33098644569) [โŒ]
    **Failure summary:** The action failed because there was an error while trying to retrieve the pull request with key 387.
    This prevented the action from proceeding with the necessary configurations and checks for the pull
    request.
    Relevant error logs: ```yaml 1: ##[group]Operating System 2: Ubuntu ... 265: 10:51:35.754 INFO Check ALM binding of project 'cleder_fastkml' 266: 10:51:35.906 INFO Detected project binding: BOUND 267: 10:51:35.907 INFO Check ALM binding of project 'cleder_fastkml' (done) | time=152ms 268: 10:51:35.909 INFO Load project pull requests 269: 10:51:36.077 INFO Load project pull requests (done) | time=170ms 270: 10:51:36.079 INFO Load branch configuration 271: 10:51:36.080 INFO Github event: pull_request 272: 10:51:36.087 INFO Auto-configuring pull request 387 273: 10:51:36.249 ERROR Something went wrong while trying to get the pullrequest with key '387' 274: 10:51:36.574 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/).