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

thankful-needle-74204

10/09/2018, 12:07 PM
Hello 🙂 can some please explain to me how pants resolves the requirements? I have a `python_binary`target that has local dependencies that are compiled before the `pyprep`goal. But when I execute the created PEX, it does not include the compiled local dependencies
e

enough-analyst-54434

10/09/2018, 1:04 PM
There are two parts to requirement resolution depending on the flavor of requirement and it sounds like you have the first part set up. Firstly, a target must have a BUILD dependency on its requirements, whether they be local (say a
python_library
BUILD target) or third party. Secondly, in the third party case, the dependency is on a
python_requirement_library
or requirements.txt file via
python_requirements
. I'll stop there to find out more about your dependency setup.
I guess I can help things along more. You say:
python_binary
target that has local dependencies that are compiled ...
What do you mean by "compiled" - what types of targets are these?
t

thankful-needle-74204

10/09/2018, 1:26 PM
in my `python_binary`target, I have defined a local dependency. However the modules for that package are created during a task before the `pyprep`goal. And when the binary is created, the modules are not found
So basically my local package looks like this:
Copy code
package
  a.py
  b.py
  __init__.py
a.py and b.py are created during a task
e

enough-analyst-54434

10/09/2018, 1:35 PM
Aha. There is a fair bit of work to get generated code seen by Pants in general still. We have that wrapped up in a base class here: https://github.com/pantsbuild/pants/blob/aeb800d621881164a3973e393f86a843aa5254af/src/python/pants/task/simple_codegen_task.py#L30-L31 Do you happen to know if your task uses this base class? It doesn't absolutely have to, but if it does not, it needs to be calling `self.context.add_new_target`: https://github.com/pantsbuild/pants/blob/master/src/python/pants/task/simple_codegen_task.py#L349 and `self.context.build_graph.inject_dependency`: https://github.com/pantsbuild/pants/blob/master/src/python/pants/task/simple_codegen_task.py#L364
The 1st call to create a "synthetic" target to own the generated source files, the 2nd to link the new target as a dependency.
t

thankful-needle-74204

10/09/2018, 3:20 PM
but that does not allow me to add an existing target, right? Is there a way to overwrite it?
e

enough-analyst-54434

10/09/2018, 3:23 PM
It does. The general scheme is as follows: Given: targetA depends on targetB:
targetA -> targetB
targetB has python code generated from the files it owns. Then: The code generating task: 1. generates py files from targetB 2. creates a "synthetic" target targetBprime whose sources are the generate files from step 1 3. adds a dependency on targetBprime to targetA
👖 1
The SimpleCodeGen Task baseclass I referenced takes care of most of these mechanics, letting your task pretty much just generate code
So, in the end you get:
targetA -> [targetB, targetBprime]
Does that make some sense?
t

thankful-needle-74204

10/09/2018, 3:37 PM
Ah I see 💡 Thank you very much! 😊
2 Views