Skip to content

refactor: move methods from MapdlGrpc class to core and extended - #4108

Merged
germa89 merged 4 commits into
mainfrom
refactor/moving-methods-out-from-mapdl-grpc-class
Jul 21, 2025
Merged

refactor: move methods from MapdlGrpc class to core and extended#4108
germa89 merged 4 commits into
mainfrom
refactor/moving-methods-out-from-mapdl-grpc-class

Conversation

@germa89

@germa89 germa89 commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

Description

As the title.

Issue linked

Close #4102

Checklist

Summary by Sourcery

Refactor MapdlGrpc by relocating file handling, session management, screenshot, and import command wrapper methods into MapdlCore and MapdlExtended to streamline class responsibilities and close issue #4102

Enhancements:

  • Move list_files, _get_file_path, and _get_file_name methods from MapdlGrpc to MapdlCore
  • Relocate screenshot and session ID utilities from MapdlGrpc to MapdlCore
  • Transfer file, igesin, satin, cat5in, and parain wrappers from MapdlGrpc to MapdlExtended

Copilot AI review requested due to automatic review settings July 21, 2025 08:07
@germa89
germa89 requested a review from a team as a code owner July 21, 2025 08:07
@germa89 germa89 self-assigned this Jul 21, 2025
@ansys-reviewer-bot

Copy link
Copy Markdown
Contributor

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

@ansys-reviewer-bot review

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This refactor centralizes file handling, session management, and screenshot utilities into MapdlCore, moves command-specific wrappers into MapdlExtended, and cleans up redundant implementations in MapdlGrpc.

Class diagram for refactored MapdlCore, MapdlExtended, and MapdlGrpc

classDiagram
    class MapdlGrpc {
        - Removed: list_files()
        - Removed: _get_file_path()
        - Removed: _get_file_name()
        - Removed: file()
        - Removed: igesin()
        - Removed: satin()
        - Removed: cat5in()
        - Removed: parain()
        - Removed: screenshot()
        - Removed: _create_session()
        - Removed: _session_id
        - Removed: _check_session_id()
        - Removed: _get_mapdl_session_id()
    }
    class MapdlCore {
        + list_files(refresh_cache: bool = True) : List[str]
        + _get_file_path(fname: str, progress_bar: bool = False) : str
        + _get_file_name(fname, ext, default_extension) : str
        + screenshot(savefig: Optional[str] = None) : str
        + _create_session()
        + _session_id
        + _check_session_id()
        + _get_mapdl_session_id()
    }
    class MapdlExtended {
        + file(fname: str = "", ext: str = "", **kwargs) : str
        + igesin(fname, ext = "", **kwargs)
        + satin(name, extension = "", path = "", entity = "", fmt = "", nocl = "", noan = "", **kwargs)
        + cat5in(name, extension = "", path = "", entity = "", fmt = "", nocl = "", noan = "", **kwargs)
        + parain(name, extension = "", path = "", entity = "", fmt = "", scale = "", **kwargs)
    }
    MapdlGrpc <|-- MapdlCore
    MapdlCore <|-- MapdlExtended
Loading

Class diagram for file handling and session management centralization

classDiagram
    class MapdlCore {
        + list_files()
        + _get_file_path()
        + _get_file_name()
        + screenshot()
        + _create_session()
        + _session_id
        + _check_session_id()
        + _get_mapdl_session_id()
    }
    class MapdlExtended {
        + file()
        + igesin()
        + satin()
        + cat5in()
        + parain()
    }
    MapdlCore <|-- MapdlExtended
Loading

File-Level Changes

Change Details Files
Relocate file handling utilities to core class
  • Extracted _get_file_path from MapdlGrpc into MapdlCore
  • Ported _get_file_name logic to MapdlCore
  • Migrated list_files method into MapdlCore
src/ansys/mapdl/core/mapdl_grpc.py
src/ansys/mapdl/core/mapdl_core.py
Migrate screenshot and session management to core class
  • Moved screenshot implementation into MapdlCore
  • Added session lifecycle methods (_create_session, _session_id property, _check_session_id, _get_mapdl_session_id)
src/ansys/mapdl/core/mapdl_grpc.py
src/ansys/mapdl/core/mapdl_core.py
Move command wrappers into extended class
  • Shifted file wrapper override with corrected default ext into MapdlExtended
  • Relocated import command wrappers (igesin, satin, cat5in, parain) with proper wraps and remote handling
