cool-easter-32542
08/17/2023, 2:12 AMUnownedDependencyError. The error only occurs on relative imports and what's interesting is pants says the source for the relative import is the old file that was moved.
Pants version
2.17.0rc1
OS
Both MacOS and Linux
Additional info
This issue is a bit difficult to reproduce. There's some specific order of operations that causes pants to get into this state.
I pushed this a branch to my example repo https://github.com/njgrisafi/pants-example/tree/example-dep-inf-issue to hopefully help with narrowing down reproducing this.
Simple reproduction
1. Clone repo git clone git@github.com:njgrisafi/pants-example.git
2. Checkout the first branch git checkout example-dep-inf-issue
3. Run dependency inference ./pants peek :: >> /dev/null
4. Checkout the second branch git checkout example-dep-inf-issue-2
5. Run dependency inference ./pants peek :: >> /dev/null
You should see the following error
UnownedDependencyError: Pants cannot infer owners for the following imports in the target app/module_2/break_pants/__init__.py:
* module_1.break_pants._example.x (line: 1)
To fix the issue you can nuke all the pants artifacts
rm -rf ~/.cache/pants
rm -rf .pids
rm -rf .pants.d
Rerunning dependency inference will now succeed as expected.
Detailed reproduction
Detailed steps to repro this behavior (first checkout repo / branch example-dep-inf-issue):
1. Run dependency inference ./pants peek :: >> /dev/null
2. Add new module app/module_2/break_pants
• Create file app/module_2/break_pants/__init__.py (with content from ._example import x)
• Move file app/module_1/break_pants/_example.py -> app/module_2/break_pants/_example.py
3. Update the old code
• app/module_1/break_pants/__init__.py (with content from module_2.break_pants import *)
4. Run dependency inference ./pants peek :: >> /dev/null
You should see an error like
UnownedDependencyError: Pants cannot infer owners for the following imports in the target app/module_2/break_pants/__init__.py:
* module_1.break_pants._example.x (line: 1)
The expected behavior is pants would map the relative import to module_2.break_pants._example.x.
pantsbuild/pantscool-easter-32542
08/22/2023, 12:43 AM