can a target have two SourceFields? i.e. a python ...
# plugins
a
can a target have two SourceFields? i.e. a python and a yaml field?
👀 1
h
Not really, unfortunately. The Target API won't be happy when you say
tgt.get(SourcesField)
What's the use case?
a
one of my targets needs both YAML and Python
h
Also fyi there is
SecondaryOwnerMixin
so that you get file-like benefits, like that a file argument still works on the target This is how
pex_binary
works. It does not "own" the file
entry_point=main.py
, yet you can still do
./pants run project/main.py
That one is safe to use on as many targets as you'd like
and Python
I wonder if that Python should be "owned" by
python_source
target, and then your new target links up to it. Similar to
pex_binary
a
yeah you're right
just need to work out how to make it work.
👍 1
h
for
pex_binary
, the gist is: 1. ensure the
python_source
target is in the
dependencies
(e.g. via dep inference rule) 2. in your rule to build stuff, use
SourceFiles
or
PythonSourceFiles
to get the Python file + all its deps present 3. Also use
SecondaryOwnerMixin
for nice semantics
a
why can I do tgt.get(SourcesField) and not tgt.get(PythonSourceField)
h
what do you mean?
a
I think I resolved it. But tg.tget(PythonSourceField) errors with
you must define sources on the target
how do I strip the source root from a filepath?
ah there it is! SourceRootRequest
h
or
StrippedSourceFiles