Skip to content

Conversation

ecoussoux-ansys
Copy link
Contributor

@ecoussoux-ansys ecoussoux-ansys commented May 20, 2025

This PR corresponds to the first step towards using ruff for linting and formatting in the pyedb project, as described in #1237.
As such, completion of this PR should not result in closing #1237.
The present changes aim at providing pyedb with a similar basic ruff configuration as the one implemented for pyaedt in ansys/pyaedt#6157, removing isort, black and flake8 at the same time.

It should be noted that ruff does not replace the following tools, whose use in the project is therefore not affected by the changes introduced here:

  • blacken-docs (used for formatting Python code blocks in documentation files): ruff does not support formatting/linting of embedded code (particularly in .rst or .md files). Similarly, blacken-docs does not support the ruff formatter as an alternative for black. This tool is therefore retained (as a pre-commit hook), despite the remaining dependency on black,
  • codespell (fixes common misspellings in source code and other files), which is not integrated into ruff,
  • numpydoc (used for formatting docstrings), which is also not integrated into ruff.

The changes in this PR are limited to the definition of a minimal configuration for ruff (in the pyproject.toml file) with only a small set of rules (namely "I"(sort) rules) applied to the code base, together with the introduction of pre-commit hooks for linting and formatting with ruff. Python files fixed by ruff are updated. Configurations for isort, black and flake8 are removed and the associated pre-commit hooks are also dropped.
The currently ignored rules (exhaustive list provided) shall be gradually applied to the project in subsequent PRs.

It is also worth mentioning that the list of rules selected until now for linting in the .flake8 file is not regarded as a reference for defining the implemented ruff configuration. Instead, this config is based on the recommendations from the pyansys-dev-guide, as introduced in ansys/pyansys-dev-guide#592.

@ecoussoux-ansys ecoussoux-ansys self-assigned this May 20, 2025
@github-actions github-actions bot added maintenance Package and maintenance related dependencies Related with project dependencies grpc-transition Changes that need to be included in gRPC transition labels May 20, 2025
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2025

Codecov Report

❌ Patch coverage is 15.00000% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.56%. Comparing base (c43278e) to head (fe98f27).

