-
Notifications
You must be signed in to change notification settings - Fork 193
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
FullyQualifiedNameProvider: Optionally consider pyproject.toml files when determining a file's module name and package #1148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few concerns with this approach:
calculate_module_and_package
shouldn't do any IO.- the location of a
pyproject.toml
is a heuristic that shouldn't be part of the core logic, it should be behind a switch that can be enabled/disabled - I'd argue that the default behavior should be the old one
Maybe it's better if the passed in repo_root
has already applied this heuristic if it's desirable.
@zsol thanks for taking a look! For context, my use case is a single repository containing many interdependent packages. Because of the interdependencies, it needs to be analyzed as a whole (e.g. I need information on the entire class hierarchy, which spans multiple packages). AFAICT, the main user of So, it's not feasible for me to have a separate repo root per package, and I don't see a way to feed the package information into FQNP.gen_cache given the current signature. AFAICT, So I think the best approach would be to have a global switch. Or perhaps an option on the Regarding the default behavior, I'd argue that the existing behavior of inferring the package from the file path relative to the repo root is also a heuristic, and for a repo that contains pyproject.toml files it is less likely to give the intended results than what I am proposing. But I'm fine with pyproject.toml parsing not being the default. |
That's right. I propose to do the My main concern is that
Agreed that the existing behavior is also just a heuristic, but I'm not convinced that the |
Sounds good. I don't see an existing API for this kind of global configuration. Is it ok if I keep it simple and just make it a global variable? |
Ugh, that's annoying :( Ideally this would be stored in the libcst config file (that's read here) and then passed into Maybe we should change the API for |
Oh, I'm not using the CLI at all. I'm using LibCST as a library from another program, so that config file doesn't apply.
|
Sounds good, then! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1148 +/- ##
==========================================
+ Coverage 91.12% 91.15% +0.03%
==========================================
Files 256 261 +5
Lines 26567 26864 +297
==========================================
+ Hits 24210 24489 +279
- Misses 2357 2375 +18 ☔ View full report in Codecov by Sentry. |
@zsol I think it's done, PTAL! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
When determining the module name and package for a source file, LibCST currently takes the file name relative to the repository root. With this change, it will instead look for the closest directory containing a
pyproject.toml
file in the file's ancestors, and consider the file name relative to that directory.This gives correct module and package names when processing a repository containing multiple packages. For files that are not covered by a
pyproject.toml
, the search ends with the given repository root, thus retaining the old behavior.