Skip to content

Commit 4e95a60

Browse files
authored
feat: make pypi-generated targets include pyi files (#2545)
Make pypi-generated targets set `pyi_srcs` to include `*.pyi` files. Work towards #2537
1 parent 50b4f87 commit 4e95a60

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ Unreleased changes template.
8888
`python_version` attribute is still used to specify the Python version.
8989
* (pypi) Updated versions of packages: `pip` to 24.3.1 and
9090
`packaging` to 24.2.
91+
* (pypi) For pypi-generated targets, `*.pyi` files are included in the
92+
`pyi_srcs` attribute instead of the `data` attribute.
9193

9294
{#v1-1-0-deprecations}
9395
#### Deprecations
@@ -141,6 +143,7 @@ Unreleased changes template.
141143
only dependencies added. See {obj}`py_library.pyi_srcs` and
142144
`py_library.pyi_deps` (and the same named attributes for `py_binary` and
143145
`py_test`).
146+
* (pypi) pypi-generated targets set `pyi_srcs` to include `*.pyi` files.
144147
* (providers) {obj}`PyInfo` has new fields to aid static analysis tools:
145148
{obj}`direct_original_sources`, {obj}`direct_pyi_files`,
146149
{obj}`transitive_original_sources`, {obj}`transitive_pyi_files`.

python/private/pypi/whl_library_targets.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def whl_library_targets(
226226
"**/*.py",
227227
"**/*.pyc",
228228
"**/*.pyc.*", # During pyc creation, temp files named *.pyc.NNNN are created
229+
"**/*.pyi",
229230
# RECORD is known to contain sha256 checksums of files which might include the checksums
230231
# of generated files produced when wheels are installed. The file is ignored to avoid
231232
# Bazel caching issues.
@@ -244,6 +245,10 @@ def whl_library_targets(
244245
# pure-Python code, e.g. pymssql, which is written in Cython.
245246
allow_empty = True,
246247
),
248+
pyi_srcs = native.glob(
249+
["site-packages/**/*.pyi"],
250+
allow_empty = True,
251+
),
247252
data = data + native.glob(
248253
["site-packages/**/*"],
249254
exclude = _data_exclude,

tests/pypi/whl_library_targets/whl_library_targets_tests.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,14 @@ def _test_whl_and_library_deps(env):
245245
exclude = [],
246246
allow_empty = True,
247247
),
248+
"pyi_srcs": _glob(["site-packages/**/*.pyi"], allow_empty = True),
248249
"data": [] + _glob(
249250
["site-packages/**/*"],
250251
exclude = [
251252
"**/*.py",
252253
"**/*.pyc",
253254
"**/*.pyc.*",
255+
"**/*.pyi",
254256
"**/*.dist-info/RECORD",
255257
] + glob_excludes.version_dependent_exclusions(),
256258
),
@@ -316,12 +318,14 @@ def _test_group(env):
316318
{
317319
"name": "_pkg",
318320
"srcs": _glob(["site-packages/**/*.py"], exclude = [], allow_empty = True),
321+
"pyi_srcs": _glob(["site-packages/**/*.pyi"], allow_empty = True),
319322
"data": [] + _glob(
320323
["site-packages/**/*"],
321324
exclude = [
322325
"**/*.py",
323326
"**/*.pyc",
324327
"**/*.pyc.*",
328+
"**/*.pyi",
325329
"**/*.dist-info/RECORD",
326330
] + glob_excludes.version_dependent_exclusions(),
327331
),

0 commit comments

Comments
 (0)