Skip to content

fix: update mpwrite and mpread methods to enforce 'LIB' as the only valid lib argument #4123

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

Merged
merged 13 commits into from
Aug 5, 2025

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented Jul 28, 2025

Description

As the title.

Issue linked

Close #3364

Checklist

Summary by Sourcery

Enforce "LIB" as the sole acceptable lib argument in mpwrite and mpread, updating defaults, error handling, and internal file-loading logic, and adjust tests to validate the new behavior.

Bug Fixes:

  • Reject non-"LIB" lib arguments in mpread with a clear MapdlRuntimeError.

Enhancements:

  • Default mpwrite and mpread lib parameter to "LIB" and streamline file path resolution for mpread using internal helpers.

Tests:

  • Update mpwrite tests to include the required mat argument and temp file cleanup.
  • Add a new test for mpread to verify reading with the default "LIB" lib and correct material count.

@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 12:18
@germa89 germa89 requested a review from a team as a code owner July 28, 2025 12:18
Copy link
Contributor

sourcery-ai bot commented Jul 28, 2025

Reviewer's Guide

Enforce 'LIB' as the sole valid library argument by updating mpwrite and mpread implementations to use default lib='LIB' with proper validation and file handling, remove legacy behaviors, and update tests to reflect the new API.

Class diagram for updated mpwrite and mpread methods

classDiagram
    class MapdlExtended {
        +mpwrite(fname, ext, lib="LIB", mat, download_file, progress_bar, **kwargs)
        +mpread(fname, ext, lib="LIB", **kwargs)
    }
    MapdlExtended --|> _MapdlCore
    class _MapdlCore {
        +mpwrite(fname, ext, lib, mat, **kwargs)
        +mpread(fname, ext, lib, **kwargs)
    }
Loading

Flow diagram for mpread 'lib' argument validation

flowchart TD
    A[Call mpread with lib argument] --> B{Is lib == 'LIB'?}
    B -- No --> C[Raise MapdlRuntimeError]
    B -- Yes --> D[Proceed with file handling and input]
Loading

File-Level Changes

Change Details Files
Restrict and validate lib argument in mpwrite/mpread implementations
  • Changed default lib parameter to 'LIB' in both methods
  • Enforce lib=='LIB' in mpread and raise MapdlRuntimeError otherwise
  • Updated mpwrite to pass lib and mat as keyword args to super()
  • Reworked mpread to use _get_file_name/_get_file_path and input() flow
src/ansys/mapdl/core/mapdl_extended.py
Revise tests for updated mpwrite/mpread behavior
  • Insert slashdelete calls before file-based tests
  • Add required mat argument to mpwrite assertions
  • Remove outdated NotImplementedError test for mpread lib
  • Introduce test_mpread_lib to validate default lib behavior and data count
tests/test_mapdl.py
Remove unused import and tidy module imports
  • Deleted unused load_file import from mapdl_extended.py
src/ansys/mapdl/core/mapdl_extended.py

Assessment against linked issues

Issue Objective Addressed Explanation
#3364 Update the PyMAPDL documentation page for the MPREAD command to clarify its usage. The PR only updates the implementation and tests for the mpread and mpwrite methods, enforcing 'LIB' as the only valid lib argument. There is no evidence in the diff or PR description of any changes to the documentation page for MPREAD.

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard 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

@germa89 germa89 self-assigned this Jul 28, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the mpwrite and mpread methods to enforce 'LIB' as the only valid value for the lib argument, addressing issue #3364. The changes remove the previous workaround that bypassed mpread with input and updates the implementation to properly validate the lib parameter.

  • Replaces the previous NotImplementedError with proper validation that only accepts 'LIB' for the lib argument
  • Updates mpread to use internal file handling methods instead of bypassing with input
  • Sets 'LIB' as the default value for the lib parameter in both methods

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/ansys/mapdl/core/mapdl_extended.py Updates mpwrite and mpread methods to enforce 'LIB' validation and use proper file handling
tests/test_mapdl.py Adds comprehensive test coverage for the new functionality and removes tests for the old error behavior

@github-actions github-actions bot added the bug Issue, problem or error in PyMAPDL label Jul 28, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @germa89 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/mapdl_extended.py:369` </location>
<code_context>
-                "The option 'lib' is not supported by the MAPDL gRPC server."
-            )
+    def mpread(self, fname="", ext="", lib="LIB", **kwargs):
+        if lib != "LIB":
+            raise MapdlRuntimeError("The 'lib' argument only support 'LIB' value.")

-        fname_ = fname + "." + ext
</code_context>

<issue_to_address>
The error message in MapdlRuntimeError contains a grammatical issue.

Please update the message to: 'The 'lib' argument only supports the 'LIB' value.'
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        if lib != "LIB":
            raise MapdlRuntimeError("The 'lib' argument only support 'LIB' value.")
=======
        if lib != "LIB":
            raise MapdlRuntimeError("The 'lib' argument only supports the 'LIB' value.")
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@germa89
Copy link
Collaborator Author

germa89 commented Jul 28, 2025

Pinging @mikerife for advice.

So far, we have set as default to use LIB for LIB argument in both. I couldn't make it work without LIB.

What do you think?

Copy link

codecov bot commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.28%. Comparing base (db31b73) to head (cfdf274).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4123      +/-   ##
==========================================
- Coverage   91.35%   91.28%   -0.08%     
==========================================
  Files         189      189              
  Lines       15650    15700      +50     
==========================================
+ Hits        14297    14331      +34     
- Misses       1353     1369      +16     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89
Copy link
Collaborator Author

germa89 commented Aug 5, 2025

@pyansys-ci-bot LGTM.

@germa89 germa89 enabled auto-merge (squash) August 5, 2025 07:46
Copy link
Contributor

@pyansys-ci-bot pyansys-ci-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approving this PR because germa89 said so in here 😬

LGTM

@germa89 germa89 merged commit 4eea4f1 into main Aug 5, 2025
78 of 83 checks passed
@germa89 germa89 deleted the fix/mpread-and-mpwrite branch August 5, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue, problem or error in PyMAPDL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: Update the PyMAPDL documentation page for MPREAD
2 participants