Skip to content

Commit abae83b

Browse files
grievejiameta-codesync[bot]
authored andcommitted
Connect cxx_python_extension generated type stub targets to the target graph
Summary: Following up on D88693627, this diff adds `cxx_python_extension` rules to the target graph, treating it in the same way as a Python library target with no sources -- there are presented in the target graph just to be able to provide the deps edge Reviewed By: connernilsen Differential Revision: D88773199 fbshipit-source-id: c8355a7036f01ebe5ca4cd3e898d4fa39068f38a
1 parent 9976f41 commit abae83b

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

prelude/python/sourcedb/pyrefly.bxl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ def _handle_alias(
112112
else:
113113
fail("Alias has no actual target".format(target.label))
114114

115+
def _handle_python_extension(
116+
entry: dict,
117+
attrs: bxl.LazyAttrs,
118+
fs: bxl.Filesystem,
119+
target: bxl.ConfiguredTargetNode,
120+
known_targets: dict[TargetLabel, bxl.ConfiguredTargetNode]) -> None:
121+
_set_entry_common_fields(entry, attrs, fs, target, known_targets)
122+
115123
def _handle_genrule(
116124
entry: dict,
117125
attrs: bxl.LazyAttrs,
@@ -289,7 +297,6 @@ def _main(ctx: bxl.Context) -> None:
289297
if x.rule_type not in (
290298
"forward",
291299
"prelude//rules.bzl:command_alias",
292-
"prelude//rules.bzl:cxx_python_extension",
293300
"prelude//rules.bzl:export_file",
294301
"prelude//rules.bzl:filegroup",
295302
) and x.label.name != "restricted_bin"
@@ -305,6 +312,8 @@ def _main(ctx: bxl.Context) -> None:
305312

306313
if x.rule_type == "prelude//rules.bzl:alias":
307314
_handle_alias(entry, attrs, x)
315+
elif x.rule_type == "prelude//rules.bzl:cxx_python_extension":
316+
_handle_python_extension(entry, attrs, fs, x, known_targets)
308317
elif x.rule_type == "prelude//rules.bzl:genrule":
309318
_handle_genrule(entry, attrs, fs, x, known_targets, to_remove, to_build, to_insert, genrule_to_insert)
310319
elif x.rule_type == "prelude//rules.bzl:python_library":

prelude/python/sourcedb/tests/pyrefly_expected.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"prelude//python/sourcedb/tests/test_files:main": {
6262
"buildfile_path": "prelude/python/sourcedb/tests/test_files/BUCK",
6363
"deps": [
64-
"prelude//python/sourcedb/tests/test_files:lib"
64+
"prelude//python/sourcedb/tests/test_files:lib",
65+
"prelude//python/sourcedb/tests/test_files:my_extension_lib"
6566
],
6667
"python_platform": "linux",
6768
"python_version": "3.12",
@@ -72,6 +73,42 @@
7273
]
7374
}
7475
},
76+
"prelude//python/sourcedb/tests/test_files:my_extension": {
77+
"buildfile_path": "prelude/python/sourcedb/tests/test_files/BUCK",
78+
"deps": [
79+
"prelude//python/sourcedb/tests/test_files:my_extension_stub"
80+
],
81+
"python_platform": "linux",
82+
"python_version": "3.12",
83+
"relative_to": null,
84+
"srcs": {}
85+
},
86+
"prelude//python/sourcedb/tests/test_files:my_extension_lib": {
87+
"buildfile_path": "prelude/python/sourcedb/tests/test_files/BUCK",
88+
"deps": [
89+
"prelude//python/sourcedb/tests/test_files:my_extension"
90+
],
91+
"python_platform": "linux",
92+
"python_version": "3.12",
93+
"relative_to": null,
94+
"srcs": {
95+
"python.sourcedb.tests.test_files.my_extension": [
96+
"prelude/python/sourcedb/tests/test_files/my_extension.py"
97+
]
98+
}
99+
},
100+
"prelude//python/sourcedb/tests/test_files:my_extension_stub": {
101+
"buildfile_path": "prelude/python/sourcedb/tests/test_files/BUCK",
102+
"deps": [],
103+
"python_platform": "linux",
104+
"python_version": "3.12",
105+
"relative_to": null,
106+
"srcs": {
107+
"python.sourcedb.tests.test_files.my_extension": [
108+
"prelude/python/sourcedb/tests/test_files/my_extension.pyi"
109+
]
110+
}
111+
},
75112
"prelude//python/sourcedb/tests/test_files:subdir": {
76113
"buildfile_path": "prelude/python/sourcedb/tests/test_files/BUCK",
77114
"deps": [

prelude/python/sourcedb/tests/test_files/BUCK

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ source_listing()
77
python_library(
88
name = "main",
99
srcs = ["main.py"],
10-
deps = [":lib"],
10+
deps = [
11+
":lib",
12+
":my_extension_lib",
13+
],
1114
)
1215

1316
python_library(
@@ -61,3 +64,21 @@ genrule(
6164
out = "generated_file.pyi",
6265
cmd = "touch ${OUT}",
6366
)
67+
68+
python_library(
69+
name = "my_extension_stub",
70+
srcs = ["my_extension.pyi"],
71+
)
72+
73+
cxx_python_extension(
74+
name = "my_extension",
75+
srcs = ["my_extension.cpp"],
76+
base_module = "my_extension",
77+
deps = [":my_extension_stub"],
78+
)
79+
80+
python_library(
81+
name = "my_extension_lib",
82+
srcs = ["my_extension.py"],
83+
deps = [":my_extension"],
84+
)

prelude/python/sourcedb/tests/test_files/my_extension.cpp

Whitespace-only changes.

prelude/python/sourcedb/tests/test_files/my_extension.py

Whitespace-only changes.

prelude/python/sourcedb/tests/test_files/my_extension.pyi

Whitespace-only changes.

0 commit comments

Comments
 (0)