Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat PythonTarget dependencies on Resources targets appropriately. #4249

Merged
merged 1 commit into from Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/python/pants/backend/python/targets/python_target.py
Expand Up @@ -124,21 +124,12 @@ def compatibility(self):

@property
def resources(self):
resource_targets = []

if self._resource_target_specs:
def get_target(spec):
address = Address.parse(spec, relative_to=self.address.spec_path)
tgt = self._build_graph.get_target(address)
if tgt is None:
raise TargetDefinitionException(self, 'No such resource target: {}'.format(address))
return tgt
resource_targets.extend(get_target(spec) for spec in self._resource_target_specs)

if self._synthetic_resources_target:
resource_targets.append(self._synthetic_resources_target)

return resource_targets
# Note: Will correctly find:
# - Regular dependencies on Resources targets.
# - Resources targets specified via resource_targets=.
# - The synthetic Resources target created from the resources= fileset.
# Because these are all in the traversable_dependency_specs.
return [dep for dep in self.dependencies if isinstance(dep, Resources)]

def walk(self, work, predicate=None):
super(PythonTarget, self).walk(work, predicate)
Expand Down
12 changes: 12 additions & 0 deletions tests/python/pants_test/targets/test_python_target.py
Expand Up @@ -79,3 +79,15 @@ def test_resource_targets(self):
expected_resource_path='res/data.txt',
expected_resource_contents='1/137')
self.assertIs(res, resource_dep)

def test_resource_dependencies(self):
self.create_file('res/data.txt', contents='1/137')
res = self.make_target(spec='res:resources', target_type=Resources, sources=['data.txt'])
lib = self.make_target(spec='test:lib',
target_type=PythonLibrary,
sources=[],
dependencies=[res])
resource_dep = self.assert_single_resource_dep(lib,
expected_resource_path='res/data.txt',
expected_resource_contents='1/137')
self.assertIs(res, resource_dep)