PY-54269 Set up cross-module dependencies using the existing "transferred roots" mechanism

Namely, whenever there is a `sys.path` entry or a user-added path pointing
to the root of another project module, instead of configuring a source root
for it, we now set up the corresponding module dependency and save it
as a "transferred root" in additional data alongside extra directories
configured as source roots.

This POC solution has a number of limitations:
- A module dependency is set up only if the corresponding module
has already been added to the project. Modules are added using
"Attach to project" as before.
- Since detecting modules is happening on the interpreter introspection
phase, if project A depends on project B, once the module B is actually
configured as an IJ module, one needs to restart SDK update for project
A's SDK to detect the dependency.
- Detecting module dependencies this way requires having a configured
project interpreter for each dependent module, which might not be
practical for large projects, such as grazie-ml.
- It doesn't play well with manual editing of module dependencies in
settings.

Overall, this workaround works well with an existing multi-module project,
where a new subproject with its own SDK and module dependencies needs to
be added as an IJ module. But ideally we need to rely on the actual
project configuration files, not on runtime values of `sys.path`, and
make the workflow of configuring all project modules at once simpler.

A registry key "python.detect.cross.module.dependencies", disabled by default,
activates the feature.

As part of the feature, I also disabled configuring source roots for
`sys.path` entries not belonging to the current module. It leads
to a confusing situation where multiple modules have a content root
(with a single source root) pointing to the same directory in another
module. In a multi-module setting, it can happen if several modules
depend on some subproject that has not yet been configured as an IJ
module.

GitOrigin-RevId: 47e832edeeea21f5206c981bd604a6012100e9da
This commit is contained in:
Mikhail Golubev
2025-02-04 22:07:19 +00:00
committed by intellij-monorepo-bot
parent 003f4e9702
commit fc8b4ca91a
5 changed files with 219 additions and 63 deletions
@@ -646,6 +646,10 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
restartRequired="false"
description="Disables automatic updating of PyPI package cache and ranking on project startup."/>
<!-- Setting up cross-module dependencies -->
<registryKey key="python.detect.cross.module.dependencies" defaultValue="false"
description="Try to detect and automatically set-up module dependencies in a multi-module project"/>
<feedback.idleFeedbackSurvey implementation="com.jetbrains.python.statistics.feedback.PythonJobSurvey"/>
<statistics.counterUsagesCollector implementationClass="com.jetbrains.python.statistics.feedback.PythonJobStatisticsCollector"/>
<backgroundPostStartupActivity implementation="com.jetbrains.python.statistics.feedback.PythonFirstLaunchChecker"/>