Adding a Python source dependency to other module in the same project

 I have a project with multiple Python modules, each of which has its own virtual environment. I want to add a source dependency from one module to another. Considering the following structure:

  • data-reader (Python module)
  • data-writer (Python module)
  • commons (Python module)

I want to add `commons` as a source package requirement to the other two modules. I have created `setup.py` file in `commons` and added the following line to the `requirements.txt` in the other two modules: `-e commons`.

After activating one of the modules (e.g., data-reader) and installing the requirements from `requirements.txt`, I can import and run scripts from `commons` using the Python interpreter from the terminal, but in Intellij IDEA the import line is underlined with a red line indicating an error and I cannot get all the auto-complete and documentation support.

I am using Intellij IDEA 2018.2 EAP and I have tried this with 2018.1 also.

Could you please let me know how can I properly define this dependency?

Thanks in advance

 

2 comments
Comment actions Permalink

Do you have a package_dir defined in your setup.py?

As far as I can tell, there are 2 ways to make IntelliJ do the right thing...

1.) Put your sources in the root of your module and don't define package_dir in your setup.py

2.) Import your shared project without the -e flag.

There is some bad combo between "editable" mode and using package_dir that IntelliJ trips over.  If you go with 1 you have to restructure your project to support your IDE (yuck).  If you go with 2 you have to pip install --force-reinstall every time you make a change in the shared library.

 

edit: additional color: https://github.com/pypa/pip/issues/435

it seems like this is no longer true with python 3.6, but intellij still doesn't see the files.

0
Comment actions Permalink

I've managed to make this work by adding the "common" module as an explicit dependency of the main project in IDEA's Project Settings -> Dependencies -> Add -> Module Dependency. Both modules are open in the same workspace.

0

Please sign in to leave a comment.