Skip to content

fix: improve code quality and numpydoc documentation #4125

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented Jul 28, 2025

Related to

#2414

Summary

  • Fix typo in _get_file_name docstring parameter description
  • Replace bare except clauses with specific OSError exceptions in launcher.py
  • Remove duplicate logging statement in licensing.py, use LOG.info instead
  • Add missing Parameters and Returns sections to Information class methods
  • Fix GL02 docstring formatting issues (closing quotes placement)
  • Add Returns section to convert.py format_using_autopep8 method

Changes Made

Code Quality Improvements:

  • Fixed docstring typo in mapdl_core.py:3195 - corrected "with our with extension" to "with or without extension"
  • Improved exception handling in launcher.py by replacing bare except: clauses with specific except OSError:
  • Cleaned up logging in licensing.py by removing duplicate print statement

Numpydoc Validation Fixes:

  • Added Parameters section to Information class docstring documenting the mapdl parameter
  • Added Returns sections to multiple methods that were missing return documentation
  • Fixed GL02 formatting issues by ensuring closing quotes are on separate lines
  • Enhanced documentation quality for better API consistency

Test plan

  • Code compiles without syntax errors
  • All changes are backward compatible
  • No functional changes to existing behavior
  • Numpydoc validation errors significantly reduced
  • Documentation improvements enhance API usability

Summary by Sourcery

Improve code quality by replacing broad exception handlers and simplifying logging, and enhance API documentation by completing and correcting Numpydoc docstrings.

Enhancements:

  • Replace bare except clauses with specific OSError exception handlers in launcher.py
  • Remove duplicate print-based logging and switch to LOG.info in licensing.py

Documentation:

  • Add missing Parameters and Returns sections to Information class methods and convert.py format_using_autopep8
  • Fix typo in _get_file_name docstring parameter description
  • Resolve GL02 formatting issues by ensuring closing quotes are on separate lines

- Fix typo in _get_file_name docstring parameter description
- Replace bare except clauses with specific OSError exceptions in launcher.py
- Remove duplicate logging statement in licensing.py, use LOG.info instead
- Add missing Parameters and Returns sections to Information class methods
- Fix GL02 docstring formatting issues (closing quotes placement)
- Add Returns section to convert.py format_using_autopep8 method
@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 13:28
@germa89 germa89 requested a review from a team as a code owner July 28, 2025 13:28
Copy link
Contributor

sourcery-ai bot commented Jul 28, 2025

Reviewer's Guide

This PR enhances code quality by refactoring docstrings for NumPy style compliance, tightening exception handling in launcher.py, and cleaning up redundant logging in licensing.py without altering existing behavior.

Class diagram for updated Information class documentation

classDiagram
    class Information {
        +__init__(mapdl: Mapdl)
        +_mapdl: Mapdl
        +_update() None
        +__repr__() str
        +product: str
        +mapdl_version: str
        +mapdl_version_update: str
        +pymapdl_version: str
    }
    %% Note: Only docstrings and documentation were updated, no structural changes to methods or attributes.
Loading

File-Level Changes

Change Details Files
Refactor docstrings to comply with numpydoc standards
  • Correct typo in file name docstring parameter
  • Add Parameters section to Information class initializer
  • Insert Returns sections in Information properties and convert method
  • Fix closing-quote placement for GL02 formatting
src/ansys/mapdl/core/mapdl_core.py
src/ansys/mapdl/core/information.py
src/ansys/mapdl/core/convert.py
Improve exception handling
  • Replace bare except clauses with specific except OSError
src/ansys/mapdl/core/launcher.py
Clean up logging
  • Remove duplicate print and consolidate to LOG.info
src/ansys/mapdl/core/licensing.py

Possibly linked issues

  • Cannot import name "_parsefull" #1: PR adds missing parameter and return descriptions, directly addressing the issue's concern about incomplete documentation and unhelpful tooltips.

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

