Open tnahm opened 5 days ago
If you use --config
, then Ruff resolves configuration relative to the current working directory. If you don't use --config
, then Ruff resolves configuration relative to the "project root". I suspect that's the source of the difference it's intentional. (Ruff will then look in {project_root}/src
and {project_root}
for a module named data
.)
This is all documented here: https://docs.astral.sh/ruff/faq/#how-does-ruff-determine-which-of-my-imports-are-first-party-third-party-etc.
Hi Charlie, thanks for your comment! I looked at the documentation and indeed this looks intentional. That being said, it does feel more like a bug than a feature, and I (and several colleagues) found it quite unintuitive that specifying a particular config file via --config changes how ruff selects the project root as a side effect. Also the help string for --config
--config <CONFIG_OPTION> Either a path to a TOML configuration file (`pyproject.toml` or `ruff.toml`), or a TOML `<KEY> = <VALUE>`
pair (such as you might find in a `ruff.toml` configuration file) overriding a specific configuration
option. Overrides of individual settings using this option always take precedence over all configuration
files, including configuration files that were also specified using `--config`
doesn't mention anything that might lead a user to suspect this behavior.
Therefore I am leaving this open with the hope that the maintainers reconsider this unintuitive side effect, or at least make it clearer in the documentation and console output. Even a log message to the effect of which project root is used would have helped in this case.
I am calling ruff in two different ways, once explicitly specifiying the config file as /home/torsten/src/service-digital-agent/.ruff.toml, once having it autodiscovered via parent.
ruff check --config /home/torsten/src/service-digital-agent/.ruff.toml --verbose knowledge_retrieval/__init__.py
vs.
ruff check --verbose knowledge_retrieval/__init__.py
In both cases, exactly the same configuration file is used (see debug logs below).
In the first case, the import of the (local) data module is correctly identified as "FirstParty", in the second case it is incorrectly identified as "ThirdParty" (see debug logs below):
vs.
This leads to a different treatment of the import statement, with an error of "I001 [*] Import block is un-sorted or un-formatted" in the second case.
I am using ruff 0.7.1