Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: adjust isort to be more compatible with ruff #1139

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

Currently, running tox -e fmt leaves the code in a state that tox -e lint complains about, for two reasons:

  • Wrapping a line in ops/charm - I'm not sure why this difference exists since autopep8 and ruff have the same max line length (or why it wasn't picked up before we used ruff), but ruff is ok with the wrapped version, so it seems like the simple fix here is to just have it wrapped.
  • "from x import a,b,c" style imports and wrapping.

For the import issue, if we adjust isort to use the "vertical hanging indent" mode (weirdly called "3") that gets most of the way there, but even though the docs show a trailing comma, one isn't included. However, if we use the --split-on-trailing-comma mode as well that does lead to a compatible format. We're not using the "force wrapping via trailing comma" trick anywhere, but it seems harmless enough to have it enabled.

I've put the options in tox.ini rather than pyproject.toml because we're intending to move to ruff for formatting soon (#1103) and this ensures that these options go away, rather than getting missed in pyproject.toml. I can change that if we'd rather keep all the options in one place.

Also bumped the isort version, which isn't required but I did while investigating, and since I've tested it and it's ok, seems reasonable. Also passed the line length to isort, which isn't needed at the moment but is more consistent.

@tonyandrewmeyer
Copy link
Contributor Author

This will fix the linting issues in #1138.

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Changes seem reasonable, especially in light of a future move to Ruff formatting.

@benhoyt benhoyt merged commit 9c0f44b into canonical:main Feb 28, 2024
28 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the fix-isort-ruff-format-clash branch March 3, 2024 22:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants