Skip to content

fix: command conversion - #4126

Merged
germa89 merged 10 commits into
mainfrom
fix/command_conversion
Jul 31, 2025
Merged

fix: command conversion#4126
germa89 merged 10 commits into
mainfrom
fix/command_conversion

Conversation

@clatapie

@clatapie clatapie commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes a few issues related to the conversion of the the MAPDL documentation.
Concerned functions:

  • clear
  • file
  • mrep

Checklist

Summary by Sourcery

Add clear() and file() methods, fix mrep argument formatting, and modernize documentation by using Sphinx cross-reference syntax for APDL commands across the codebase

New Features:

  • Expose the APDL /CLEAR command via a new clear() method in the database setup
  • Introduce the FILE command as a new file() method in the POST1 setup

Bug Fixes:

  • Remove redundant positional separator in mrep() to correct argument formatting

Enhancements:

  • Standardize docstrings across multiple modules by replacing literal APDL command mentions with Sphinx :ref: cross-references

@clatapie
clatapie requested review from Copilot and germa89 July 28, 2025 14:00
@clatapie
clatapie requested a review from a team as a code owner July 28, 2025 14:00
@clatapie
clatapie requested a review from pyansys-ci-bot July 28, 2025 14:00
@sourcery-ai

sourcery-ai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implements Python wrappers for the MAPDL FILE and /CLEAR commands with complete docstrings and examples, corrects the MREP command signature to align with APDL syntax, and standardizes documentation by converting literal command mentions to Sphinx cross-references and refining doc formatting across multiple modules.

Class diagram for new and updated command wrappers (FILE, CLEAR, MREP)

classDiagram
    class SetUp {
        +clear(read: str = "", **kwargs)
        ...
    }
    class SetUpPost1 {
        +file(fname: str = "", ext: str = "", **kwargs)
        ...
    }
    class SetUpGraphics {
        +mrep(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)
        ...
    }
    SetUp <|-- SetUpPost1 : uses
    SetUp <|-- SetUpGraphics : uses
Loading

Class diagram for FILE command wrapper in SetUpPost1

classDiagram
    class SetUpPost1 {
        +file(fname: str = "", ext: str = "", **kwargs)
        ...
    }
Loading

Class diagram for CLEAR command wrapper in SetUp

classDiagram
    class SetUp {
        +clear(read: str = "", **kwargs)
        ...
    }
Loading

Class diagram for corrected MREP command signature in SetUpGraphics

classDiagram
    class SetUpGraphics {
        +mrep(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)
        ...
    }
Loading

File-Level Changes

Change Details Files
Introduce Python wrapper for FILE command
  • Added new file() method in Post1 SetUp class
  • Wrote detailed docstring with parameters, notes, and examples
  • Built command string and return via self.run
src/ansys/mapdl/core/_commands/post1/set_up.py
Introduce Python wrapper for /CLEAR command
  • Added clear() method in Database SetUp class
  • Wrote detailed docstring covering parameters and usage notes
  • Built command string and return via self.run
src/ansys/mapdl/core/_commands/database/set_up.py
Fix MREP command argument formatting
  • Removed redundant comma in f-string argument list
  • Aligned parameter ordering to match APDL /MREP syntax
src/ansys/mapdl/core/_commands/graphics/set_up.py
Standardize documentation cross-references and styling
  • Replaced literal FILE and /CLEAR mentions with Sphinx :ref: cross-references
  • Updated command mentions (e.g. FILE, /CLEAR) across various modules
  • Fixed minor whitespace and punctuation in docstrings
src/ansys/mapdl/core/_commands/post1/set_up.py
src/ansys/mapdl/core/_commands/post1/special_purpose.py
src/ansys/mapdl/core/_commands/post1/load_case_calculations.py
src/ansys/mapdl/core/_commands/post26/display.py
src/anssys/mapdl/core/_commands/post26/set_up.py
src/anssys/mapdl/core/_commands/aux2/binary_file_manipulation.py
src/anssys/mapdl/core/_commands/apdl/parameter_definition.py
src/anssys/mapdl/core/_commands/apdl/matrix_operations.py
src/anssys/mapdl/core/_commands/aux15/iges.py
src/anssys/mapdl/core/_commands/session/files.py
src/anssys/mapdl/core/_commands/session/processor_entry.py
src/anssys/mapdl/core/_commands/session/run_controls.py

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 bug Issue, problem or error in PyMAPDL label Jul 28, 2025

