Skip to content

ruff should respect pyproject.toml existence for first-party scraping #23590

@thejcannon

Description

@thejcannon

Summary

Given:

.
├── projects
│   └── brown-lentil
│       ├── brown_lentil
│       │   └── subdir
│       │       └── soup.py
│       └── pyproject.toml
└── ruff.toml

where pyproject.toml is empty and ruff.toml just has [lint]\nselect = ["I"]

and where soup.py imports typing, pytest, and brown_lentil, ruff check --fix projects/brown-lentil/brown_lentil/subdir/soup.py will result in:

import typing  # TODO: Does EVERY module need to import this??

import brown_lentil
import pytest  # Always good to test your soup first

I think what's happening here is that:

  • Ruff is using the directory containing the ruff.toml as the "project root"
    • If I put a ruff.toml next to my pyproject.toml there, then it formats correctly
  • The missing __init__.py in brown_lentil is bypassing Ruff's "same-package" check
    • IDK if this is a bug or a feature, but maybe should be documented. I'll make a separate PR

Ideally, the existence of a pyproject.toml (even one not containing [tool.ruff]) would mark this as a project root (it is called a "py project" file after all 😉)

Version

ruff 0.15.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    isortRelated to import sorting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions