Skip to content

Commit cc48fab

Browse files
Matt D'Souzafacebook-github-bot
authored andcommitted
parse srcs field in python_binary targets
Summary: It turns out that `python_binary` targets can specify `srcs` -- we should also handle this case. Reviewed By: grievejia Differential Revision: D14752547 fbshipit-source-id: 7bb75a11eb02d069f2b1b1e6dd22841ec0646a44
1 parent da1163f commit cc48fab

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

client/buck_project_builder/parser/build_target.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,24 @@ def parse(call: ast.Call, build_file_directory: str) -> "NonPythonTarget":
7777

7878

7979
class PythonBinary(BuildTarget):
80+
def __init__(
81+
self,
82+
build_file_directory: str,
83+
name: str,
84+
dependencies: List[str],
85+
sources: Optional[List[str]] = None,
86+
) -> None:
87+
super(PythonBinary, self).__init__(build_file_directory, name, dependencies)
88+
self.sources = sources or [] # type: List[str]
89+
8090
def rule_name(self) -> str:
8191
return "python_binary"
8292

8393
@staticmethod
8494
def parse(call: ast.Call, build_file_directory: str) -> "PythonBinary":
8595
base = BuildTarget.parse_base_information(call, build_file_directory)
86-
return PythonBinary(build_file_directory, base.name, base.dependencies)
96+
sources = _get_sources(base.keywords.get("srcs"))
97+
return PythonBinary(build_file_directory, base.name, base.dependencies, sources)
8798

8899

89100
class PythonLibrary(BuildTarget):

client/buck_project_builder/parser/tests/build_target_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def _get_call(tree: ast.AST) -> ast.Call:
3535
PYTHON_BINARY_TARGET_2 = """
3636
python_binary(
3737
name = "binary_target_2",
38-
deps = []
38+
deps = [],
39+
srcs = ["a.py"],
3940
)
4041
"""
4142

@@ -96,13 +97,15 @@ def test_python_binary(self):
9697
target.dependencies,
9798
["//some/project:another_target", "//some/other:target"],
9899
)
100+
self.assertListEqual(target.sources, [])
99101

100102
tree = ast.parse(PYTHON_BINARY_TARGET_2)
101103
call = _get_call(tree)
102104
target = PythonBinary.parse(call, "some/project")
103105
self.assertEqual(target.target, "//some/project:binary_target_2")
104106
self.assertEqual(target.name, "binary_target_2")
105107
self.assertListEqual(target.dependencies, [])
108+
self.assertListEqual(target.sources, ["a.py"])
106109

107110
tree = ast.parse(PYTHON_BINARY_TARGET_3)
108111
call = _get_call(tree)

0 commit comments

Comments
 (0)