-
-
Notifications
You must be signed in to change notification settings - Fork 459
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: Replace isort with Ruff import sorting #1507
Conversation
This is the first step in Ruff adoption. Ruff is faster and will allow us to perform more fixes and checks in the future (e.g. replacing flake8, auto-removing unused imports). There are some changes around places that use renamed imports (`import X import Y as Z`) but I think it's not any worse.
name: isort (pyi) | ||
types: [pyi] | ||
- id: ruff | ||
args: ["--fix", "--fixable=I001", "--exit-non-zero-on-fix"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--exit-non-zero-on-fix
is suggested at https://github.com/charliermarsh/ruff-pre-commit
] | ||
|
||
[tool.ruff.isort] | ||
split-on-trailing-comma = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option makes Ruff collapse multiline imports back to a single line if they're short enough to fit. E.g.
from typing import (
Any,
)
to
from typing import Any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: astral-sh/ruff#4153
Please, don't merge it just yet. I want to have a proper look in ~4 days. |
@sobolevn Ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I forgot about it.
What exactly are we winning here?
We can change one setting in isort
to have the same result.
Like I said in the first comment:
This is only the first step, the "win" in this PR is small still. Basically, Ruff is faster than isort and already has a plugin for PyCharm/IntellIJ IDEA (which I use for developing django-stubs). But Ruff's feature set covers so much and its speed is so good that, having used it in my personal projects, it seems like a no-brainer to adopt it. I used to hate pre-commit hooks with a passion because they make committing excruciatingly slow. But using Ruff is hardly noticeable. One particular example, we had the problem with PRs #1508 and #1509 have a taste of what's to come, but it can do more things. Exhaustive list of checks/fixes here: https://beta.ruff.rs/docs/rules/ but I would enable them in small steps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's try it!
Maybe |
Looks like it doesn't. But django-stubs isn't using using isort's |
I am going to contribute |
This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [django-stubs](https://github.com/typeddjango/django-stubs) ([changelog](https://github.com/typeddjango/django-stubs/releases)) | dev | patch | `4.2.1` -> `4.2.2` | `4.2.3` | --- ### Release Notes <details> <summary>typeddjango/django-stubs (django-stubs)</summary> ### [`v4.2.2`](https://github.com/typeddjango/django-stubs/releases/tag/4.2.2) [Compare Source](https://github.com/typeddjango/django-stubs/compare/4.2.1...4.2.2) #### Headline changes - **mypy 1.4:** Recommended mypy version updated to 1.4.x - Support for `django-split-settings`, `django-configurations` and other Django settings addons with `strict_settings = false` option, [see README for details](https://github.com/typeddjango/django-stubs#how-to-use-a-custom-library-to-handle-django-settings) - We have now adopted [mypy's stubtest](https://mypy.readthedocs.io/en/stable/stubtest.html) to automatically find discrepancies between Django and django-stubs. If you want to contribute to django-stubs but are not sure where to start, have a look at [stubtest's TODO list](https://github.com/typeddjango/django-stubs/blob/master/scripts/stubtest/allowlist_todo.txt) file, which lists the many issues discovered by stubtest. ##### Django 4.2 changes - Applied Django 4.2 deprecations by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1523](https://github.com/typeddjango/django-stubs/pull/1523) - Updated global settings and `AppConfig` class to match Django 4.2 by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1524](https://github.com/typeddjango/django-stubs/pull/1524) - Added types for new 'system checks' in Django 4.2 by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1526](https://github.com/typeddjango/django-stubs/pull/1526) - Added `ManifestStaticFilesStorage` new parameters by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1528](https://github.com/typeddjango/django-stubs/pull/1528) - Added new methods to `Sitemap` class by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1527](https://github.com/typeddjango/django-stubs/pull/1527) - Added new `headers=` parameter to `(Async)RequestFactory` and `(Async)Client` classes by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1529](https://github.com/typeddjango/django-stubs/pull/1529) - Additional fixes by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1537](https://github.com/typeddjango/django-stubs/pull/1537) - GDAL-related GeoDjango updates in Django 4.2 by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1525](https://github.com/typeddjango/django-stubs/pull/1525) - Added ORM `^` and `~` operator support, JSON lookup classes, Postgres lookup classes, `ModelForm` changes, `json_script` template filter parameters by [@​Alexerson](https://github.com/Alexerson) in [https://github.com/typeddjango/django-stubs/pull/1536](https://github.com/typeddjango/django-stubs/pull/1536) - Added and updated `db.backends` `DatabaseIntrospection` and `DatabaseOperations` classes by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1571](https://github.com/typeddjango/django-stubs/pull/1571) ##### Stubs additions - Added `QuerySet._result_cache` attribute and `_fetch_all()` method by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1505](https://github.com/typeddjango/django-stubs/pull/1505) - Added `ModelAdmin.search_help_text` attribute by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1546](https://github.com/typeddjango/django-stubs/pull/1546) - Added email console handler `EmailBackend.write_message()` method by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1547](https://github.com/typeddjango/django-stubs/pull/1547) - Added `ModelAdmin.get_formset_kwargs()` method by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1545](https://github.com/typeddjango/django-stubs/pull/1545) - Added `Signal._live_receivers()` method by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1551](https://github.com/typeddjango/django-stubs/pull/1551) - Added `SQLCompiler._order_by_pairs()` method by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1586](https://github.com/typeddjango/django-stubs/pull/1586) - Added `memcache_key_warnings()` function by [@​rvanlaar](https://github.com/rvanlaar) in [https://github.com/typeddjango/django-stubs/pull/1562](https://github.com/typeddjango/django-stubs/pull/1562) ##### Stubs fixes - Fixed `create_model_instance` incorrect data argument type by [@​namper](https://github.com/namper) in [https://github.com/typeddjango/django-stubs/pull/1521](https://github.com/typeddjango/django-stubs/pull/1521) - Marked `RequestSite.{save,delete}` methods as `NoReturn` since they always raise by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1530](https://github.com/typeddjango/django-stubs/pull/1530) - Updated `SafeExceptionReporterFilter` attributes and removed obsolete `CLEANSED_SUBSTITUTE` by [@​mthuurne](https://github.com/mthuurne) in [https://github.com/typeddjango/django-stubs/pull/1540](https://github.com/typeddjango/django-stubs/pull/1540) - Changed `AppConfig.default_auto_field` to attribute instead of method by [@​mthuurne](https://github.com/mthuurne) in [https://github.com/typeddjango/django-stubs/pull/1541](https://github.com/typeddjango/django-stubs/pull/1541) - Fixed `default_error_messages` attribute type of base `Field` and `GenericIPAddressField` classes by [@​asottile](https://github.com/asottile) in [https://github.com/typeddjango/django-stubs/pull/1538](https://github.com/typeddjango/django-stubs/pull/1538) - Improved spatialite `DatabaseWrapper` attributes by [@​filbasi](https://github.com/filbasi) in [https://github.com/typeddjango/django-stubs/pull/1544](https://github.com/typeddjango/django-stubs/pull/1544) - Improved types for Signal `dispatch.dispatcher` by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1567](https://github.com/typeddjango/django-stubs/pull/1567) - Accept `str` field names for `Window.order_by()`, allow `None` for `asc/desc` arguments by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1574](https://github.com/typeddjango/django-stubs/pull/1574) - Updated many `django.utils.*` types from stubtest by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1575](https://github.com/typeddjango/django-stubs/pull/1575) - Updated many `db.migrations.operations` types from stubtest by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1583](https://github.com/typeddjango/django-stubs/pull/1583) - Added `StepValueValidator`, fixed argument for `SRIDCacheEntry`/`EmailValidator`, improved `urls.resolvers` types by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1589](https://github.com/typeddjango/django-stubs/pull/1589) ##### Plugin changes - Fixed `ForeignKey` queryset filters on un-swapped models by [@​UnknownPlatypus](https://github.com/UnknownPlatypus) in [https://github.com/typeddjango/django-stubs/pull/1495](https://github.com/typeddjango/django-stubs/pull/1495) - Add `strict_settings` option, allow runtime fallbacks for custom settings by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1557](https://github.com/typeddjango/django-stubs/pull/1557) - Add "Settings" section to README by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1581](https://github.com/typeddjango/django-stubs/pull/1581) - Automatically reset mypy cache when plugin settings change by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1578](https://github.com/typeddjango/django-stubs/pull/1578) - Fixed unhandled exception `KeyError: 'model_bases'` and related errors by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1563](https://github.com/typeddjango/django-stubs/pull/1563) ##### django-stubs-ext - Added `TypedDatabaseRouter` as database router base class by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1522](https://github.com/typeddjango/django-stubs/pull/1522) ##### CI/testing - CI: Replace isort with Ruff import sorting by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1507](https://github.com/typeddjango/django-stubs/pull/1507) - CI: Auto-remove unused imports using Ruff by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1508](https://github.com/typeddjango/django-stubs/pull/1508) - CI: Enable Ruff pyupgrade fixes by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1509](https://github.com/typeddjango/django-stubs/pull/1509) - CI: Run django-stubs-ext tests in full build matrix by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1552](https://github.com/typeddjango/django-stubs/pull/1552) - Remove typecheck test and clean things up by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1556](https://github.com/typeddjango/django-stubs/pull/1556) - Add stubtest with lots of errors (currently) by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1560](https://github.com/typeddjango/django-stubs/pull/1560) - Removed extra `--generate-allowlist` by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1576](https://github.com/typeddjango/django-stubs/pull/1576) ##### Housekeeping - Removed unsupported Django versions from package classifiers by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1553](https://github.com/typeddjango/django-stubs/pull/1553) - Removed try-except around import of `ArrayField` by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1558](https://github.com/typeddjango/django-stubs/pull/1558) - Reverted: Fix crash when psycopg2 is not installed by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1565](https://github.com/typeddjango/django-stubs/pull/1565) - Removed usage of `mypy_extensions` by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1566](https://github.com/typeddjango/django-stubs/pull/1566) - Upgrade to Mypy 1.4.0 by [@​christianbundy](https://github.com/christianbundy) in [https://github.com/typeddjango/django-stubs/pull/1572](https://github.com/typeddjango/django-stubs/pull/1572) - Chore: set Black Python target to 3.8+ explicitely by [@​GabDug](https://github.com/GabDug) in [https://github.com/typeddjango/django-stubs/pull/1573](https://github.com/typeddjango/django-stubs/pull/1573) - Update `flake8` plugins by [@​sobolevn](https://github.com/sobolevn) in [https://github.com/typeddjango/django-stubs/pull/1579](https://github.com/typeddjango/django-stubs/pull/1579) - CI: Run tests and pre-commit using newest Python version by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1582](https://github.com/typeddjango/django-stubs/pull/1582) - Removed duplicate "import all" test file by [@​adamchainz](https://github.com/adamchainz) in [https://github.com/typeddjango/django-stubs/pull/1587](https://github.com/typeddjango/django-stubs/pull/1587) - Update compatible-mypy to 1.4.x by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1588](https://github.com/typeddjango/django-stubs/pull/1588) - Version 4.2.2 release (django-stubs, django-stubs-ext) by [@​intgr](https://github.com/intgr) in [https://github.com/typeddjango/django-stubs/pull/1590](https://github.com/typeddjango/django-stubs/pull/1590) #### New Contributors - [@​namper](https://github.com/namper) made their first contribution in [https://github.com/typeddjango/django-stubs/pull/1521](https://github.com/typeddjango/django-stubs/pull/1521) - [@​filbasi](https://github.com/filbasi) made their first contribution in [https://github.com/typeddjango/django-stubs/pull/1544](https://github.com/typeddjango/django-stubs/pull/1544) - [@​GabDug](https://github.com/GabDug) made their first contribution in [https://github.com/typeddjango/django-stubs/pull/1567](https://github.com/typeddjango/django-stubs/pull/1567) - [@​rvanlaar](https://github.com/rvanlaar) made their first contribution in [https://github.com/typeddjango/django-stubs/pull/1562](https://github.com/typeddjango/django-stubs/pull/1562) **Full Changelog**: typeddjango/django-stubs@4.2.1...4.2.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xLjExIiwidXBkYXRlZEluVmVyIjoiMzYuMS4xMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
This is the first step in adopting Ruff: https://beta.ruff.rs/
Ruff is faster and will allow us to perform more fixes and checks in the future (e.g. replacing flake8, pyupgrade, auto-removing unused imports, etc).
There are some import formatting changes around places that use renamed imports (
import X import Y as Z
) but I think it's not any worse.Related issues
Ruff was suggested in typeddjango/djangorestframework-stubs#399 (comment), I checked it out and it's absolutely amazing! Thanks @orsinium.