astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
28.59k stars 926 forks source link

moving imports to the top of the file with ruff #12084

Closed RishiMalhotra920 closed 3 days ago

RishiMalhotra920 commented 3 days ago

I'm switching over from isort to ruff and one feature I dearly miss is auto-moving imports to the top of the file. I'm using ruff v0.5.0.

Say I have this file a.py

import numpy
import pandas

print("hello world")
import os

print(os, pandas, numpy)

Running the following commands doesn't move the import os to the top.

ruff check --select I --fix a.py
ruff format

I know that with isort, running isort . moves the import os to the top.

Is there a way to enable this for standalone ruff? Also, is there a reason this isn't enabled by default?

MichaReiser commented 3 days ago

To my knowledge, Ruff has no support for the new float-to-top option yet. Did youse the new setting in your project with isort?

charliermarsh commented 3 days ago

I think this can be merged with #1251.