Skip to content

feat: Setting up Ruff and updating the repo content accordingly #594

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 11 commits into
base: main
Choose a base branch
from

Conversation

ecoussoux-ansys
Copy link
Contributor

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

This PR implements the change discussed in #593, i.e. migrating the pyansys-dev-guide to Ruff.

The specific configs for Black, isort and flake8 are removed and the .pre-commit-config.yaml file is updated accordingly, while a ruff.toml file defining the rules used by Ruff for linting and formatting is introduced.
Python files fixed by Ruff are updated.

Since the project does not currently contain a pyproject.toml file, it was decided not to define one for the purpose of holding the Ruff configuration, but instead to specify it in a ruff.toml file placed at the root of the project. The introduction of a pyproject.toml file is considered to be beyond the scope of this PR, which is the motivation for this choice.
Should a pyproject.toml file be created in the future, the content of the ruff.toml can simply be added to it and this config file removed.

As indicated in #593, the use of blacken-docs in .pre-commit-config.yaml is maintained as this tool (used for formatting Python code blocks in documentation files) cannot currently be replaced by Ruff, which does not support formatting/linting of embedded code (particularly in .rst or .md files, see astral-sh/ruff#8237). Similarly, blacken-docs does not support the Ruff formatter as an alternative for Black (see adamchainz/blacken-docs#352).
This tool is therefore retained (see here about the Ruff pre-commit hook astral-sh/ruff-pre-commit#55) for this project, despite the remaining dependence on Black.

Close #593

@github-actions github-actions bot added maintenance Package and maintenance related enhancement New features or code improvements labels May 6, 2025
@ecoussoux-ansys ecoussoux-ansys self-assigned this May 6, 2025
@github-actions github-actions bot added the documentation Improvements or additions to documentation label May 6, 2025
@ecoussoux-ansys ecoussoux-ansys marked this pull request as ready for review May 7, 2025 14:37
Copy link
Contributor

@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 this PR @ecoussoux-ansys, I left some minor comments

self = add_stdout_handler(self, level=level)

def setLevel(self, level="DEBUG"):
def setlevel(self, level="DEBUG"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting this and for the explanation.
I reverted in 7c944dc the others changes I had made to that method's name where you did not directly provide a suggested fix.

file_handler = logging.FileHandler(filename)
file_handler.setLevel(level)
file_handler.setlevel(level)
Copy link
Contributor

Choose a reason for hiding this comment

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

echo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Changes applied in 7c944dc for this and subsequent occurrences.

Copy link
Contributor

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

Here is a new batch of suggestion :)

ruff.toml Outdated
Comment on lines 24 to 32
ignore = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D105", # Missing docstring in magic method
"D400", # First line should end with a period
"TD002", # Missing author in TODOs comment
"TD003", # Missing issue link in TODOs comment
]
Copy link
Contributor

Choose a reason for hiding this comment

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

@ecoussoux-ansys Can't those ignore be removed ? The repo doesn't contain too many content so it should be doable right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure it's doable : Most of the issues reported by Ruff for which I initially decided to introduce these ignore rules were related to missing docstrings.
I added minimalist docstrings where possible and added a few "# noqa" flags to disable ruff checks for cases where I did not know better. I tried not to simply silence all reported errors by using such "# noqa" everywhere, hence the newly introduced docstrings, of admittedly limited usefulness.
Does this approach and my changes look good for you?

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 enhancement New features or code improvements maintenance Package and maintenance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up Ruff and remove previous tools for formatting and linting
2 participants