https://pantsbuild.org/ logo
#development
Title
# development
c

curved-television-6568

01/10/2022, 1:36 PM
I find this a bit unfortunate, that field validation is done lazily… 🧵
Copy code
$ ./pants package ::
14:35:21.61 [ERROR] 1 Exception encountered:

  InvalidFieldException: Unrecognized field `repositories=['@pypi']` in target src/underpants:dist. Valid fields for the target type `python_distribution`: ['dependencies', 'description', 'entry_points', 'generate_setup', 'provides', 'sdist', 'sdist_config_settings', 'tags', 'wheel', 'wheel_config_settings'].

$ ./pants publish ::
$
That is, the
publish
goal was a no-op, where as package correctly informed me there’s a configuration issue (missing the
pants.backend.experimental.python
backend)… even update-build-files fails to notice this issue… cc @hundreds-father-404 any thoughts how to best address this?
h

hundreds-father-404

01/10/2022, 1:49 PM
Where is this error being created? Most validation happens when creating Target, which is pretty eager. Even
list
should do the trick. But it's possible to raise InvalidFieldExceptiob inside a rule rather than via target API, which is lazy
c

curved-television-6568

01/10/2022, 2:04 PM
The stacktrace for
list
is:
Copy code
Engine traceback:
  in select
  in pants.backend.project_info.list_targets.list_targets
  in pants.engine.internals.graph.resolve_addresses_from_specs
  in pants.engine.internals.build_files.addresses_from_address_specs
  in pants.engine.internals.graph.resolve_unexpanded_targets
  in pants.engine.internals.graph.resolve_target (src/underpants:dist)
Traceback (most recent call last):
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.7zfHJF/install/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 705, in native_engine_generator_send
    res = func.send(arg)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.7zfHJF/install/lib/python3.9/site-packages/pants/engine/internals/graph.py", line 191, in resolve_target
    target = target_type(target_adaptor.kwargs, address, union_membership)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.7zfHJF/install/lib/python3.9/site-packages/pants/util/meta.py", line 188, in new_init
    prev_init(self, *args, **kwargs)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.7zfHJF/install/lib/python3.9/site-packages/pants/engine/target.py", line 339, in __init__
    self.field_values = self._calculate_field_values(unhydrated_values, address)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.7zfHJF/install/lib/python3.9/site-packages/pants/engine/target.py", line 356, in _calculate_field_values
    raise InvalidFieldException(
pants.engine.target.InvalidFieldException: Unrecognized field `repositories=['@pypi']` in target src/underpants:dist. Valid fields for the target type `python_distribution`: ['dependencies', 'description', 'entry_points', 'generate_setup', 'provides', 'sdist', 'sdist_config_settings', 'tags', 'wheel', 'wheel_config_settings'].
And similar for
package
The issue then would be that
publish
doesn’t create the target, as it’s not considered as the backend that would consider it is not active..
Perhaps such a corner case, that it’s not really worth exploring..
h

hundreds-father-404

01/13/2022, 6:01 PM
Weird that
publish
doesn't create the
Target
, given that it calls
package
under-the-hood?
c

curved-television-6568

01/13/2022, 7:31 PM
Well, no, I guess it isn’t, as it’ll will only call
package
for targets that also has a
publish
field set. And with that backend missing, there isn’t one for
python_distribution
h

hundreds-father-404

01/13/2022, 7:32 PM
Ah ha, cool. Then this is all expected 🙂
1
c

curved-television-6568

01/13/2022, 7:34 PM
So the “unfortunate” bit is perhaps more that there isn’t a “validate all my targets” goal.. you only get that as a side effect of using your targets.
But, now that all this is clearer to me, it’s less and less important to do anything about (for me), but could potentially be confusing for new/unexperienced users..
h

hundreds-father-404

01/13/2022, 7:36 PM
that there isn’t a “validate all my targets” goal.
The fastest way to do that is
./pants list :: > /dev/null
💯 1
c

curved-television-6568

01/13/2022, 7:37 PM
Right!
Copy code
[cli.alias]
validate-targets = "list ::"
but.. there’s no redirection support there…. 🤔
h

hundreds-father-404

01/13/2022, 7:42 PM
You could easily create a plugin goal based on
list_targets.py
if you were motivated enough. Don't have it write to
Console
. I think it literally would do nothing more than request
Targets
in the rule signature
Actually you could have the goal request
AllTargets
so that you don't need to specify CLI specs
c

curved-television-6568

01/13/2022, 8:21 PM
Haha, yeah, true 🙂
Not 100 sure if there’s a big enough motivation for implementing it, tho.. ?
h

hundreds-father-404

01/13/2022, 8:23 PM
Depends how useful it is to your org. I personally would instead use
./pants list :: > /dev/null  # Validate all targets
in my CI and wouldn't even bother with creating a
[cli].alias
because I wouldn't expect users to be running it daily
c

curved-television-6568

01/13/2022, 8:34 PM
no true, and I wouldn’t be running this in CI, oh wait, maybe that’s a neat idea actually, to pre-emptively check that all targets are well defined.
but indeed, I’d stick with
list
and a comment, then too…
my issue I ran into was during local development, and that I missed that the publish goal I was after was in an experimental backend I hadn’t yet added…
tripped me up for a minute 😛