@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 focuses on improving code quality and numpydoc documentation compliance across multiple MAPDL core files. The changes address docstring formatting issues, enhance exception handling, and clean up logging statements.

  • Fixed a typo in docstring parameter description and improved exception handling specificity
  • Enhanced numpydoc compliance by adding missing Parameters and Returns sections to documentation
  • Cleaned up duplicate logging statements and improved docstring formatting consistency

Reviewed Changes

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

Show a summary per file
File Description
src/ansys/mapdl/core/mapdl_core.py Fixed typo in _get_file_name docstring parameter description
src/ansys/mapdl/core/licensing.py Removed duplicate logging statement, consolidated to single LOG.info call
src/ansys/mapdl/core/launcher.py Replaced bare except clauses with specific OSError exceptions
src/ansys/mapdl/core/information.py Added missing Parameters section to class docstring and Returns sections to property methods
src/ansys/mapdl/core/convert.py Added missing Returns section to format_using_autopep8 method

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!


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 dependencies maintenance General maintenance of the repo (libraries, cicd, etc) bug Issue, problem or error in PyMAPDL labels Jul 28, 2025
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 93.93939% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.30%. Comparing base (514cfae) to head (b8d907d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4125   +/-   ##
=======================================
  Coverage   91.30%   91.30%           
=======================================
  Files         189      189           
  Lines       15698    15706    +8     
=======================================
+ Hits        14333    14341    +8     
  Misses       1365     1365           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot removed dependencies maintenance General maintenance of the repo (libraries, cicd, etc) labels Jul 29, 2025
@germa89
Copy link
Collaborator Author

germa89 commented Aug 1, 2025

Skipping coverage since it is minor.

@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

@germa89
Copy link
Collaborator Author

germa89 commented Aug 1, 2025

My idea was to fix all the numpydocs issues in this PR. But it is waaay to much work for only one PR. So... this is just one.

By files

COUNT    | LINE
-----------------------------------------------------
     106 | src/ansys/mapdl/core/mapdl_extended.py
      92 | src/ansys/mapdl/core/mapdl_core.py
      91 | src/ansys/mapdl/core/mapdl_grpc.py
      51 | src/ansys/mapdl/core/post.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
      46 | src/ansys/mapdl/core/mesh_grpc.py
Details

COUNT | LINE

 106 | src/ansys/mapdl/core/mapdl_extended.py
  92 | src/ansys/mapdl/core/mapdl_core.py
  91 | src/ansys/mapdl/core/mapdl_grpc.py
  51 | src/ansys/mapdl/core/post.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
  46 | src/ansys/mapdl/core/mesh_grpc.py
  41 | src/ansys/mapdl/core/misc.py
  39 | src/ansys/mapdl/core/post.py
  38 | src/ansys/mapdl/core/launcher.py
  31 | src/ansys/mapdl/core/mapdl_geometry.py
  30 | src/ansys/mapdl/core/information.py
  30 | src/ansys/mapdl/core/solution.py
  27 | src/ansys/mapdl/core/parameters.py
  23 | src/ansys/mapdl/core/errors.py
  22 | src/ansys/mapdl/core/plotting/visualizer.py
  21 | src/ansys/mapdl/core/mapdl_core.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
  20 | src/ansys/mapdl/core/mapdl_grpc.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
  19 | src/ansys/mapdl/core/xpl.py
  18 | src/ansys/mapdl/core/component.py
  18 | src/ansys/mapdl/core/database/database.py
  16 | src/ansys/mapdl/core/mapdl_geometry.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
  16 | src/ansys/mapdl/core/pool.py
  13 | src/ansys/mapdl/core/convert.py
  13 | src/ansys/mapdl/core/licensing.py
  12 | src/ansys/mapdl/core/inline_functions/line_queries.py
  12 | src/ansys/mapdl/core/krylov.py
  10 | src/ansys/mapdl/core/logging.py
   9 | .ci/pytest_summary.py
   9 | src/ansys/mapdl/core/parameters.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   8 | src/ansys/mapdl/core/database/nodes.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   8 | src/ansys/mapdl/core/licensing.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   7 | src/ansys/mapdl/core/mapdl_console.py
   6 | src/ansys/mapdl/core/component.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   6 | src/ansys/mapdl/core/database/elems.py
   6 | src/ansys/mapdl/core/launcher.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   6 | src/ansys/mapdl/core/mapdl_extended.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   5 | src/ansys/mapdl/core/database/elems.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   5 | src/ansys/mapdl/core/database/nodes.py
   4 | src/ansys/mapdl/core/database/database.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   4 | src/ansys/mapdl/core/logging.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   4 | src/ansys/mapdl/core/mesh_grpc.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   3 | src/ansys/mapdl/core/convert.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   3 | src/ansys/mapdl/core/database/elems.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   3 | src/ansys/mapdl/core/inline_functions/component_queries.pydocstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   3 | src/ansys/mapdl/core/mesh/mesh.py
   3 | src/ansys/mapdl/core/xpl.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | 
   2 | src/ansys/mapdl/core/database/nodes.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | src/ansys/mapdl/core/helpers.py
   2 | src/ansys/mapdl/core/information.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | src/ansys/mapdl/core/inline_functions/core.py
   2 | src/ansys/mapdl/core/mapdl_console.py'loglevel'} not documented
   2 | src/ansys/mapdl/core/mapdl_console.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | src/ansys/mapdl/core/mapdl_core.py'graphics_backend', 'log_apdl', 'log_file'} not documented
   2 | src/ansys/mapdl/core/mapdl_extended.py'plot_bc_labels', 'plot_bc_legend', 'bc_glyph_size'}
   2 | src/ansys/mapdl/core/mapdl_extended.pydocumented
   2 | src/ansys/mapdl/core/mapdl_grpc.pydocumented
   2 | src/ansys/mapdl/core/misc.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | src/ansys/mapdl/core/report.py
   2 | src/ansys/mapdl/core/solution.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   2 | src/ansys/mapdl/core/xpl.pyin the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/_version.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/cli/convert.py'check_parameter_names', 'clear_at_start', 'output', 'cleanup_output', 'line_ending', 'comment_solve', 'macros_as_functions', 'exec_file', 'add_imports', 'file', 'auto_exit', 'loglevel', 'header'} not documented
   1 | src/ansys/mapdl/core/common_grpc.py
   1 | src/ansys/mapdl/core/common_grpc.pythe quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/convert.py'add_imports', 'macros_as_functions', 'line_ending', 'show_log', 'print_com', 'cleanup_output', 'clear_at_start', 'graphics_backend', 'loglevel', 'header', 'auto_exit', 'filename_out', 'comment_solve'} not documented
   1 | src/ansys/mapdl/core/errors.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/inline_functions/inline_functions.py
   1 | src/ansys/mapdl/core/jupyter.py
   1 | src/ansys/mapdl/core/jupyter.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/krylov.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/mapdl_console.py'nproc'} not documented
   1 | src/ansys/mapdl/core/mapdl_core.pydocumented
   1 | src/ansys/mapdl/core/mapdl_extended.py'kloop', '**kwargs', 'it1num'} not documented
   1 | src/ansys/mapdl/core/mapdl_extended.py'par16', 'par3', 'par12', 'par13', 'par8', 'par10', 'par5', '**kwargs', 'par7', 'par19', 'par18'} not documented
   1 | src/ansys/mapdl/core/mapdl_extended.py'show_line_numbering'} not documented
   1 | src/ansys/mapdl/core/mapdl_extended.pynot documented
   1 | src/ansys/mapdl/core/mapdl_grpc.py'disable_run_at_connect', 'cleanup_on_exit', 'remote_instance', '**start_parm', 'remove_temp_dir_on_exit', 'loglevel', 'print_com', 'port', 'ip'} not documented
   1 | src/ansys/mapdl/core/mapdl_grpc.py'item2', 'item4', 'entnum'} not documented
   1 | src/ansys/mapdl/core/mapdl_grpc.py'option2', 'option6'} not documented
   1 | src/ansys/mapdl/core/mapdl_grpc.py["PNG"', 'Optional', 'disable_run_at_connect
   1 | src/ansys/mapdl/core/mapdl.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/mesh/mesh.pydocumented
   1 | src/ansys/mapdl/core/mesh/mesh.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/parameters.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/plotting/plotting_defaults.py'shaft_radius'} not documented
   1 | src/ansys/mapdl/core/plotting/theme.pyclose the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/plotting/visualizer.py'color', 'feature_angle', 'show_edges', 'edge_color', 'background', 'n_colors', 'add_point_labels_kwargs', 'show_axes', 'point_size', 'render_points_as_spheres', 'opacity', 'text_color', 'render_lines_as_tubes', 'split_sharp_edges', 'lighting', 'smooth_shading', 'font_family', 'scalar_bar_args', 'show_scalar_bar', 'add_mesh_kwargs', 'style', 'cmap', 'theme', 'flip_scalars', 'font_size', 'show_bounds'} not documented
   1 | src/ansys/mapdl/core/plotting/visualizer.py'line_width', 'color', 'show_edges', 'edge_color', 'background', 'n_colors', 'add_point_labels_kwargs', 'plotter_kwargs', 'show_axes', 'meshes', 'point_size', 'render_points_as_spheres', 'opacity', 'plot_bc_legend', 'text_color', 'render_lines_as_tubes', 'split_sharp_edges', 'lighting', 'smooth_shading', 'font_family', 'title', 'scalar_bar_args', 'points', 'labels', 'show_scalar_bar', 'plot_bc_labels', 'add_mesh_kwargs', 'return_cpos', 'bc_labels_font_size', 'style', 'cmap', 'bc_labels', 'theme', 'mapdl', 'flip_scalars', 'bc_glyph_size', 'plot_bc', 'font_size', 'bc_target', 'show_bounds', 'return_plotter'} not documented
   1 | src/ansys/mapdl/core/plotting/visualizer.py'plot_bc_labels', 'plot_bc_legend'} not documented
   1 | src/ansys/mapdl/core/plotting/visualizer.py'return_cpos', 'notebook'} not documented
   1 | src/ansys/mapdl/core/pool.py'exec_file'} not documented
   1 | src/ansys/mapdl/core/pool.py'restart_failed', 'override', 'timeout', 'names', 'run_location', 'progress_bar', 'exec_file', 'wait'} not documented
   1 | src/ansys/mapdl/core/pool.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)
   1 | src/ansys/mapdl/core/report.pydocumented
   1 | src/ansys/mapdl/core/report.pyquotes in the same line as the text, or leave a blank line between the last text and the quotes)

1022 | TOTAL LINES
  95 | DISTINCT LINES

By issues

COUNT    | LINE
-----------------------------------------------------
     435 | RT01 No Returns section found
     334 | PR01 Parameters
     204 | GL02 Closing quotes should be placed in the line after the last text
Details

COUNT    | LINE
-----------------------------------------------------
     435 | RT01 No Returns section found
     334 | PR01 Parameters
     204 | GL02 Closing quotes should be placed in the line after the last text
      16 | PR02 Unknown parameters
      14 | RT03 Return value has no description
       5 | RT04 Return value description should start with a capital letter
       2 | 
       1 | GL09 Deprecation warning should precede extended summary
-----------------------------------------------------
    1011 | TOTAL LINES
       8 | DISTINCT LINES

@germa89
Copy link
Collaborator Author

germa89 commented Aug 1, 2025

GL02 has been fixed in 920ddc2

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.

2 participants