Skip to content

Commit

Permalink
feat: make pypi-generated targets include pyi files (#2545)
Browse files Browse the repository at this point in the history
Make pypi-generated targets set `pyi_srcs` to include `*.pyi` files.

Work towards #2537
  • Loading branch information
rickeylev authored Jan 8, 2025
1 parent 50b4f87 commit 4e95a60
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Unreleased changes template.
`python_version` attribute is still used to specify the Python version.
* (pypi) Updated versions of packages: `pip` to 24.3.1 and
`packaging` to 24.2.
* (pypi) For pypi-generated targets, `*.pyi` files are included in the
`pyi_srcs` attribute instead of the `data` attribute.

{#v1-1-0-deprecations}
#### Deprecations
Expand Down Expand Up @@ -141,6 +143,7 @@ Unreleased changes template.
only dependencies added. See {obj}`py_library.pyi_srcs` and
`py_library.pyi_deps` (and the same named attributes for `py_binary` and
`py_test`).
* (pypi) pypi-generated targets set `pyi_srcs` to include `*.pyi` files.
* (providers) {obj}`PyInfo` has new fields to aid static analysis tools:
{obj}`direct_original_sources`, {obj}`direct_pyi_files`,
{obj}`transitive_original_sources`, {obj}`transitive_pyi_files`.
Expand Down
5 changes: 5 additions & 0 deletions python/private/pypi/whl_library_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def whl_library_targets(
"**/*.py",
"**/*.pyc",
"**/*.pyc.*", # During pyc creation, temp files named *.pyc.NNNN are created
"**/*.pyi",
# RECORD is known to contain sha256 checksums of files which might include the checksums
# of generated files produced when wheels are installed. The file is ignored to avoid
# Bazel caching issues.
Expand All @@ -244,6 +245,10 @@ def whl_library_targets(
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
pyi_srcs = native.glob(
["site-packages/**/*.pyi"],
allow_empty = True,
),
data = data + native.glob(
["site-packages/**/*"],
exclude = _data_exclude,
Expand Down
4 changes: 4 additions & 0 deletions tests/pypi/whl_library_targets/whl_library_targets_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ def _test_whl_and_library_deps(env):
exclude = [],
allow_empty = True,
),
"pyi_srcs": _glob(["site-packages/**/*.pyi"], allow_empty = True),
"data": [] + _glob(
["site-packages/**/*"],
exclude = [
"**/*.py",
"**/*.pyc",
"**/*.pyc.*",
"**/*.pyi",
"**/*.dist-info/RECORD",
] + glob_excludes.version_dependent_exclusions(),
),
Expand Down Expand Up @@ -316,12 +318,14 @@ def _test_group(env):
{
"name": "_pkg",
"srcs": _glob(["site-packages/**/*.py"], exclude = [], allow_empty = True),
"pyi_srcs": _glob(["site-packages/**/*.pyi"], allow_empty = True),
"data": [] + _glob(
["site-packages/**/*"],
exclude = [
"**/*.py",
"**/*.pyc",
"**/*.pyc.*",
"**/*.pyi",
"**/*.dist-info/RECORD",
] + glob_excludes.version_dependent_exclusions(),
),
Expand Down

0 comments on commit 4e95a60

Please sign in to comment.