❌ Your patch status has failed because the patch coverage (15.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    #1233      +/-   ##
==========================================
+ Coverage   49.50%   49.56%   +0.05%     
==========================================
  Files         254      254              
  Lines       37900    37857      -43     
==========================================
- Hits        18764    18763       -1     
+ Misses      19136    19094      -42     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added the testing Anything related to testing label May 20, 2025
@ecoussoux-ansys ecoussoux-ansys removed dependencies Related with project dependencies testing Anything related to testing grpc-transition Changes that need to be included in gRPC transition labels May 20, 2025
@ecoussoux-ansys ecoussoux-ansys marked this pull request as ready for review May 20, 2025 16:14
# Conflicts:
#	.pre-commit-config.yaml
#	src/pyedb/configuration/cfg_components.py
#	src/pyedb/configuration/cfg_padstacks.py
#	src/pyedb/configuration/cfg_ports_sources.py
#	src/pyedb/dotnet/database/cell/layout.py
#	src/pyedb/dotnet/database/dotnet/database.py
#	src/pyedb/dotnet/database/padstack.py
#	src/pyedb/dotnet/edb.py
#	src/pyedb/generic/design_types.py
#	src/pyedb/grpc/database/components.py
#	src/pyedb/grpc/database/hfss.py
#	src/pyedb/grpc/database/layers/stackup_layer.py
#	src/pyedb/grpc/database/layout/layout.py
#	src/pyedb/grpc/database/layout_validation.py
#	src/pyedb/grpc/database/modeler.py
#	src/pyedb/grpc/database/net/net.py
#	src/pyedb/grpc/database/nets.py
#	src/pyedb/grpc/database/padstacks.py
#	src/pyedb/grpc/database/primitive/bondwire.py
#	src/pyedb/grpc/database/primitive/path.py
#	src/pyedb/grpc/database/primitive/rectangle.py
#	src/pyedb/grpc/database/source_excitations.py
#	src/pyedb/grpc/database/stackup.py
#	src/pyedb/grpc/database/terminal/bundle_terminal.py
#	src/pyedb/grpc/database/terminal/terminal.py
#	src/pyedb/grpc/database/utility/simulation_configuration.py
#	src/pyedb/grpc/edb.py
#	tests/grpc/system/conftest.py
#	tests/grpc/system/test_edb_future_features_242.py
#	tests/grpc/system/test_edb_materials.py
#	tests/grpc/system/test_edb_padstacks.py
#	tests/grpc/system/test_edb_stackup.py
#	tests/grpc/unit/conftest.py
#	tests/legacy/system/conftest.py
#	tests/legacy/system/test_edb_components.py
#	tests/legacy/system/test_edb_definition.py
#	tests/legacy/system/test_edb_extended_nets.py
#	tests/legacy/system/test_edb_ipc.py
#	tests/legacy/system/test_edb_modeler.py
#	tests/legacy/system/test_edb_nets.py
#	tests/legacy/system/test_edb_stackup.py
#	tests/legacy/system/test_emi_scanner.py
#	tests/legacy/system/test_siwave_features.py
#	tests/system/base_test_class.py
#	tests/system/test_edb_geometry.py
#	tests/system/test_edb_padstacks.py
@github-actions github-actions bot added dependencies Related with project dependencies testing Anything related to testing grpc-transition Changes that need to be included in gRPC transition labels Aug 26, 2025
svandenb-dev
svandenb-dev previously approved these changes Aug 26, 2025
Copy link
Collaborator

@svandenb-dev svandenb-dev left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 26, 2025
@ecoussoux-ansys
Copy link
Contributor Author

@svandenb-dev,
In my last commit I ran ruff linting and formatting against all the files again, which lead to some changes to enforce the I001 unsorted-imports rule that is part of the minimal config introduced for the tool.
I also added two entries to the list of the ignored rules for ruff in the pyproject.toml file (E712 true-false-comparison and N816 mixed-case-variable-in-global-scope).
On top of that, I updated the .pre-commit-config.yaml file to use the latest releases available for the ruff and blacken-docs hooks, also removing again the isort and flake8 hooks which were probably reintroduced when merging the main branch inside this one.
Hopefully these updates make the PR truly up-to-date and ready for review!

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

I think there should be some rewrite here to avoid the following changes from

nets.generate_extended_nets(
    resistor_below=5,
    ...
)

to

nets.generate_extended_nets(
    resistor_below = (5,)
    ...
)
>>> nets.generate_extended_nets(
>>> resistor_below=5,
>>> resistor_below = (5,)
>>>inductor_below=0.5,
>>> capacitor_above=0.1
>>> capacitor_above = 0.1
>>> )

It is even more strange with >>> power_nets=["VDD_CPU", "VDD_MEM"], to >>> power_nets = (["VDD_CPU", "VDD_MEM"],).

@ecoussoux-ansys Could you have a look ? I think it complexifies the documentation

@ecoussoux-ansys
Copy link
Contributor Author

I think there should be some rewrite here to avoid the following changes from

nets.generate_extended_nets(
    resistor_below=5,
    ...
)

to

nets.generate_extended_nets(
    resistor_below = (5,)
    ...
)
>>> nets.generate_extended_nets(
>>> resistor_below=5,
>>> resistor_below = (5,)
>>>inductor_below=0.5,
>>> capacitor_above=0.1
>>> capacitor_above = 0.1
>>> )

It is even more strange with >>> power_nets=["VDD_CPU", "VDD_MEM"], to >>> power_nets = (["VDD_CPU", "VDD_MEM"],).

@ecoussoux-ansys Could you have a look ? I think it complexifies the documentation

Thank you for pointing this out. Indeed, this type of reformatting, which occurred in several places, is incorrect.

This happens because ruff is confused by the fact that in some doc strings, code examples that were spread over several lines did not have the >>> properly replaced by ... where needed.
When the correct syntax was in place, the reformatting of code examples in doc strings was performed as expected, as can be seen, for example, in the changes introduced in src/pyedb/dotnet/database/components.py! However, when a line begins with >>> when it should begin with ..., ruff considers it to be an independent statement and does not interpret the comma at the end of the line as a separator between consecutive function arguments, but as the syntax for defining a tuple, which ruff makes explicit by introducing parentheses.

All occurrences of this kind of reformatting should be corrected by the changes introduced by c881dac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Related with project dependencies documentation Improvements or additions to documentation grpc-transition Changes that need to be included in gRPC transition maintenance Package and maintenance related testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants