-
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow pants to select targets by file(s) (#5930)
Fixes #5912 Problem There should be an option to accept literal files, and then select the targets that own those files. Similar to how the --changed-parent triggers a diff and the targets are selected based on the result. The proposed syntax is something like: $ ./pants \ --owner-of=this/is/a/file/name.java \ # flag triggers owner lookup --owner-of=this/is/a/file/name/too.py \ # flag triggers owner lookup compile # goal Solution I've created a global option --owner-of= that takes a list of files as a parameter, and created a OwnerCalculator class to handle the logic similar to how ChangeCalculator works with the --changed-* subsystem. Result Now users will be able to run goals on files without needing to know which target owns those files. Also, the list-owners goal can be deprecated in favor of --owner-of=some/file.py list It is important to note that multiple target selection methods are not allowed, so it fails when more than one of --changed-*, --owner-of, or target specs are supplied. e.g. this fails: $ ./pants \ --owner-of=this/is/a/file/name.java \ # flag triggers owner lookup --owner-of=this/is/a/file/name/too.py \ # flag triggers owner lookup compile <another target>
- Loading branch information
Showing
6 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/python/pants_test/engine/legacy/test_owners_integration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
from pants_test.pants_run_integration_test import PantsRunIntegrationTest | ||
|
||
|
||
class ListOwnersIntegrationTest(PantsRunIntegrationTest): | ||
def test_owner_of_success(self): | ||
pants_run = self.do_command('--owner-of=testprojects/tests/python/pants/dummies/test_pass.py', | ||
'list', | ||
success=True) | ||
self.assertEquals( | ||
pants_run.stdout_data.strip(), | ||
'testprojects/tests/python/pants/dummies:passing_target' | ||
) | ||
|
||
def test_owner_list_not_owned(self): | ||
pants_run = self.do_command('--owner-of=testprojects/tests/python/pants/dummies/test_nonexistent.py', | ||
'list', | ||
success=True) | ||
self.assertIn('WARNING: No targets were matched in', pants_run.stderr_data) | ||
|
||
def test_owner_list_two_target_specs(self): | ||
# Test that any of these combinations fail with the same error message. | ||
expected_error = ('Multiple target selection methods provided. Please use only one of ' | ||
'--changed-*, --owner-of, or target specs') | ||
pants_run_1 = self.do_command('--owner-of=testprojects/tests/python/pants/dummies/test_pass.py', | ||
'--changed-parent=master', | ||
'list', | ||
success=False) | ||
self.assertIn(expected_error, pants_run_1.stderr_data) | ||
|
||
pants_run_2 = self.do_command('--owner-of=testprojects/tests/python/pants/dummies/test_pass.py', | ||
'list', | ||
'testprojects/tests/python/pants/dummies:passing_target', | ||
success=False) | ||
self.assertIn(expected_error, pants_run_2.stderr_data) | ||
|
||
pants_run_3 = self.do_command('--changed-parent=master', | ||
'list', | ||
'testprojects/tests/python/pants/dummies:passing_target', | ||
success=False) | ||
self.assertIn(expected_error, pants_run_3.stderr_data) |