src/ansys/mapdl/core/mapdl_grpc.py
src/ansys/mapdl/core/mapdl_extended.py
Clean up MapdlGrpc by deleting moved implementations
  • Removed file ops, session management, screenshot, and command wrappers from MapdlGrpc
src/ansys/mapdl/core/mapdl_grpc.py

Assessment against linked issues

Issue Objective Addressed Explanation
#4102 Move the method _get_file_name from mapdl_grpc to mapdl_core.

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. 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

@github-actions github-actions Bot added the enhancement Improve any current implemented feature label Jul 21, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the PyMAPDL codebase by moving methods from the MapdlGrpc class to more appropriate locations in the core and extended modules. The changes improve code organization by distributing functionality according to architectural boundaries.

  • Moved several file handling and session management methods from mapdl_grpc.py to mapdl_core.py
  • Moved CAD file import methods to mapdl_extended.py for better modularity
  • Updated the file method implementation to handle different default extensions correctly

Reviewed Changes

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

File Description
src/ansys/mapdl/core/mapdl_grpc.py Removed methods and imports that were moved to core/extended modules
src/ansys/mapdl/core/mapdl_core.py Added core functionality methods including file handling, session management, and screenshot capability
src/ansys/mapdl/core/mapdl_extended.py Added CAD file import methods and updated file method with new logic

Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_core.py
Comment thread src/ansys/mapdl/core/mapdl_core.py

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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 found some issues that need to be addressed.

Blocking issues:

  • Variable 'path_' is referenced but not defined. (link)

General comments:

  • In mapdl_extended.py the file() override unpacks only file_, ext_, _ but then uses path_ which is never defined—adjust the unpacking to include path_ correctly.
  • You’ve changed the default extension in mapdl_extended.file from "rst" to "cdb"—please confirm this aligns with existing use cases to avoid unintended breakage.
  • The file‐handling helpers (_get_file_path, _get_file_name, list_files, screenshot) are duplicated across Core and Extended—consider extracting them into a shared mixin or utility module to reduce code drift.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In mapdl_extended.py the file() override unpacks only file_, ext_, _ but then uses path_ which is never defined—adjust the unpacking to include path_ correctly.
- You’ve changed the default extension in mapdl_extended.file from "rst" to "cdb"—please confirm this aligns with existing use cases to avoid unintended breakage.
- The file‐handling helpers (_get_file_path, _get_file_name, list_files, screenshot) are duplicated across Core and Extended—consider extracting them into a shared mixin or utility module to reduce code drift.

## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/mapdl_extended.py:109` </location>
<code_context>
-        fname = self._get_file_name(fname, ext, "rst")
+        fname = self._get_file_name(fname, ext, "cdb")
         fname = self._get_file_path(fname, kwargs.get("progress_bar", False))
         file_, ext_, _ = self._decompose_fname(fname)
-        return self._file(file_, ext_, **kwargs)
+        if self._local:
+            return self._file(filename=path_ / file_, extension=ext_, **kwargs)
+        else:
</code_context>

<issue_to_address>
Variable 'path_' is referenced but not defined.

'path_' is not defined in this context. Unpack it from '_decompose_fname' or update the variable name to match the unpacked values to avoid a NameError.
</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.

Comment thread src/ansys/mapdl/core/mapdl_extended.py
Comment thread src/ansys/mapdl/core/mapdl_core.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_core.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated
Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated
@codecov

codecov Bot commented Jul 21, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 85.63218% with 25 lines in your changes missing coverage. Please review.

Project coverage is 91.30%. Comparing base (f021ab2) to head (e71ef3e).
Report is 5 commits behind head on main.

❌ Your patch status has failed because the patch coverage (85.63%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4108      +/-   ##
==========================================
- Coverage   91.39%   91.30%   -0.09%     
==========================================
  Files         189      189              
  Lines       15667    15649      -18     
==========================================
- Hits        14319    14289      -30     
- Misses       1348     1360      +12     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89

germa89 commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator Author

Since it is a refactoring, let's not check the coverage.

@pyansys-ci-bot LGTM.

@germa89
germa89 enabled auto-merge (squash) July 21, 2025 18:46

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

Copy link
Copy Markdown
Contributor

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 86fa0c0 into main Jul 21, 2025
@germa89
germa89 deleted the refactor/moving-methods-out-from-mapdl-grpc-class branch July 21, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve any current implemented feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong location of _get_file_name

3 participants