-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature-request] enhanced first-party detection #1332
Comments
|
Hi @andersk, we disagree here.
Unless something changed very recently, this is only true if the package is a direct child of one of the paths on src.
While this might be typical, it is not necessarily the most common design for large projects using monorepos. I work on the large monorepo Dagster. Our python packages are not siblings of
There's nothing ambiguous about a setting that tells ruff to classify packages as first-party depending on a suffix. Also, I think by your definition Ruff is already using a heuristic that works 99% of the time for first-party detection (i.e. for non-namespace packages), which is to trace FWIW, I requested that functionality specifically to support situations where there are many python packages in a monorepo but one doesn't want to add a |
My goal here isn’t to agree or disagree, just to figure out whether the existing mechanisms are sufficient and where they fall short. Looking at your monorepo, it seems to me that you should be able to configure [tool.ruff]
src = [
"docs/dagit-screenshot",
"examples/*",
"helm/dagster/schema",
"integration_tests/python_modules/*",
"python_modules/*",
"python_modules/libraries/*",
] which seems manageable? Meanwhile, your proposed |
The
See my previous comment-- ruff already detects
|
Ah, my apologies for misreading—I hadn’t noticed that update (#1266). It seems to me that if we’re going to trace up the |
I have a similar problem with bazel monorepo setup, where Example (variable name could be better): [tool.ruff]
root-file = ["BUILD", "BUILD.bazel"] Example structure:
|
@condemil - Oh yeah that's an interesting use-case. Is it possible to solve with
|
Unfortunately, the solution you mentioned isn't working. I don't know the exact reason, but I may guess it is because of the following:
|
Ah yeah that makes sense -- I didn't realize that you wanted each package to consider each other package as third-party (which is reasonable but not always the case for monorepos). Lemme try a few things out before I make any other suggestions. |
Probably the most common use-case for marking a package as a "known first party" import is when you have an associated test package. In the world of
pytest
, the associated test package is typically called<TARGET_PKG>_tests
. It would be cool if auto-first-party detection was smart enough to understand this.For example:
This could be implemented by a
tool.ruff.isort
option called something likefirst-party-grouping-suffixes
(certainly not wedded to the name). The idea would be that any package matching a suffix is treated identically to its "stem" for purposes of first-party grouping. So:IMO
["_tests"]
would be a reasonable default for this option. There might also be other suffixes to include used by other test frameworks.The text was updated successfully, but these errors were encountered: