Do we want to elevate a mechanism for required fie...
# development
h
Do we want to elevate a mechanism for required fields? Concrete example:
alias()
must have the field
target
defined. We could achieve this ad hoc, but do we anticipate this being a useful mechanism? For example, if we elevate it, then we can do nice things like say
required
in the output of
./v2 target-types
a
Yessssssssssssss
Also there are useful predicates I’d really like to apply
e.g. “Anything in the deps of a python library must be something pythony - if you depend on a scala_library we will error” because right now we just ignore them
👍 1
Also libraries which depend on binaries! Bad!
👍 1
h
See https://github.com/pantsbuild/pants/pull/9392 for required fields 🙂 We already enforce that Python target types must end in
.py
, but that’s an interesting idea to generalize the mechanism! That’s very easy to do!
Also libraries which depend on binaries! Bad!
I’m not sure what this will look like yet because we still have to figure out hydration of
Dependencies
. (We start out with
List[Address]
. I think hydration means getting a
Sequence[Target]
for the direct dependencies). We could add post-hydration validation that no target types have the field
BinarySources
a
We already enforce that Python target types must end in
.py
,
I think we enforce that for source files, but not dependencies. I think I can write:
Copy code
python_library(dependencies = [":some_java_library"])
java_library(name = "some_java_library"])
And everything will be fine and the dep will just be ignored, which is kind of bad
h
Oh, correct. I see what you mean. That would be a great mechanism! NB that you need to make exceptions for
Files
and
Resources
, but that’s achievable. It gets a little awkward that you can’t say
assert isinstance(tgt, Files)
because that breaks custom target types like
CustomFiles
, given the field-driven nature of the API. But, we could do
assert tgt.has_field(FilesSources)
as a proxy to know it’s a Files target
a
An interesting problem to design, for sure 🙂
❤️ 1