Skip to content

Conversation

@germa89
Copy link
Collaborator

@germa89 germa89 commented Jun 25, 2025

Description

As the title.

Issue linked

Extracted from #1300.

Checklist

Summary by Sourcery

Improve the inquire method to provide typed and consistent return values, handle missing responses gracefully, and support boolean queries.

Enhancements:

  • Return None when in non-interactive mode and no response is received.
  • Extract the last line of multiline responses for ENV and TITLE inquiries.
  • Parse and strip the response value for all inquiries.
  • Return boolean values for EXIST, WRITE, READ, and EXEC inquiries, with error handling on unexpected output.
  • Convert numeric responses to floats and fall back to strings for non-numeric outputs.

@germa89 germa89 requested a review from a team as a code owner June 25, 2025 11:03
@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 25, 2025

Reviewer's Guide

Refactors the inquire method to add non-interactive exit handling, streamline multiline output processing, support boolean responses for certain functions, and enable numeric fallback parsing.

File-Level Changes

Change Details Files
Handle empty responses in non-interactive mode
  • Return None when no response and not storing commands
  • Remove nested else wrapping multiline logic
src/ansys/mapdl/core/mapdl_extended.py
Unify multiline output extraction for ENV and TITLE
  • Apply splitlines()[-1] outside response-existence block
  • Simplify response trimming logic
src/ansys/mapdl/core/mapdl_extended.py
Map specific functions to boolean results
  • Detect EXIST/WRITE/READ/EXEC functions
  • Return True for “1.0” and False for “0.0”
  • Raise error on unexpected boolean output
src/ansys/mapdl/core/mapdl_extended.py
Introduce numeric conversion fallback
  • Wrap float conversion in try/except
  • Return raw string if ValueError occurs
src/ansys/mapdl/core/mapdl_extended.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. 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

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 - here's some feedback:

  • Update the inquire method docstring to mention the new None return in non-interactive mode.
  • Add a guard to check for an '=' in the response before splitting, to avoid unexpected IndexError.
  • Include a unit test for the branch that raises on unexpected boolean output to ensure correct error handling.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Update the `inquire` method docstring to mention the new None return in non-interactive mode.
- Add a guard to check for an '=' in the response before splitting, to avoid unexpected `IndexError`.
- Include a unit test for the branch that raises on unexpected boolean output to ensure correct error handling.

## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/mapdl_extended.py:1466` </location>
<code_context>
+
+        # Check if the function is to check existence
+        # so it makes sense to return a boolean
+        if func.upper() in ["EXIST", "WRITE", "READ", "EXEC"]:
+            if "1.0" in response:
+                return True
+            elif "0.0" in response:
+                return False
+            else:
+                raise MapdlRuntimeError(
+                    f"Unexpected output from 'mapdl.inquire' function:\n{response}"
+                )

-        return response
</code_context>

<issue_to_address>
String matching for boolean response may be fragile.

Using substring matching for '1.0' and '0.0' may cause incorrect results if these values appear elsewhere in the response. Use an exact match to ensure correct boolean conversion.
</issue_to_address>

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.

@github-actions github-actions bot added the new feature Request or proposal for a new feature label Jun 25, 2025
@germa89 germa89 enabled auto-merge (squash) June 25, 2025 11:32
@germa89 germa89 self-assigned this Jun 25, 2025
@germa89
Copy link
Collaborator Author

germa89 commented Jun 25, 2025

@pyansys-ci-bot LGTM.

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

@codecov
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.14%. Comparing base (53ad87c) to head (cac0037).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4035      +/-   ##
==========================================
+ Coverage   89.05%   89.14%   +0.09%     
==========================================
  Files         187      187              
  Lines       14970    14993      +23     
==========================================
+ Hits        13331    13365      +34     
+ Misses       1639     1628      -11     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89 germa89 disabled auto-merge June 25, 2025 11:57
@germa89 germa89 merged commit 72263e1 into main Jun 26, 2025
49 checks passed
@germa89 germa89 deleted the feat/improving-inquire branch June 26, 2025 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Request or proposal for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants