stale-nightfall-29801
10/22/2021, 9:17 AMcore is working fine (it's tests run and it packages from what I can tell) and it's BUILD file looks like this:
python_library(
name = "core",
sources = ["core/*.py"],
)
python_tests(
name="test",
sources = ["test/test_*.py"],
dependencies=["core"],
)
python_distribution(
name="dist",
dependencies=["core"],
setup_py_commands=["bdist_wheel", "sdist"],
provides=setup_py(
name='core',
version="1.0.0",
description='blah, blah, blah',
),
)
foo which depends on core can not find core as per this error:
________________ ERROR collecting foo/test/test_cherrypy.py _________________
ImportError while importing test module '/tmp/process-executionLlK5rO/foo/test/test_cherrypy.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/home/james/.pyenv/versions/3.8.12/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
foo/test/test_cherrypy.py:11: in <module>
from core.test_utils import token
E ModuleNotFoundError: No module named 'core.test_utils'
foo 's BUILD looks like this:
python_library(
name = "foo",
sources = ["foo/jwtutils.py", "foo/jwthug.py", "foo/jwtcherry.py"],
dependencies = ["core:core"]
)
python_tests(
name="test",
sources = ["test/test_*.py"],
dependencies=[
"core:core",
"thirdparty/python:cherrypy"
],
)
python_distribution(
name="dist",
dependencies=["foo"],
setup_py_commands=["bdist_wheel", "sdist"],
provides=setup_py(
name='foo',
version="1.0.0",
description='foo library',
),
)
My expectation is that the dependencies in python_tests make the core library available to foo, is this assumption incorrect?curved-television-6568
10/22/2021, 9:26 AMcurved-television-6568
10/22/2021, 9:27 AMstale-nightfall-29801
10/22/2021, 12:12 PMcore and foo are folders side-by-side and foo tests depend on a test_utils.py from corecurved-television-6568
10/22/2021, 12:39 PMenough-analyst-54434
10/22/2021, 1:52 PMfrom core.test_utils import token
E ModuleNotFoundError: No module named 'core.test_utils'
Pants needs to know X in the filesystem path X/core/test_utils.py. Pants call X a "source root". This is equivalent to a PYTHONPATH entry for Python. The list of "source roots" Pants knows about can be found by running pants roots. If X is not in the list printed out, you need to teach Pants about X as described here: https://www.pantsbuild.org/docs/source-roots#configuring-source-rootsstale-nightfall-29801
10/22/2021, 2:53 PMcore and foo are under monorepo if I'm in ~/Documents/monorepo and I do ./pants root and see . is that correctly telling me that it's root is at monorepo and it should successfully be able to find core and foo from each other ... OR should ./pants root be showing me . core foo ?enough-analyst-54434
10/22/2021, 3:04 PM., that says the file core/bob.py will be importable as core.bob.stale-nightfall-29801
10/22/2021, 3:10 PMcore/core/bob.py would be at core.core.bob which is not what I want ... the "outer" core holds the REAME, dockerfile, etc ... core/core is the "deployable" codeenough-analyst-54434
10/22/2021, 3:27 PMcore and foo. Let us know if https://www.pantsbuild.org/docs/source-roots#configuring-source-roots doesn't get you across the finish line.happy-kitchen-89482
10/22/2021, 3:49 PMtests parallel source tree is officially recommended. In the Pants repo, for example, we mostly have tests right alongside the code they test (so src/python/foo/bar.py is tested by src/python/foo/bar_test.py. Pants allows you to do this because it has the information to know not to bundle tests in the distribution, and so on. We like it because it's really easy to find the tests for some module, and vice versa.happy-kitchen-89482
10/22/2021, 3:49 PMstale-nightfall-29801
10/22/2021, 4:03 PMBUILD file at the root of each library/project folder.stale-nightfall-29801
10/22/2021, 4:18 PMcore/core and foo/foo but the BUILD files are at core and foo (This is where I really wanted to keep the "admin" like dockerfiles, README, LICENCE, etc.. as well as BUILD)stale-nightfall-29801
10/22/2021, 4:19 PMhappy-kitchen-89482
10/22/2021, 4:25 PMhappy-kitchen-89482
10/22/2021, 4:25 PMstale-nightfall-29801
10/22/2021, 4:26 PMNoSourceRootError: No source root found for `core`. See <https://www.pantsbuild.org/v2.7/docs/source-roots> for how to define source roots.happy-kitchen-89482
10/22/2021, 4:26 PMhappy-kitchen-89482
10/22/2021, 4:26 PMwitty-crayon-22786
10/22/2021, 4:26 PM./pants roots reporting?stale-nightfall-29801
10/25/2021, 8:29 AM. with the above changes it's reporting:
core/core and foo/foo I've also had to add the tests at core/test and foo/teststale-nightfall-29801
10/25/2021, 10:54 AM__init__.py in one of the test folders (This isn't my code, I'm copying into my Pants PoC folders from our main monorepo 😬 ).. I'd previously fixed this but re-copied everything after the main repo had a release ... Anyway. All is good now, no need to modify the sources. I just needed to make sure everything had a __init__.py