@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 @clatapie - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • No input validation is performed on fname or ext. (link)

General comments:

  • The new file method name shadows the built-in Python file identifier—consider renaming (e.g., set_file) to avoid confusion and potential conflicts.
  • The updated /MREP signature removed a placeholder argument—please verify this change matches the official APDL command spec so parameters don’t shift unexpectedly.
  • After adding clear and file commands, ensure they’re included in the module’s public API (e.g., in __all__ or the command registry) so they’re discoverable and autocompletable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `file` method name shadows the built-in Python `file` identifier—consider renaming (e.g., `set_file`) to avoid confusion and potential conflicts.
- The updated `/MREP` signature removed a placeholder argument—please verify this change matches the official APDL command spec so parameters don’t shift unexpectedly.
- After adding `clear` and `file` commands, ensure they’re included in the module’s public API (e.g., in `__all__` or the command registry) so they’re discoverable and autocompletable.

## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/_commands/post1/set_up.py:629` </location>
<code_context>
+        POST26
+        ^^^^^^
+        """
+        command = f"FILE,{fname},{ext}"
+        return self.run(command, **kwargs)
+
</code_context>

<issue_to_address>
No input validation is performed on fname or ext.

Special characters in these inputs could lead to malformed APDL commands or injection risks. Please add validation or sanitization to ensure safe input values.

Suggested implementation:

```python
    import re

    def file(self, fname: str = "", ext: str = "", **kwargs):
        r"""Specifies the data file where results are to be found.

        Mechanical APDL Command: `FILE <https://ansyshelp.ansys.com/Views/Secured/corp/v232/en//ans_cmd/Hlp_C_FILE.html>`_

        Parameters
        ----------
        fname : str
            File name and directory path (248 characters maximum, including the characters needed for the
            directory path). An unspecified directory path defaults to the working directory; in this case,
            Only alphanumeric characters, underscores, hyphens, and periods are allowed. Directory separators are allowed.
        ext : str
            File extension. Only alphanumeric characters and underscores are allowed.

        Raises
        ------
        ValueError
            If `fname` or `ext` contains invalid characters.

```

```python
        # Allow alphanumerics, underscores, hyphens, periods, and directory separators in fname
        if not re.match(r'^[\w\-.\\/]*$', fname):
            raise ValueError(
                f"Invalid characters in fname: {fname!r}. Only alphanumerics, underscores, hyphens, periods, and directory separators are allowed."
            )
        # Allow only alphanumerics and underscores in ext
        if not re.match(r'^[\w]*$', ext):
            raise ValueError(
                f"Invalid characters in ext: {ext!r}. Only alphanumerics and underscores are allowed."
            )

        command = f"FILE,{fname},{ext}"
        return self.run(command, **kwargs)

```
</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/_commands/post1/set_up.py
@clatapie clatapie changed the title fix: command converion fix: command conversion Jul 28, 2025

@germa89 germa89 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me. Thank you @clatapie !

@germa89
germa89 enabled auto-merge (squash) July 29, 2025 15:25
Comment thread src/ansys/mapdl/core/mapdl_extended.py Outdated

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov

codecov Bot commented Jul 31, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.30%. Comparing base (db31b73) to head (491793d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4126      +/-   ##
==========================================
- Coverage   91.35%   91.30%   -0.05%     
==========================================
  Files         189      189              
  Lines       15650    15657       +7     
==========================================
- Hits        14297    14296       -1     
- Misses       1353     1361       +8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89
germa89 merged commit 10b2e1b into main Jul 31, 2025
43 checks passed
@germa89
germa89 deleted the fix/command_conversion branch July 31, 2025 17:19
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.

4 participants