brash-student-40401
09/29/2022, 1:38 PMsetup.py
? The use case here is moving code to a monorepo, and trying to use code that was previously installed with a pip install
. From some old Github conversations, I believe this should be possible, but I couldn't find documentation for how to set things up. Details in đź§µ.brash-student-40401
09/29/2022, 1:38 PMsrc
|- common
| |- packageA
| |- BUILD
| |- __init__.py
| |- packageA_class.py
| |- ...
| |- packageB
| |- packageB
| |- BUILD
| |- __init__.py
| |- packageB_class.py
| |- ...
| |- setup.py
| |- BUILD
| |- ...
In this case, packageB
is coming from another repo. In a non-monorepo world, I would simply pip install packageB
, and use import packageB
in packageA's code. However, once I moved it to my monorepo, I can't get the dependency coded correctly in packageA
.
Here's my `src/common/packageB/BUILD`:
python_sources()
python_distribution(
name="packageB_dist",
provides=setup_py(
setup_script="setup.py",
name="packageB",
version="0.2.0",
),
)
And `src/common/packageA/BUILD`:
python_sources()
pex_binary(
name="packageA_bin",
entry_point="packageA_class.py",
dependencies=["src/common/packageB:packageB_dist"]
)
My expectation here is that when I try to build packageA
, it will use `packageB`'s setup.py
to install it, and then I can do a simple import common.packageB
, but that gives me a ModuleNotFoundError
. What am I missing here to get this use case working?
Running ./pants dependencies src/common/packageA
correctly indicates the problem:
13:23:53.21 [WARN] Pants cannot infer owners for the following imports in the target src/common/packageA/packageA_class.py:
* common.packageB (line: 1)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
src/common/packageA/packageA_class.py
src/common/packageB:packageB_dist
So it sees the packageB distribution, but cannot resolve its import.happy-kitchen-89482
09/29/2022, 2:36 PMhappy-kitchen-89482
09/29/2022, 2:37 PMsrc/common/packageB:packageB_dist
to A’s python_sources
target. It’s the code in that target that is actually consuming packageB via an import.happy-kitchen-89482
09/29/2022, 2:39 PMcommon.packageB
import, so not clear why that is failing.happy-kitchen-89482
09/29/2022, 2:39 PM./pants roots
show?brash-student-40401
09/29/2022, 2:42 PM./pants roots
correctly shows src
as a root, I'm using the import common.whatever
elsewhere succesfullyhappy-kitchen-89482
09/29/2022, 2:47 PMsrc/common/packageB
has no __init__.py
, so I wouldn’t expect you to be able to import from ithappy-kitchen-89482
09/29/2022, 2:48 PMbrash-student-40401
09/29/2022, 2:48 PMsetup.py
for now is laziness - I expected it to keep everything nice, without me having to mess with the BUILD too much. But there's nothing really special in there, I believe I can get away without ithappy-kitchen-89482
09/29/2022, 2:48 PMhappy-kitchen-89482
09/29/2022, 2:48 PMhappy-kitchen-89482
09/29/2022, 2:49 PMhappy-kitchen-89482
09/29/2022, 2:50 PMsrc/common/packageB
as a source rootbrash-student-40401
09/29/2022, 2:51 PMcommon/packageB/packageB/
(where all the code lives) to just common/packageB/
?happy-kitchen-89482
09/29/2022, 2:51 PMcommon.packageB
?happy-kitchen-89482
09/29/2022, 2:51 PMsetup.py
is to add src/common/packageB
as a source roothappy-kitchen-89482
09/29/2022, 2:52 PMimport packageB
, not import common.packageB
happy-kitchen-89482
09/29/2022, 2:52 PMimport packageB
was how packageA was importing it before the monorepo?brash-student-40401
09/29/2022, 2:53 PMimport common.packageB.packageB
and got past that first import, but bombed deeper in the code where there are old `import packageB`s that I need to fix. I think I have a few options to try, let me play around and let you know.brash-student-40401
09/29/2022, 2:53 PMhappy-kitchen-89482
09/29/2022, 4:10 PMbrash-student-40401
09/30/2022, 3:42 AMhappy-kitchen-89482
09/30/2022, 5:14 AM