fierce-greece-10087
03/05/2025, 1:33 PMpants fmt to only do the checking? I'm using ruff and tried passing the --check flag with pants fmt :: -- --check, but without success. I see there is a --lint-skip-fixers , but I don't find an equivalent for fmt. Is there a way for me to achieve this? I'd like a CI job to fail with exit code 1 if the code is not formatted.wide-midnight-78598
03/05/2025, 1:33 PMpants lint runs the fmt checker, doesn't it?wide-midnight-78598
03/05/2025, 1:33 PMpants lint --only=ruff-format or something?wide-midnight-78598
03/05/2025, 1:35 PMpantsanity % pants lint --only=ruff-format :: β main*
08:34:31.12 [INFO] Initializing scheduler...
08:34:42.74 [INFO] Scheduler initialized.
08:34:42.92 [INFO] Completed: Format with `ruff format` - ruff format made no changes.
β ruff format succeeded.fierce-greece-10087
03/05/2025, 1:37 PMfierce-greece-10087
03/05/2025, 1:49 PMpants lint checks what I want with ruff, but pants fmt only fixes code style things, while it skipps the import ordering. When I run pants lint, it reports them and says they're fixable with the --fix flag, while format doesn't do anything about them. I tried passing --fix to both lint and fmt.wide-midnight-78598
03/05/2025, 1:51 PMpants fixwide-midnight-78598
03/05/2025, 1:52 PMwide-midnight-78598
03/05/2025, 1:53 PMpants fix fmt lint check test is my typical non-packaging workflowfierce-greece-10087
03/05/2025, 1:54 PMfierce-greece-10087
03/05/2025, 2:23 PMpants fix and pants fmt say everything is fine, but pants lint says I have some import statements unsorted. I'm not sure where this difference could come from, as it's ruff in all cases.wide-midnight-78598
03/05/2025, 2:24 PMfierce-greece-10087
03/05/2025, 2:26 PMfix and fmt pass, saying everything is fine, lint fails with the same error as beforewide-midnight-78598
03/05/2025, 2:27 PMfierce-greece-10087
03/05/2025, 2:32 PMbackend_packages = [
"pants.backend.python",
"pants.backend.python.typecheck.mypy",
"pants.backend.experimental.python",
"pants.backend.experimental.python.lint.ruff.check",
"pants.backend.experimental.python.lint.ruff.format",
"pants.backend.docker",
]
I presume nothing else could run other than what's in the backends. I would suspect isort for example, but it's not there.wide-midnight-78598
03/05/2025, 2:33 PMwide-midnight-78598
03/05/2025, 2:33 PMpants fix fmt lint --only=ruff-format :: fails?fierce-greece-10087
03/05/2025, 2:36 PMCompleted: Lint with `ruff check` - ruff check failed (exit code 1).wide-midnight-78598
03/05/2025, 2:37 PMwide-midnight-78598
03/05/2025, 2:37 PMfierce-greece-10087
03/05/2025, 2:39 PMpants fix did fix the import ordering. Before I had much more errors regarding import ordering. Now pants fix says everything is fine, but pants lint still finds import ordering problems. Since it's ruff running behind the scenes in both cases, I'm not sure how this can happen.wide-midnight-78598
03/05/2025, 2:40 PMwide-midnight-78598
03/05/2025, 2:40 PMruff check --fixfierce-greece-10087
03/05/2025, 2:49 PMpants export and tried running ruff in the exported venv. All checks are fine: ruff format , ruff format --check, ruff check, ruff check --fix.wide-midnight-78598
03/05/2025, 2:50 PMfierce-greece-10087
03/05/2025, 2:51 PMwide-midnight-78598
03/05/2025, 2:51 PMhappy-kitchen-89482
03/05/2025, 5:08 PM:: or are you using --changed-since? There is an issue with how the tools infer first-party vs third-party that requires all the imported code to be present in the sandbox, so the tool can see it, but depending on how you invoked Pants, and on what's been cached, it may not be.happy-kitchen-89482
03/05/2025, 5:09 PMfierce-greece-10087
03/06/2025, 1:41 PM:: . Did also --changed-since, but I get the same result.
I'll check if there are some settings for ruff as you suggest, thanks.famous-kilobyte-26155
03/06/2025, 6:45 PMfamous-kilobyte-26155
03/06/2025, 7:02 PMhappy-kitchen-89482
03/07/2025, 12:38 AMfierce-greece-10087
03/07/2025, 12:47 PMknown-first-party didn't help. Also, only ruff is executed in this case (ruff format and ruff check). So I don't think I'm experiencing the joys of multiple nonstadard tools doing overlapping things π . I'll try to come up with a reproducible sample.fierce-greece-10087
03/07/2025, 2:14 PMknown-first-party and known-local-folder for every package in our repo. I did it wrong at the first attempt, where I thought I just need to set known-first-party globally. Now I use a local pyproject.toml for every package, where I take common settings via:
[tool.ruff]
extend = "../../../pyproject.toml"
And I removed the global pyproject.toml as a config for ruff in `pants.toml`:
[ruff]
config = "pyproject.toml" # <---- delete
So now ruff picks up the per-package pyproject.toml each time it goes through the folders.
Thank you all for the help !