https://pantsbuild.org/ logo
#general
Title
# general
s

stale-nightfall-29801

10/26/2021, 9:21 AM
Sorry about this I've another Pants issue I could use some support on. I've got this structure that I'm trying to build a pex_binary target for (and eventually a docker target, but I'm not there yet): bar • bar ◦ init.py ◦ server.py ◦ data.py ◦ utils.py • test ◦ init.py ◦ <test_files> • BUILD • README • Dockerfile And this is my BUILD file
Copy code
python_library(
    name = "bar",
    sources = ["bar/*.py"],
)
python_tests(
    name="test",
    sources = ["test/test_*.py"],
    dependencies=[":bar","foo:foo"],
)
pex_binary(
    name="run",
    dependencies=[":bar"],
    entry_point="bar/server.py:main",
)
Here is the error:
Copy code
$ ./pants run bar:run 
Traceback (most recent call last):
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 483, in execute
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 401, in _wrap_coverage
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 432, in _wrap_profiling
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 539, in _execute
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 655, in execute_entry
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/pex.py", line 686, in execute_pkg_resources
  File "/home/james/Documents/monorepo/.pants.d/tmpfiz317ey/run.pex/.bootstrap/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py", line 2481, in resolve
ModuleNotFoundError: No module named 'server'
And checking my
./pants/roots
is see: bar bar/bar bar/test Also the tests run fine when I do
./pants test bar:test
Given my past problems I'm assuming it's a roots issue, but my other targets (2 packages, 2 tests) and the tests here all work. It's just the
pex_binary
in this web service that seems to not be working now.
c

curved-television-6568

10/26/2021, 9:31 AM
Just guessing here.. but it could be the
bar/bar
root that causing issues.. did you see it required for something else to work?
Aside, you shouldn’t have to add the dependency in the pex target.. as it will be inferred from the entry point.
s

stale-nightfall-29801

10/26/2021, 10:05 AM
Yeah this was the solution to my problem the other day with my directory structure where I had core/core/something.py requiring to be referenced as: core.core.something. There's 3 subfolders in this repo currently with the same structure and path entries and they all package and test fine,
bar
tests fine but fails to run
c

curved-television-6568

10/26/2021, 10:07 AM
I would have expected a source root of just
bar
to allow other parts to reference your modules as
bar.data
etc…
But I’m no expert, so will defer for a few hours until the experts wake up.. 🙂
s

stale-nightfall-29801

10/26/2021, 10:16 AM
Yeah you're right I'd just written an overly permissive glob in the roots config. But restricting it back down doesn't change anything
Ok this was the issue. I think the problems where: 1) My thinking about roots (I'd assumed it wouldn't hurt to have move files in there than the actual root) 2) The root_pattern glob was always drilling down too far as my folders are
foo/foo/<code>
so a pattern of
./foo
always yields
./foo
&
./foo/foo
The Fix:
Copy code
[source]
marker_filenames = ["BUILD"]
As I only put
BUILD
in my roots. Thanks again
👍 1
c

curved-television-6568

10/26/2021, 12:05 PM
Thanks for the feedback.
h

happy-kitchen-89482

10/26/2021, 3:45 PM
Glad that worked out! Sorry for the trouble. Source roots can be a gotcha, if you have any suggestions on how to improve the documentation on them, that would be really appreciated!
💯 1
I had in the past done a little work on autodetecting them in
tailor
, but it's trickier than you might think
s

stale-nightfall-29801

10/28/2021, 1:41 PM
Thanks, will do. I'll get my Proof of Concept project working then I'll reflect on the pain points and see how I can contribute back 🙂
❤️ 2