Skip to content

Commit

Permalink
Improve deprecations (#6097)
Browse files Browse the repository at this point in the history
* Only warn about the 'source' argument if it's actually being paid
  attention to by the Target, rather than if it's being ignored by the
  target.
* Use an eager empty fileset, rather than a lazy one, if sources is an
  empty collection literal in a BUILD file - this means we don't get a
  deprecation in this case, as we shouldn't.
  • Loading branch information
illicitonion authored and cosmicexplorer committed Jul 11, 2018
1 parent 0390517 commit 450de70
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/python/pants/build_graph/target.py
Expand Up @@ -112,16 +112,8 @@ def check_unknown(self, target, kwargs, payload):
"""
ignore_params = set((self.get_options().ignored or {}).get(target.type_alias, ()))
unknown_args = {arg: value for arg, value in kwargs.items() if arg not in ignore_params}
if 'source' in unknown_args:
if 'sources' in payload.as_dict():
deprecated_conditional(
lambda: True,
'1.10.0.dev0',
('The source argument in targets is deprecated - it gets automatically promoted to '
'sources. Target {} should just use a sources argument. No BUILD files need changing. '
'The source argument will stop being populated -').format(target.type_alias),
)
unknown_args.pop('source')
if 'source' in unknown_args and 'sources' in payload.as_dict():
unknown_args.pop('source')
if 'sources' in unknown_args:
if 'sources' in payload.as_dict():
deprecated_conditional(
Expand Down Expand Up @@ -890,16 +882,19 @@ def create_sources_field(self, sources, sources_rel_path, key_arg=None):
else:
sources = FilesetWithSpec.empty(sources_rel_path)
elif isinstance(sources, (set, list, tuple)):
# Received a literal sources list: convert to a FilesetWithSpec via Files.
deprecated_conditional(
lambda: True,
'1.10.0.dev0',
('Passing collections as the value of the sources argument to create_sources_field is '
'deprecated, and now takes a slow path. Instead, class {} should have its sources '
'argument populated by the engine, either by using the standard parsing pipeline, or by '
'requesting a SourcesField product from the v2 engine.').format(self.__class__.__name__)
)
sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
if sources:
# Received a literal sources list: convert to a FilesetWithSpec via Files.
deprecated_conditional(
lambda: True,
'1.10.0.dev0',
('Passing collections as the value of the sources argument to create_sources_field is '
'deprecated, and now takes a slow path. Instead, class {} should have its sources '
'argument populated by the engine, either by using the standard parsing pipeline, or by '
'requesting a SourcesField product from the v2 engine.').format(self.__class__.__name__)
)
sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
else:
sources = FilesetWithSpec.empty(sources_rel_path)
elif not isinstance(sources, FilesetWithSpec):
key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
Expand Down

0 comments on commit 450de70

Please sign in to comment.