Skip to content
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

Plugin doesn't recognise python source roots #350

Open
hsestupin opened this issue Jun 27, 2018 · 19 comments
Open

Plugin doesn't recognise python source roots #350

hsestupin opened this issue Jun 27, 2018 · 19 comments
Labels
lang: python Python rules integration not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) product: IntelliJ IntelliJ plugin type: bug

Comments

@hsestupin
Copy link

Sample project https://github.com/hsestupin/bazel-python-source-root

Open file https://github.com/hsestupin/bazel-python-source-root/blob/master/python_source_root/mymodule/submodule/b.py

What I expect is that absolute mymodule import is normally resolved and user is able to jump via cmd+b from sub_a.aa() call expresison to adjacent module a.py.

Now it's impossible since Idea says that mymodule is unresolved.

screen shot 2018-06-27 at 13 09 19

However this could be fixed by manually setting python_source_root directory as a source root in project settings. But obviously this change will be immediately discarded after the next project sync.

May be my project setup is incomplete or there is some workaround ?

@brendandouglas
Copy link
Contributor

Thanks for letting us know. This is a bazel-specific issue, which is why we hadn't noticed earlier -- per-target custom source roots aren't allowed in the internal version of bazel.

This shouldn't be too difficult to fix. We'll need to change our skylark aspect to collect the 'imports' attribute data, and either set up source roots as you suggest, or add some additional custom import resolvers.

Source roots would be a much more reliable solution of course, but aren't a python-specific concept in IJ -- for projects with multiple languages, source roots can conflict. If we can't find a way around that, we'll just continue with custom import resolvers (which already provide resolution relative to the workspace root and genfiles directory).

@chaoren chaoren added the lang: python Python rules integration label Aug 1, 2018
@PoncinMatthieu
Copy link

We have a very similar issue. Imports are not resolved between subpackages.
For example we define tests as a subpackages, so we have something like this:

/my_package/BUILD
/my_package/tests/BUILD

And projectview file would look like this:

directories:
  my_package/

When syncing our project, intellij will set my_package in the python_source_root, but our subpackage is not added and therefore any imports made on the tests subpackage is not resolved by IntelliJ.
We are also able to fix it by directly editing the python_source_root. However IntelliJ UI prevents us from doing that directly because it consider the new directory conflicting with the current one, but we are able to trick it into adding it by first excluding the tests folder from the current source root.
Note that bazel plugin also doesn't take into account the import attributes nor the genfiles (#389)
Should I report this as a separate issue or keep this here?

@ghost
Copy link

ghost commented Apr 15, 2019

@brendandouglas Is this on Google's IJ team's roadmap to fix anytime soon? This is a recently discovered pain point for one of our teams that has migrated to Bazel. It's my job to make sure they don't revolt, so without an upstream fix coming, I may have to try fixing it myself. I don't mind rolling up my sleeves, but any guidance would be appreciated. :)

@brendandouglas
Copy link
Contributor

Hi @beasleyr-vmw, this isn't on our roadmap at the moment. The hard part here is exposing the additional source roots to starlark in a usable form (ideally after make variable substitution).

@knarukulla
Copy link

Any workaround to the issue would be helpful

@thirtyseven
Copy link
Contributor

A workaround we use is to have the python source root be separately listed in the directories: section of the project view file. However, for this to work, none of its parent directories (including .) can be listed.

@thomaslangston-mongodb
Copy link

Copying my understanding of the problem from my duplicate issue: #3783

The Bazel IntelliJ plugin appears to detect IntelliJ project source roots by the presence of specific Java centric identifiers.

https://github.com/bazelbuild/intellij/blob/master/java/src/com/google/idea/blaze/java/sync/source/SourceDirectoryCalculator.java

Manually editing the source roots via the context menu by clicking on a folder in the Project view and selecting "Mark Directory As -> Sources Root" is discarded on each IntelliJ Bazel plugin Sync.

For Python files and targets, this means their source roots are never detected and cannot be persisted between IntelliJ Bazel plugin Syncs.

Source root detection doesn't appear to work even for Java files in some cases : #1992

I can think of a few different paths to address this problem:

Stop automatically setting source roots on each Sync. Force them to be manually configured like a regular IntelliJ project.
Maybe still allow automatic detection only on the first IntelliJ project import?
Allow manual configurations via IntelliJ's menus to work as an override that persists through syncs.
Make a BUILD target / .bazelproject setting / etc. that flags a directory during Sync as a source root.
Refine the automatic detection logic so it can detect the correct source roots under a variety of scenarios including Python only directories

@github-actions
Copy link

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Mar 16, 2023
@thirtyseven
Copy link
Contributor

@bazelbuild/triage this issue is still relevant

@gmishkin
Copy link

Specifically I'm curious if

The hard part here is exposing the additional source roots to starlark

Is not a concern anymore since rules_python was (I think?) moved to Starlark recently.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Mar 17, 2023
@sgowroji sgowroji added product: IntelliJ IntelliJ plugin awaiting-maintainer Awaiting review from Bazel team on issues labels Apr 17, 2023
@keertk keertk moved this from Untriaged to Triaged in Bazel IntelliJ Plugin Apr 17, 2023
@mai93 mai93 added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed awaiting-maintainer Awaiting review from Bazel team on issues labels Apr 17, 2023
@mai93 mai93 removed their assignment Apr 17, 2023
@mai93 mai93 moved this from Triaged to Backlog in Bazel IntelliJ Plugin Apr 17, 2023
@github-actions
Copy link

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Oct 18, 2023
Copy link

github-actions bot commented Nov 1, 2023

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in Bazel IntelliJ Plugin Nov 1, 2023
@honnix
Copy link

honnix commented Nov 30, 2023

I believe this is still a very relevant feature request.

@WearyMonkey
Copy link

WearyMonkey commented Dec 6, 2023

Still relevant, we have mono repository with typescript project under a sub-directory.
There's currently no way to set the typescript projects src/ as a sources root.

@mai93 mai93 reopened this Dec 6, 2023
@github-project-automation github-project-automation bot moved this from Done to Untriaged in Bazel IntelliJ Plugin Dec 6, 2023
@mai93 mai93 moved this from Untriaged to Backlog in Bazel IntelliJ Plugin Dec 6, 2023
@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Dec 7, 2023
Copy link

github-actions bot commented Jun 7, 2024

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 7, 2024
@phil-osk
Copy link

phil-osk commented Jun 7, 2024

This is still an issue that everyone with a monorepo has to work around.

@mai93 mai93 added not stale Issues or PRs that are inactive but not considered stale and removed stale Issues or PRs that are stale (no activity for 30 days) labels Jun 7, 2024
@luke-robertson
Copy link

+1

@tpasternak
Copy link
Collaborator

I didn't have time to check that, but it seems the problem is at least partially covered #6599 (comment)

@tpasternak
Copy link
Collaborator

@luke-robertson @phil-osk can you confirm if you still experience the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: python Python rules integration not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) product: IntelliJ IntelliJ plugin type: bug
Projects
Status: Untriaged
Development

No branches or pull requests