Skip to content

CHORE: Enforce ruff pyflakes F rules#6239

Merged
SMoraisAnsys merged 35 commits into
mainfrom
chore/enforce-ruff-pyflakes-F-rules
Jun 25, 2025
Merged

CHORE: Enforce ruff pyflakes F rules#6239
SMoraisAnsys merged 35 commits into
mainfrom
chore/enforce-ruff-pyflakes-F-rules

Conversation

@ecoussoux-ansys
Copy link
Copy Markdown
Contributor

@ecoussoux-ansys ecoussoux-ansys commented Jun 6, 2025

Description

This PR is a follow-up to #6157, which introduced a minimal configuration for ruff to pyaedt and to #6203, which applied the "E" rules (related to pycodestyle) on the entire codebase.
Here, the "F" rules (related to Pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f) are enforced, allowing their removal from the list of ignored linting rules for ruff.

This effort is part of the migration of pyaedt towards using ruff for code formatting and linting, as requested in issue #4775.
This PR is also contributing to the efforts described in issue #5504.

"F" rules were incrementally applied (one rule per commit) using the same approach as in #6203.
The strategy followed for enforcing this set of rules has been to avoid as much as possible the deactivation of specific checks on a per-file basis and the creation of special cases. This has occasionally involved introducing some debatable changes, which reviewers might want to pay particular attention to: These are listed below, together with other non-trivial modifications suggested in this PR:

  • The approach for fixing errors related to rule F401 (unused-import) in __init__.py files was to follow one of the methods described in https://docs.astral.sh/ruff/rules/unused-import/, which consists in explicitly declaring the imported symbols as part of the modules' interfaces using __all__. Some instances of in-file noqa: F401 were also removed where possible,
  • A refactoring of the imports in src/ansys/aedt/core/__init__.py was applied, so that variables and classes are directly imported from the modules in which these are defined,
  • Rule F403 (undefined-local-with-import-star) only impacted files in the src/pyaedt/ folder. Therefore, it was decided to ignore this rule for all files from this folder in order not to invest time in tedious refactoring of this deprecated part of the codebase,
  • Rule F821 (undefined-name) is ignored in file doc/source/Resources/pyaedt_installer_from_aedt.py for lack of a better alternative for managing variables specific to IronPython with respect to this rule,
  • The test test_plot_insertion_losses in test_touchstone_data.py was modified. Currently the variable res returned line 32 is equal to []: res is not []returns True but the syntax res != [] recommended by ruff will return False. Therefore, the asserted equality is rewritten to res == [], in line with the result actually obtained from this test, despite it seeming to contradict the previous implementation for this check,
  • The ruff pre-commit hook is updated in .pre-commit-config.yaml.

Issue linked

Related to #4775 and #5504.

@ecoussoux-ansys ecoussoux-ansys self-assigned this Jun 6, 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

@github-actions github-actions Bot added maintenance Package and maintenance related documentation Improvements or additions to documentation labels Jun 6, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 85.29%. Comparing base (0e05f78) to head (9ce27d7).

❌ Your patch check has failed because the patch coverage (80.00%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6239   +/-   ##
=======================================
  Coverage   85.29%   85.29%           
=======================================
  Files         173      173           
  Lines       65310    65273   -37     
=======================================
- Hits        55705    55677   -28     
+ Misses       9605     9596    -9     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ecoussoux-ansys ecoussoux-ansys marked this pull request as ready for review June 13, 2025 13:41
@ecoussoux-ansys ecoussoux-ansys requested a review from a team as a code owner June 13, 2025 13:41
Copy link
Copy Markdown
Collaborator

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @ecoussoux-ansys !!!
I left some comments. I'm wondering if some of the changes are due to ruff or if they are changes performed in the main branch and somehow reflected in this PR. Can you have a look and address them ?

Comment thread doc/source/conf.py
Comment thread src/ansys/aedt/core/application/design.py
Comment thread src/ansys/aedt/core/extensions/installer/jupyter_template.ipynb
Comment thread src/ansys/aedt/core/hfss3dlayout.py
Comment thread src/ansys/aedt/core/modeler/cad/primitives.py
Comment thread src/pyaedt/generic/near_field_import.py
Comment thread tests/integration/test_touchstone_data.py
Comment thread tests/system/general/test_08_Primitives3D.py
Comment thread src/ansys/aedt/core/hfss3dlayout.py
SMoraisAnsys
SMoraisAnsys previously approved these changes Jun 23, 2025
Comment thread src/ansys/aedt/core/extensions/hfss/move_it.py
@SMoraisAnsys SMoraisAnsys enabled auto-merge (squash) June 23, 2025 14:33
@SMoraisAnsys SMoraisAnsys merged commit ca7abec into main Jun 25, 2025
36 of 37 checks passed
@SMoraisAnsys SMoraisAnsys deleted the chore/enforce-ruff-pyflakes-F-rules branch June 25, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation maintenance Package and maintenance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants