Source navigation with nonstandard package directory structure...

Is it possible to have a python package, that is defined in the source with a slightly unusual directory structure, be parsed so that PyCharm code navigation behaves desirably?

Because I’m mixing languages in my project, I’ve got an intermediate directory that ‘breaks’ what would be a clean package/module structure, which in turn prevents click-to-go-to-definition behavior from PyCharm. For example, the source for a package might be store like this:

              (<<< let’s say a function foo() is defined in this module)

       [c++ files in this dir]


In any source that uses package_A, I might refer to a module like so:

        from package_A.subpackageA_1.module_c import foo


My build process puts everything together so that this is correct and it runs properly in the “released” executable code, but this structure breaks code smarts in PyCharm (used during development) so that I can’t easily mouse-click on functions such as foo() and jump to the definition in module_c.

Is there a way to tweak some PyCharm setting - maybe something about project structure  - that would allow this to behave properly? It *seems* like it might, hence my question!

Thanks in advance for any ideas...


Comment actions Permalink


You can try marking "subpackage_A_1" directory as source -

But you would also need to change the import statement to...

subpackageA_1.module_c import foo

So it probably defeats the purpose.

The only solution I can think of is to generate stubs for your modules and place them at the target location. Then, tweak your build script to remove the stubs before placing the actual code there.

Comment actions Permalink

Thanks for the response Andrey - Let me see if either of those are palatable.

I'm wondering how others handle their multiple-language development - I don't like having vastly different locations per-language...


Please sign in to leave a comment.