ruff icon indicating copy to clipboard operation
ruff copied to clipboard

An equivalent to `force_sort_within_sections` from isort

Open tmke8 opened this issue 3 years ago • 1 comments

I personally prefer to sort imports like this (which used to be the standard sorting for the Python extension on VS Code):

import numpy as np
import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
import tqdm

from .my_module import my_func

as opposed to this sorting, which is how isort (and ruff) sorts by default:

import numpy as np
import torch
import torch.nn.functional as F
import tqdm
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor

from .my_module import my_func

(Notice how tqdm is sandwiched there in the torch imports.)

With isort, I can achieve the desired sorting with the force_sort_within_sections option. Would you be interested in supporting this as well?

tmke8 avatar Dec 02 '22 22:12 tmke8

Yeah we can probably support this (and I don't mind doing so), though it requires a bit of refactoring to the import model.

charliermarsh avatar Dec 04 '22 04:12 charliermarsh

Added in #1635.

charliermarsh avatar Jan 09 '23 06:01 charliermarsh