
install ruff
#| eval: false
pip install ruff
check code
before correct python file
import pandas
from importlib.metadata import version
print('test.py is running')
print('version is :')
print(version('rich'))
a=3+1
a
playing.py:6:8: F401 [*] `pandas` imported but unused
|
6 | import pandas
| ^^^^^^ F401
7 |
8 | from importlib.metadata import version
|
= help: Remove unused import: `pandas`
Found 1 error.
[*] 1 fixable with the `--fix` option.
fix code
Code
!ruff check playing.py --fix
after fix
Code
import pandas
from importlib.metadata import version
print('test.py is running')
print('version is :')
print(version('rich'))
a=3+1
a
add ruff as extension in positron

using ruff on .qmd file
ruff only work on .py file, So if want to use ruff to check .qmd file then it need to convert to .py first.
convert .qmd to .py
Code
quarto convert index.qmd # → index.ipynb
Code
!jupyter nbconvert --to python index.ipynb # → index.py
reference:
https://github.com/astral-sh/ruff