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:

package_A/
    python/
        __init__.py
        module_a.py
        module_b.py
        subpackage_A_1/
                __init__.py
                module_c.py        (<<< let’s say a function foo() is defined in this module)

    cpp/
       [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...

Michael

2 comments
Comment actions Permalink

Hi, 

You can try marking "subpackage_A_1" directory as source - https://www.jetbrains.com/help/pycharm/project-structure-dialog.html#2f736

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.

1
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...

0

Please sign in to leave a comment.