Skip to content

Commit e0affec

Browse files
committed
finish impl
1 parent 31e16ee commit e0affec

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

python/private/py_library.bzl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,22 @@ def _get_venv_symlinks(ctx, dist_info_metadata):
290290
venv_path = dist_info_dir,
291291
))
292292

293-
for src in ctx.files.srcs:
294-
if src.extension not in PYTHON_FILE_EXTENSIONS:
295-
continue
293+
for src in ctx.files.srcs + ctx.files.data:
296294
path = _repo_relative_short_path(src.short_path)
297295
if not path.startswith(site_packages_root):
298296
continue
299297
path = path.removeprefix(site_packages_root)
300298
dir_name, _, filename = path.rpartition("/")
301299

302-
if dir_name and filename.startswith("__init__."):
300+
if src.extension not in PYTHON_FILE_EXTENSIONS:
301+
if dir_name.endswith(".dist-info"):
302+
# we have already handled the stuff
303+
pass
304+
elif dir_name:
305+
# TODO @aignas 2025-05-30: is this the right way?
306+
dirs_with_init[dir_name] = None
307+
repo_runfiles_dirname = runfiles_root_path(ctx, src.short_path).partition("/")[0]
308+
elif dir_name and filename.startswith("__init__."):
303309
dirs_with_init[dir_name] = None
304310
repo_runfiles_dirname = runfiles_root_path(ctx, src.short_path).partition("/")[0]
305311
elif not dir_name:

tests/modules/other/simple_v2/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ py_library(
1111
),
1212
experimental_venvs_site_packages = "@rules_python//python/config_settings:venvs_site_packages",
1313
imports = [package_name() + "/site-packages"],
14+
pyi_srcs = glob(["**/*.pyi"]),
1415
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Intentionally empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Intentionally empty

tests/venv_site_packages_libs/bin.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
import os
32
import sys
43
import unittest
54
from pathlib import Path
@@ -30,13 +29,37 @@ def test_imported_from_venv(self):
3029
self.assert_imported_from_venv("single_file")
3130
self.assert_imported_from_venv("simple")
3231

33-
def test_distinfo_is_overriden(self):
32+
def test_pyi_is_included(self):
33+
self.assert_imported_from_venv("simple")
34+
module = importlib.import_module("simple")
35+
module_path = Path(module.__file__)
36+
37+
# this has been not included through data but through `pyi_srcs`
38+
pyi_files = [p.name for p in module_path.parent.glob("*.pyi")]
39+
self.assertIn("__init__.pyi", pyi_files)
40+
41+
def test_data_is_included(self):
42+
self.assert_imported_from_venv("simple")
43+
module = importlib.import_module("simple")
44+
module_path = Path(module.__file__)
45+
46+
site_packages = module_path.parent.parent
47+
48+
# Ensure that packages from simple v1 are not present
49+
files = [p.name for p in site_packages.glob("*")]
50+
self.assertIn("simple.libs", files)
51+
52+
def test_override_pkg(self):
3453
self.assert_imported_from_venv("simple")
3554
module = importlib.import_module("simple")
3655
self.assertEqual(
3756
"2.0.0",
3857
module.__version__,
3958
)
59+
60+
def test_dirs_from_replaced_package_are_not_present(self):
61+
self.assert_imported_from_venv("simple")
62+
module = importlib.import_module("simple")
4063
module_path = Path(module.__file__)
4164

4265
site_packages = module_path.parent.parent
@@ -48,10 +71,7 @@ def test_distinfo_is_overriden(self):
4871

4972
# Ensure that packages from simple v1 are not present
5073
files = [p.name for p in site_packages.glob("*")]
51-
self.assertNotIn(
52-
"simple_extras",
53-
files,
54-
)
74+
self.assertNotIn("simple_extras", files)
5575

5676

5777
if __name__ == "__main__":

0 commit comments

Comments
 (0)