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

add: ruff linter #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add: ruff linter #293

wants to merge 1 commit into from

Conversation

virajkanwade
Copy link
Contributor

poetry run ruff check --fix appmap

https://docs.astral.sh/ruff/

@apotterri apotterri self-requested a review March 17, 2024 08:59
@apotterri
Copy link
Contributor

We're already using pylint for linting: https://github.com/getappmap/appmap-python/blob/master/tox.ini#L24 . I'm not opposed to switching to ruff, but if we do, we should remove pylint. This should probably also include a config file for ruff that more or less matches the pylint config.

@apotterri
Copy link
Contributor

We're using semantic-release for appmap-python, so the subject lines for commits need to follow this format: https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format .

(Our own CONTRIBUTING.md really needs an update that mentions this....)

Copy link
Contributor

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

Thanks very much for this.

@@ -4,4 +4,3 @@

if not Env.current.is_appmap_repo and Env.current.enables("unittest"):
logger.debug("Test recording is enabled (unittest)")
import _appmap.unittest # pyright: ignore pylint: disable=unused-import
Copy link
Contributor

Choose a reason for hiding this comment

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

This import needs to be retained, so it should be marked with # noqa: F401 rather than deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

pyproject.toml Outdated
@@ -49,6 +49,7 @@ packaging = ">=19.0"
#
# So, if you'd like to run the tests outside of tox, run `pip install -r requirements-dev.txt` to
# install it and the rest of the dev dependencies.
ruff = "^0.3.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in the dev dependencies (below).

@virajkanwade
Copy link
Contributor Author

We're using semantic-release for appmap-python, so the subject lines for commits need to follow this format: https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format .

(Our own CONTRIBUTING.md really needs an update that mentions this....)

Updated the commit message. Hopefully chose the correct one.

@virajkanwade
Copy link
Contributor Author

We're already using pylint for linting: https://github.com/getappmap/appmap-python/blob/master/tox.ini#L24 . I'm not opposed to switching to ruff, but if we do, we should remove pylint. This should probably also include a config file for ruff that more or less matches the pylint config.

Most of projects are now moving from pylint to ruff.
https://docs.astral.sh/ruff/faq/#how-does-ruffs-linter-compare-to-pylint

Also, the fastapi unused wsgimiddleware import, ruff highlighted it, but I didn't notice it as such in the pylint output.

This was a suggestion for replacing pylint with ruff and not both together.

I am not aware of other places where you might have to replace pylint in the dev environments/ CI etc.

@apotterri
Copy link
Contributor

We're already using pylint for linting: https://github.com/getappmap/appmap-python/blob/master/tox.ini#L24 . I'm not opposed to switching to ruff, but if we do, we should remove pylint. This should probably also include a config file for ruff that more or less matches the pylint config.

Most of projects are now moving from pylint to ruff. https://docs.astral.sh/ruff/faq/#how-does-ruffs-linter-compare-to-pylint
Yup, seems like a good idea to me.

Also, the fastapi unused wsgimiddleware import, ruff highlighted it, but I didn't notice it as such in the pylint output.

This was a suggestion for replacing pylint with ruff and not both together.
Understood. I wasn't suggesting this either.

I am not aware of other places where you might have to replace pylint in the dev environments/ CI etc.
The main thing we're using pylint to try to keep the code from getting worse: https://github.com/getappmap/appmap-python/blob/master/tox.ini#L24 .

We need to retain this functionality if we switch to ruff, so this PR would need to include changes to do that, as well.

@virajkanwade
Copy link
Contributor Author

@apotterri Just to confirm, this is executed when running tox? Also, what is the expected outcome here? Tests should fail if there is any pylint error? As pylint-exit only returns 1 on Fatal message issued or Usage error

@apotterri
Copy link
Contributor

Yes, it's run when the tox environment is py310-web: https://app.travis-ci.com/github/getappmap/appmap-python/jobs/619305807#L579 .

pylint computes a score for the code, and has a setting that controls the minimum score: https://github.com/getappmap/appmap-python/blob/master/pylintrc#L3 . If the code that's getting built has a score that's below that threshold, pylint-exit returns non-zero.

@virajkanwade
Copy link
Contributor Author

Yes, it's run when the tox environment is py310-web: https://app.travis-ci.com/github/getappmap/appmap-python/jobs/619305807#L579 .

pylint computes a score for the code, and has a setting that controls the minimum score: https://github.com/getappmap/appmap-python/blob/master/pylintrc#L3 . If the code that's getting built has a score that's below that threshold, pylint-exit returns non-zero.

Doesn't seem to be working that way.

# Specify a score threshold under which the program will exit with error.
fail-under=9.83
------------------------------------------------------------------
Your code has been rated at 9.80/10 (previous run: 9.80/10, +0.00)

The following messages were raised:

  - error message issued
  - warning message issued
  - refactor message issued
  - convention message issued

No fatal messages detected.  Exiting gracefully...

@apotterri
Copy link
Contributor

That would be bug, then. It's intended to work that way, and I thought that was the description from pylint-exit.

@apotterri
Copy link
Contributor

That would be bug, then. It's intended to work that way, and I thought that was the description from pylint-exit.

Looking again at the doc for pylint-exit, I see that I misread it. It doesn't clean to exit non-zero if the fail_under check fails. So, there's definitely a bug in the build that needs to be fixed.

@apotterri
Copy link
Contributor

As far as replacing pylint with ruff....

I'm concerned about the statement here that ruff isn't a drop-in replacement for pylint: https://docs.astral.sh/ruff/faq/#how-does-ruffs-linter-compare-to-pylint , and especially that it does less type checking.

Also astral-sh/ruff#970 .

@virajkanwade
Copy link
Contributor Author

Yes, ruff is used along with mypy. But at this time, adding type annotation for every variable might be a big task. We can leave adding ruff in backlog as a future task, but address the highlighted issues in a separate PR.

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.

2 participants