pythonpants

Subproject dependencies in pants


I am new to using pantsbuild and I can't seem to find any good questions, answers, or documentation around my dillema.

I have a Pants project which should be buildable on its own. It has its own pants and pants.ini file as well as all BUILD files containing paths relative to the project root (where pants.ini is). This project is hosted on GitHub.

I'd like to use this project as a dependency in a second project. I've chosen to use git submodules to do this. Now, I have a layout like the following:

path
├── pants
├── pants.ini
├── projectA
│   └── src
│       └── python
|           └── main
│               ├── BUILD
│               └── main.py
└── projectB
    ├── pants
    ├── pants.ini
    └── src
        └── python
            ├── libA
            |   ├── BUILD
            |   └── lib.py
            └── libB
                ├── BUILD
                └── lib.py

Naturally, I am looking to use projectB's BUILD targets from within projectA, so in projectA's BUILD, I have something of the sort:

dependencies = [ "projectB/src/python:libA" ]

This is all well and good. However, since projectB is an independent project, it's src/python/libA/BUILD file contains something of the sort:

dependencies = [ "src/python:libB" ]

Because of this, projectB can indeed be built independently. However, when trying to build projectA, the build targets from projectB search starting from projectA's project root, for instance:

Exception Message: libB was not found in BUILD files from path/src/python

Does pantsbuild have any clean way to handle these subproject dependencies? Or would I be forced to alter the BUILD files of the subproject in order to fit them within my project layout (Causing the project to be unbuildable independently)?

Any solutions or advice is welcomed!


Solution

  • So it turns out that the functionality I was hoping for was not supported by pants. At first, I followed the advice of a Yi Cheng in the comments and created a script to replace all subproject BUILD rules with those that are in relation to the root project. That script can be found here: https://github.com/brandonio21/pants-subproject-prep

    The script was pretty limited, however, and was far from a workable solution. I have since changed pants upstream to support the behavior. The PR was here: https://github.com/pantsbuild/pants/pull/4088

    Now, if you have a subproject within another pants project, building the root project with --subproject-roots=["path/to/subproject1_root", "path/to/subproject2_root"] (Or specifying the option in pants.ini) will build the subproject from the proper subproject root