Make rope project aware of core libraries

217 Views Asked by At

I'm working on a large code base and I'd like to set up rope projects so that rope is fast and does what I want. For what it's worth, I'm using rope with emacs, but if I understand correctly, rope's behavior should be independent of the editor.

The code base has many core libraries used by many apps. Each app depends on one or more core libraries but never on another app. Here's a simplified representation of the directory structure:

repo
|-- core 
|   |--CoreLib1
|   |   |-- CoreLib1.egg-info
|   |   `-- library_module
|   |        |-- __init__.py
|   |        `-- lib.py
|   `--CoreLib2
|       |-- CoreLib2.egg-info
|       `-- library_module
|            |-- __init__.py
|            `-- lib.py
`-- apps
    |-- AppA
    |   |-- AppA.egg-info
    |   `-- app_a_module
    |        |-- __init__.py
    |        `-- src.py
    |-- AppB
    |   |-- AppB.egg-info
    |   `-- app_b_module
    |        |-- __init__.py
    |        `-- src.py
    `-- AppC
        |-- AppC.egg-info
        `-- app_c_module
             |-- __init__.py
             `-- src.py

What I want to do

Currently I have repo/.ropeproject, and rope behaves how I want, but is slow. I believe the slowness is because it's analyzing all the code in all the apps at any given time. To solve this, I'm trying to create a rope project in each app (e.g. /repo/apps/AppA/.ropeproject) that knows about core but doesn't know about the other apps. The problem is, I can't get it to know about core. This means I can't do any rope operations on any names from core.

Works, but is slow:

  1. Make sure there are no .ropeproject directories in the whole code base. Create a rope project in /repo/.
  2. Put the following code in /repo/.ropeproject/config.py:
    src_dirs = [
        dirpath
        for dirpath, dirnames, filenames in os.walk('core/')
        if any(map(lambda dirname: dirname.endswith('.egg-info'), dirnames))
    ]
    for src_dir in src_dirs:
        prefs.add('python_path', src_dir)
  1. Reload the rope project (to make sure it's using the freshly updated config.py)
  2. Rope Generate Autoimport Cache. This takes upwards of 60 seconds and can't run in the background.
  3. While editing repo/apps/AppA/app_a_module/src.py, attempt to use rope to auto-import a name from core. It works.

Fast, but doesn't work:

  1. Make sure there are no .ropeproject directories in the whole code base. Create a rope project in /repo/apps/AppA/.
  2. Put the following code in apps/AppA/.ropeproject/config.py:
    src_dirs = [
        dirpath
        for dirpath, dirnames, filenames in os.walk('../../core/')
        if any(map(lambda dirname: dirname.endswith('.egg-info'), dirnames))
    ]
    for src_dir in src_dirs:
        prefs.add('python_path', src_dir)
  1. Reload the rope project (to make sure it's using the freshly updated config.py)
  2. Rope Generate Autoimport Cache. This takes less than 1 second.
  3. While editing repo/apps/AppA/app_a_module/src.py, attempt to use rope to auto-import a name from core. It fails.

Is what I want to do within the scope of rope's capabilities? Should it be able to work? If so, what am I doing wrong?

0

There are 0 best solutions below