Skip to content
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

ci: implement ruff #554

Merged
merged 7 commits into from
Jan 22, 2024
Merged

ci: implement ruff #554

merged 7 commits into from
Jan 22, 2024

Conversation

DaniBodor
Copy link
Collaborator

@DaniBodor DaniBodor commented Jan 15, 2024

Implement ruff linter and formatter in deeprank in lieu of prospector.

best reviewed one commit at a time:

  1. set up ruff
    • replace prospector by ruff in CI
    • add ruff settings to pyproject.toml and remove .prospector.yml
    • format pyproj.toml
  2. update docs regarding new linting/formatting
  3. update settings.json for vs code
    • automatically flag linting issues and apply formatting upon save of python files
    • some additional settings
  4. implement new linting and formatting throughout
    • this is a huge commit, basically touching the entire code base; probably not worthwhile reviewing in detail. In short
      • auto-format the entire code base (using ruff format .)
      • manually or automatically fix all linting issues flagged by ruff . (or suppressed)
      • remove pylint suppression calls
      • additional manual formatting to error messages to avoid them printing lots of whitespace/tabs when raised
  5. remove all commented out code (linting issue ERA001), this part should be reviewed.
    • this was done in a separate commit to check that all deleted code is indeed legacy as opposed to accidentally being commented out
    • some commented out code may contain information that should be stored in a more appropriate manner
  6. suppress some warnings during testing
    • I would like to get to the bottom of the warnings thrown during test_trainer, but that took too much time and will be for another issue.
  7. format non-python files

closes #541

@DaniBodor DaniBodor changed the base branch from main to dev January 15, 2024 16:07
@DaniBodor DaniBodor force-pushed the 541_ruff_dbodor branch 2 times, most recently from 882115a to 8ca2ed4 Compare January 15, 2024 16:27
@DaniBodor DaniBodor force-pushed the 541_ruff_dbodor branch 8 times, most recently from 793373e to 2422406 Compare January 16, 2024 14:31
@DaniBodor DaniBodor requested a review from gcroci2 January 16, 2024 14:46
@DaniBodor DaniBodor mentioned this pull request Jan 16, 2024
@DaniBodor DaniBodor changed the title 541 ruff dbodor ci: implement ruff Jan 16, 2024
Copy link
Collaborator

@gcroci2 gcroci2 left a comment

Choose a reason for hiding this comment

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

Nice work :D I left very minor comments and seems all great. Three other things:

  • You used Prettier on non-python files, what about adding it as the default formatter for non-python files in the vscode settings? It would be even better to have ruff as the default for non-python files as well, but I think that ruff is for python files only, right?
  • I had a lower version of ruff (0.1.4 instead of the latest, 0.1.13) and it was giving me 4 errors when running ruff . from local. No errors with the updated ruff version. I'd add the version on the dependencies list in the toml file (ruff >= 0.1.13)
  • When I run ruff format ., I get the following warning:
The following rules may cause conflicts when used with the formatter: 'ISC001'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the 'select' or 'extend-select' configuration, or adding them to the 'ignore' configuration.
86 files left unchanged

Maybe is a good idea to disable ISC001 adding it to the ignore configuration in the toml file?

README.dev.md Outdated

We use [prospector](https://pypi.org/project/prospector/) with pyroma for linting. For running it locally, use `prospector` or `prospector <filepath_or_folderpath>` for specific files/folders.
We use [ruff](https://docs.astral.sh/ruff/) for linting, sorting imports and formatting code. The configurations of `ruff` are set in [pyproject.toml](pyproject.toml) file. If you are using VS code, you can activate the [Ruff extension](charliermarsh.ruff) to automatically format the code and flag linting issues upon saving. Otherwise, please check both linting (`ruff .`) and formatting (`ruff format .`, this automatically formats the entire code base) before requesting a review.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add the correct link for project.toml file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The link works like this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that ruff added it. Do we know why? Is also added init files in each tests subfolder

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

from INP001:

Python packages are directories that contain a file named init.py. The existence of this file indicates that the directory is a Python package, and so it can be imported the same way a module can be imported.

Directories that lack an init.py file can still be imported, but they're indicative of a special kind of package, known as a "namespace package" (see: PEP 420). Namespace packages are less widely used, so a package that lacks an init.py file is typically meant to be a regular package, and the absence of the init.py file is probably an oversight.

@DaniBodor DaniBodor force-pushed the 541_ruff_dbodor branch 3 times, most recently from d84e2af to 7dc2526 Compare January 22, 2024 13:33
@DaniBodor
Copy link
Collaborator Author

Nice work :D I left very minor comments and seems all great. Three other things:

  • You used Prettier on non-python files, what about adding it as the default formatter for non-python files in the vscode settings? It would be even better to have ruff as the default for non-python files as well, but I think that ruff is for python files only, right?

Done in 7dc2526 (edited style: format non-python files)

  • I had a lower version of ruff (0.1.4 instead of the latest, 0.1.13) and it was giving me 4 errors when running ruff . from local. No errors with the updated ruff version. I'd add the version on the dependencies list in the toml file (ruff >= 0.1.13)

Done in b5767f6 (edited ci: set up ruff linter)

  • When I run ruff format ., I get the following warning:
The following rules may cause conflicts when used with the formatter: 'ISC001'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the 'select' or 'extend-select' configuration, or adding them to the 'ignore' configuration.
86 files left unchanged

Maybe is a good idea to disable ISC001 adding it to the ignore configuration in the toml file?

This is because the format may put strings that are on sequential lines onto the same line but keeps them as two separate strings and this creates the linting issue you reference. I think we do want the formatter to do this and for the linter to pick it up.
I now added that linting issue to the "safe to fix" list (in b5767f6), so that it automatically get fixed upon saving as well. Stupidly however, you need to save twice (first save will move the two strings onto one line, the second save will merge into a single string) for the full issue to resolve. Also, the warning persists and I haven't found a way to suppress it.

@DaniBodor DaniBodor merged commit fb46161 into dev Jan 22, 2024
6 of 8 checks passed
@DaniBodor DaniBodor deleted the 541_ruff_dbodor branch January 22, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change linter to ruff
2 participants