Hey folks! I’m having trouble with in-monorepo (so...
# general
m
Hey folks! I’m having trouble with in-monorepo (source layout) dependencies declared with poetry in pyproject.toml, when running
pants test ::
. The structure of the dependency isn’t flattened, so the references to it fail (when
pytest
works correctly, outside of pants). What am I missing? •
src/libs/package_1
depends on
src/libs/package_2
, ◦ declared with a line like
package_2 = { path = "../package_2", develop = true }
in the
[tool.poetry.dependencies]
section of my
pyproject.toml
◦ Code for package 2 lives in
src/libs/package_2/src/package_2/*.py
◦ both have a single BUILD file in the package root, with
python_sources
,
python_tests
and
poetry_requirements
(sources depends on poetry, tests on both) •
pytest
, run outside of pants, executes tests in
src/libs/package_1/tests/test_*.py
◦ It correctly loads
package_2
source files and tests succeed ◦ I believe this is because of the line
packages = [{ include = "package_2", from = "src" }]
inside
[tool.poetry]
of my package_2
pyproject.toml
. •
pants test src/libs/package_1::
fails with
ModuleNotFoundError: No module named 'package_2'
◦ When I keep & inspect the sandbox, the
src/libs/package_2/
dir is empty except for
src/package_2/*.py
◦ I believe
package_1
is unable to read the source in
../package_2/*.py
because it’s actually in
../package_2/src/package_2/*.py
but there’s no
pyproject.toml
there to include that — does this seem correct? •
pants run tools/whatever::
(which depends on
package_1
) successfully runs using
package_1
(and its dependency on
package_2
) I’ve tried including a
resources(name="pyproject", sources=["pyproject.toml"])
in
package_2
, (with both the package_2
python_sources
depending on it, and package_1's
python_tests
) — with no change in the outcome, despite the package_2
pyproject.toml
being present in the sandbox. I think I’m either missing something stupid; or the approach I’m taking with using
poetry
for dependency management is confusing matters. Can anyone suggest debug steps?
g
good debug step would be a public repo replicating just the scenario you're looking for. some 'first-look' suggestions: • try without poetry https://www.pantsbuild.org/stable/docs/python/overview/third-party-dependencies • try
resources(name=reqs, sources="pyproject.toml")
- raw string instead of an array • check
echo $PYTHONPATH
• check `pants.toml`: source root_patterns, python-bootstrap
☝️ 1
m
Yeah, it’s probably time for a minimal repro repo. Thanks for the nudge 🙂
Ooh, some great new advice in the edits too — thank you!