Skip to content

Commit ce0bb1b

Browse files
committed
fix(venv): include pth files at the root of the site-packages folder
Before this PR we would not include `pth` files at the root of the `site-packages` folder, but we would include if they are further down the tree. Fixes #3339 Fixes #2071
1 parent f84640b commit ce0bb1b

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ END_UNRELEASED_TEMPLATE
105105
* (venvs) {obj}`--venvs_site_packages=yes` works for packages that dynamically
106106
link to shared libraries
107107
([#3228](https://github.com/bazel-contrib/rules_python/issues/3228)).
108+
* (venvs) {obj}`--venvs_site_packages=yes` includes `pth` files at the root of the
109+
site-packages folder
110+
([#3339](https://github.com/bazel-contrib/rules_python/issues/3339)).
108111
* (uv) {obj}`//python/uv:lock.bzl%lock` now works with a local platform
109112
runtime.
110113
* (toolchains) WORKSPACE builds now correctly register musl and freethreaded

python/private/common.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ PYTHON_FILE_EXTENSIONS = [
3636
"dylib", # Python C modules, Mac specific
3737
"py",
3838
"pyc",
39+
"pth", # import 'pth' files
3940
"pyi",
4041
"so", # Python C modules, usually Linux
4142
]

python/private/venv_runfiles.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ def get_venv_symlinks(ctx, files, package, version_str, site_packages_root):
290290
entry = VenvSymlinkEntry(
291291
kind = VenvSymlinkKind.LIB,
292292
link_to_path = paths.join(runfiles_dir_name, site_packages_root, filename),
293+
link_to_file = src,
293294
package = package,
294295
version = version_str,
295-
venv_path = filename,
296+
venv_path = path,
296297
files = depset([src]),
297298
)
298299
venv_symlinks.append(entry)

tests/venv_site_packages_libs/app_files_building/app_files_building_tests.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,33 @@ def _test_empty_and_trivial_inputs_impl(env, _):
204204
VenvSymlinkKind.LIB: {"a": "+pypi_a/site-packages/a"},
205205
})
206206

207+
def _test_top_level_symlinks(name):
208+
analysis_test(
209+
name = name,
210+
impl = _test_top_level_symlinks_impl,
211+
target = "//python:none",
212+
)
213+
214+
_tests.append(_test_top_level_symlinks)
215+
216+
def _test_top_level_symlinks_impl(env, _):
217+
# Test with empty list of entries
218+
actual = build_link_map(_ctx(), [])
219+
env.expect.that_dict(actual).contains_exactly({})
220+
221+
# Test with an entry with no files
222+
entries = [
223+
_entry("a.py", "+pypi_a/site-packages", ["a.py"]),
224+
_entry("a.pth", "+pypi_a/site-packages", ["a.pth"]),
225+
]
226+
actual = build_link_map(_ctx(), entries)
227+
env.expect.that_dict(actual).contains_exactly({
228+
VenvSymlinkKind.LIB: {
229+
"a.pth": "+pypi_a/site-packages",
230+
"a.py": "+pypi_a/site-packages",
231+
},
232+
})
233+
207234
def _test_multiple_venv_symlink_kinds(name):
208235
analysis_test(
209236
name = name,

0 commit comments

Comments
 (0)