hello! this is probably a dumb question but is the...
# general
a
hello! this is probably a dumb question but is there a way to figure out why some files are not being included as dependencies if I am relying on dependency inference? for example if I have
src/BUILD
Copy code
python_library(
    name='server'
)
src/app.py
which imports
fraud.api
I would assume that fraud/api.py would be included in the
./pants dependencies --transitive src:server
output? However it is not present - (it is very possible that I am misunderstanding the dependency inference capabilities)
h
Hello! Often this is one of two things: 1) Multiple targets "own" the module
fraud.api
. See the warning at https://www.pantsbuild.org/docs/targets#sources 2) Source roots are not configured properly What is the file corresponding to
fraud.api
?
a
i have my source_route set to to pull in
src
From that link i saw the
./pants list fraud/api.py
command which seemed helpful!
Copy code
Scrubbed PYTHONPATH=/home/nate/wave/remit-srv/src: from the environment.
12:38:51.90 [INFO] initializing pantsd...
12:38:52.29 [INFO] pantsd initialized.
12:38:52.95 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/bin/local_pants_runner.py", line 276, in run
    engine_result = self._run_v2(goals)
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/bin/local_pants_runner.py", line 190, in _run_v2
    return self._maybe_run_v2_body(goals, poll=False)
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/bin/local_pants_runner.py", line 207, in _maybe_run_v2_body
    return self.graph_session.run_goal_rules(
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/init/engine_initializer.py", line 131, in run_goal_rules
    exit_code = self.scheduler_session.run_goal_rule(
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/engine/internals/scheduler.py", line 563, in run_goal_rule
    self._raise_on_error([t for _, t in throws])
  File "/home/nate/.cache/pants/setup/bootstrap-Linux-x86_64/2.2.0_py38/lib/python3.8/site-packages/pants/engine/internals/scheduler.py", line 531, in _raise_on_error
    raise ExecutionError(

Exception message: 1 Exception encountered:

  ResolveError: No owning targets could be found for the file `src/fraud/api.py`.

Please check that there is a BUILD file in `src/fraud` with a target whose `sources` field includes `src/fraud/api.py`. See <https://www.pantsbuild.org/v2.2/docs/targets> for more information on target definitions.
If you would like to ignore un-owned files, please pass `--owners-not-found-behavior=ignore`.
thanks so much for the quick response also
do I need to add a BUILD file to all directories in my project for dependency inference to work?
h
do I need to add a BUILD file to all directories in my project for dependency inference to work?
More or less, yeah. And Pants 2.3 can automate this for you. Change
pants_version = "2.3.0rc0"
, then run
./pants tailor
(Lmk if Pants fails to run, there's an issue with running in certain linux environments we're trying to isolate)
w
would commit before running
./pants tailor
, as it will update your BUILD files. but yea, it’s for precisely this case.
βž• 2
a
ah ha! i was just going to ask if it would be worth adding something like that
w
thanks to @acceptable-guitar-79854 for the initial idea, to @jolly-midnight-72759 for the name, and @happy-kitchen-89482 for the implementation πŸ˜ƒ
πŸ‘– 2
βž• 3
h
Seconding the suggestion of running
tailor
in a clean commit as it doesn't have a dry run mode (yet?) and will actively modify your build files. Although it only appends, never modifies existing targets.
a
great - one thing that is a little confusing about the documentation (or maybe I don't understand how it works) is that here: https://www.pantsbuild.org/docs/existing-repositories# it says:
As explained in Targets and BUILD files, you can use fewer BUILD files, such as one BUILD file per subproject; but we find that one BUILD file per directory is a good default.
Which sounds like it dependency inference will still work even if you only have one BUILD file per larger unit of code (e.g. the top level package)
πŸ‘ 1
h
Which sounds like it dependency inference will still work even if you only have one BUILD file per larger unit of code (e.g. the top level package)
Yeah, it should, but only if you set
sources=["**/*.py"]
for example so that every Python file has a single owning target Although now that
./pants tailor
exists and it's less expensive to create one BUILD file per directory, we want to encourage even more using that style, whereas before we were more that either approach is valid. That section should probably be rewritten now
a
ohhhhhh huh interesting yeah i think it would be super helpful to add that context
are the docs in github? I can submit a PR adding that
❀️ 2
h
They're with a site called Readme.io. Do you see the "Suggest edits" button in the top right corner?
a
yup! thanks
h
Thanks for the docs suggestion @average-australia-85137! To check, is dependency inference working for you alright?
a
it is now after I added all BUILD files, I'm on 2.2 now but I will check with 2.3 in a bit (right now I'm working on getting our tests running)
πŸ’― 1