intermodule dependency within the same project via relative path

I'm using IDEA Python plugin but I think this pertains to pycharm as well:

My project has 2 modules. scripts in module2 depend on scripts in module1 eg myscript.py needs to import help.py

I'd like to set a relative 'classpath' in module2 ie: something like $MODULEDIR$../../../../module1/src/py so it knows about the scripts in module1.src.py

I know I can do this by doing sys.path.append( <../../../../module1/src/py ) but don't wish to do that as my deploy mechanism will be different.

Dir Structure:

c:\MyProject

     -module1

           -src

                -py            

                     -helper.py

     -module2

          -src

                -py            

                    -myscript.py #depends on helper.py

I want to do this so that if someone else opens my project but has a different root dir eg c:\workspace\MyProject everything will still work because all the paths are relative to the project.

thanks

7 comments
Comment actions Permalink

In the Python plugin, you can define a dependency between the modules in Settings | Project Structure. Then the Python plugin will automatically add the dependent modules to the PYTHONPATH.

0
Comment actions Permalink

Thanks Dmitry,

Ive added module1 as a dependency of module2.

does that mean I will have to refer to helper.py via import src.main.py.helper?

that doesn't seem to work for me. importing helper.py doesn't work either. is it looking in a target folder in that module instead?

0
Comment actions Permalink

No, it looks at source roots (if you have any defined) or content roots. Please make sure that the "py" directory is marked as a source root.

0
Comment actions Permalink

Thank you, that makes sense and has worked.

Does Pycharm or the IDEA plugin give me a way of packaging that via a deploy button.

eg. if I write a setup.py will it output the tarball, zip and or msi for me?

0
Comment actions Permalink

You can use the distutils integration for this purpose. You'll need to write a setup.py file describing how your application needs to be packaged.

0
Comment actions Permalink

Sorr yi'm still new to pycharm and IDEA, I tried googling it but did not see any reference to: 'distutils integration' for Pycharm.

can you elaborate please? I do appreiate all your help!

0

Please sign in to leave a comment.