Anselmoo / spectrafit

📊📈🔬 SpectraFit is a command-line and Jupyter-notebook tool for quick data-fitting based on the regular expression of distribution functions.
https://anselmoo.github.io/spectrafit/
BSD 3-Clause "New" or "Revised" License
25 stars 7 forks source link

refactor: :recycle: File I/O operations for better readability and maintainability #1621

Closed Anselmoo closed 3 days ago

Anselmoo commented 3 days ago

All PR-Submissions:


New ✨✨ Feature-Submissions:


Changes to ⚙️ Core-Features:


Summary by Sourcery

Refactor file I/O operations to enhance code readability and maintainability by replacing open() function calls with the Path.open() method across various modules.

Enhancements:

semanticdiff-com[bot] commented 3 days ago

Review changes with SemanticDiff.

Analyzed 9 of 9 files.

Overall, the semantic diff is 82% smaller than the GitHub diff.

Filename Status
:heavy_check_mark: spectrafit/tools.py 53.71% smaller
:heavy_check_mark: spectrafit/plugins/data_converter.py 47.8% smaller
:heavy_check_mark: spectrafit/plugins/file_converter.py 85.65% smaller
:heavy_check_mark: spectrafit/plugins/notebook.py 94.24% smaller
:heavy_check_mark: spectrafit/plugins/pkl_converter.py 31.81% smaller
:heavy_check_mark: spectrafit/plugins/pkl_visualizer.py 67.62% smaller
:heavy_check_mark: spectrafit/plugins/pptx_converter.py 43.97% smaller
:heavy_check_mark: spectrafit/plugins/rixs_converter.py 89.19% smaller
:heavy_check_mark: spectrafit/plugins/rixs_visualizer.py 43.98% smaller
sourcery-ai[bot] commented 3 days ago

Reviewer's Guide by Sourcery

This pull request refactors file I/O operations across multiple files in the spectrafit project to improve readability and maintainability. The main change is the consistent use of the Path.open() method instead of the built-in open() function for file operations. This change simplifies the file opening process and makes the code more idiomatic when working with pathlib.Path objects.

Sequence Diagram

sequenceDiagram
    participant C as Code
    participant P as Path Object
    participant F as File
    C->>P: Create Path object
    C->>P: Call open() method
    P->>F: Open file
    F-->>C: Return file object
    C->>F: Perform I/O operations
    C->>F: Close file

File-Level Changes

Change Details Files
Refactored file I/O operations to use Path.open() method
  • Replaced open() function calls with Path.open() method
  • Simplified file path handling by using Path objects directly
  • Updated file opening modes to be consistent across different file types
  • Removed redundant path construction in some cases
spectrafit/plugins/file_converter.py
spectrafit/plugins/notebook.py
spectrafit/tools.py
spectrafit/plugins/rixs_converter.py
spectrafit/plugins/pkl_visualizer.py
spectrafit/plugins/rixs_visualizer.py
spectrafit/plugins/data_converter.py
spectrafit/plugins/pkl_converter.py
spectrafit/plugins/pptx_converter.py

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. #### 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).
sonarcloud[bot] commented 3 days ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

codecov[bot] commented 3 days ago

Codecov Report

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

Project coverage is 100.00%. Comparing base (6349d58) to head (3ca511a). Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1621 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 44 44 Lines 4468 4468 ========================================= Hits 4468 4468 ``` | [Flag](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn) | `100.00% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn) | Coverage Δ | | |---|---|---| | [spectrafit/plugins/data\_converter.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Fdata_converter.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL2RhdGFfY29udmVydGVyLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/file\_converter.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Ffile_converter.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL2ZpbGVfY29udmVydGVyLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/notebook.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Fnotebook.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL25vdGVib29rLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/pkl\_converter.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Fpkl_converter.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL3BrbF9jb252ZXJ0ZXIucHk=) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/pkl\_visualizer.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Fpkl_visualizer.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL3BrbF92aXN1YWxpemVyLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/pptx\_converter.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Fpptx_converter.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL3BwdHhfY29udmVydGVyLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/rixs\_converter.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Frixs_converter.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL3JpeHNfY29udmVydGVyLnB5) | `100.00% <100.00%> (ø)` | | | [spectrafit/plugins/rixs\_visualizer.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Fplugins%2Frixs_visualizer.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC9wbHVnaW5zL3JpeHNfdmlzdWFsaXplci5weQ==) | `100.00% <100.00%> (ø)` | | | [spectrafit/tools.py](https://app.codecov.io/gh/Anselmoo/spectrafit/pull/1621?src=pr&el=tree&filepath=spectrafit%2Ftools.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anselm+Hahn#diff-c3BlY3RyYWZpdC90b29scy5weQ==) | `100.00% <100.00%> (ø)` | |