11""
22
3- load ("@bazel_skylib//lib:paths.bzl" , "paths" )
43load ("@rules_testing//lib:analysis_test.bzl" , "analysis_test" )
54load ("@rules_testing//lib:test_suite.bzl" , "test_suite" )
65load ("//python/private:py_info.bzl" , "VenvSymlinkEntry" , "VenvSymlinkKind" ) # buildifier: disable=bzl-visibility
@@ -58,34 +57,16 @@ def _venv_symlinks_from_entries(entries):
5857 ))
5958 return sorted (result , key = lambda e : (e .link_to_path , e .venv_path ))
6059
61- def _entry (venv_path , link_to_path , files = [] , ** kwargs ):
60+ def _entry (venv_path , link_to_path , files , ** kwargs ):
6261 kwargs .setdefault ("kind" , VenvSymlinkKind .LIB )
6362 kwargs .setdefault ("package" , None )
6463 kwargs .setdefault ("version" , None )
65-
66- def short_pathify (path ):
67- path = paths .join (link_to_path , path )
68-
69- # In tests, `../` is used to step out of the link_to_path scope.
70- path = paths .normalize (path )
71-
72- # Treat paths starting with "+" as external references. This matches
73- # how bzlmod names things.
74- if link_to_path .startswith ("+" ):
75- # File.short_path to external repos have `../` prefixed
76- path = paths .join ("../" , path )
77- else :
78- # File.short_path in main repo is main-repo relative
79- _ , _ , path = path .partition ("/" )
80- return path
64+ kwargs .setdefault ("link_to_file" , None )
8165
8266 return VenvSymlinkEntry (
8367 venv_path = venv_path ,
8468 link_to_path = link_to_path ,
85- files = depset ([
86- _file (short_pathify (f ))
87- for f in files
88- ]),
69+ files = depset (files ),
8970 ** kwargs
9071 )
9172
@@ -100,15 +81,34 @@ _tests.append(_test_conflict_merging)
10081
10182def _test_conflict_merging_impl (env , _ ):
10283 entries = [
103- _entry ("a" , "+pypi_a/site-packages/a" , ["a.txt" ]),
104- _entry ("a-1.0.dist-info" , "+pypi_a/site-packages/a-1.0.dist-info" , ["METADATA" ]),
105- _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , ["b.txt" ]),
106- _entry ("x" , "_main/src/x" , ["x.txt" ]),
107- _entry ("x/p" , "_main/src-dev/x/p" , ["p.txt" ]),
108- _entry ("duplicate" , "+dupe_a/site-packages/duplicate" , ["d.py" ]),
109- # This entry also provides a/x.py, but since the "a" entry is shorter
110- # and comes first, its version of x.py should win.
111- _entry ("duplicate" , "+dupe_b/site-packages/duplicate" , ["d.py" ]),
84+ _entry ("a" , "+pypi_a/site-packages/a" , [
85+ _file ("../+pypi_a/site-packages/a/a.txt" ),
86+ ]),
87+ _entry ("a-1.0.dist-info" , "+pypi_a/site-packages/a-1.0.dist-info" , [
88+ _file ("../+pypi_a/site-packages/a-1.0.dist-info/METADATA" ),
89+ ]),
90+ _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , [
91+ _file ("../+pypi_a_b/site-packages/a/b/b.txt" ),
92+ ]),
93+ _entry ("x" , "_main/src/x" , [
94+ _file ("src/x/x.txt" ),
95+ ]),
96+ _entry ("x/p" , "_main/src-dev/x/p" , [
97+ _file ("src-dev/x/p/p.txt" ),
98+ ]),
99+ _entry ("duplicate" , "+dupe_a/site-packages/duplicate" , [
100+ _file ("../+dupe_a/site-packages/duplicate/d.py" ),
101+ ]),
102+ _entry ("duplicate" , "+dupe_b/site-packages/duplicate" , [
103+ _file ("../+dupe_b/site-packages/duplicate/d.py" ),
104+ ]),
105+ # Case: two distributions provide the same file (instead of directory)
106+ _entry ("ff/fmod.py" , "+ff_a/site-packages/ff/fmod.py" , [
107+ _file ("../+ff_a/site-packages/ff/fmod.py" ),
108+ ]),
109+ _entry ("ff/fmod.py" , "+ff_b/site-packages/ff/fmod.py" , [
110+ _file ("../+ff_b/site-packages/ff/fmod.py" ),
111+ ]),
112112 ]
113113
114114 actual , conflicts = build_link_map (_ctx (), entries , return_conflicts = True )
@@ -117,6 +117,7 @@ def _test_conflict_merging_impl(env, _):
117117 "a/a.txt" : _file ("../+pypi_a/site-packages/a/a.txt" ),
118118 "a/b/b.txt" : _file ("../+pypi_a_b/site-packages/a/b/b.txt" ),
119119 "duplicate/d.py" : _file ("../+dupe_a/site-packages/duplicate/d.py" ),
120+ "ff/fmod.py" : _file ("../+ff_a/site-packages/ff/fmod.py" ),
120121 "x/p/p.txt" : _file ("src-dev/x/p/p.txt" ),
121122 "x/x.txt" : _file ("src/x/x.txt" ),
122123 }
@@ -274,8 +275,12 @@ _tests.append(_test_package_version_filtering)
274275
275276def _test_package_version_filtering_impl (env , _ ):
276277 entries = [
277- _entry ("foo" , "+pypi_v1/site-packages/foo" , ["foo.txt" ], package = "foo" , version = "1.0" ),
278- _entry ("foo" , "+pypi_v2/site-packages/foo" , ["bar.txt" ], package = "foo" , version = "2.0" ),
278+ _entry ("foo" , "+pypi_v1/site-packages/foo" , [
279+ _file ("../+pypi_v1/site-packages/foo/foo.txt" ),
280+ ], package = "foo" , version = "1.0" ),
281+ _entry ("foo" , "+pypi_v2/site-packages/foo" , [
282+ _file ("../+pypi_v2/site-packages/foo/bar.txt" ),
283+ ], package = "foo" , version = "2.0" ),
279284 ]
280285
281286 actual = build_link_map (_ctx (), entries )
@@ -300,15 +305,15 @@ def _test_malformed_entry_impl(env, _):
300305 "a" ,
301306 "+pypi_a/site-packages/a" ,
302307 # This file is outside the link_to_path, so it should be ignored.
303- ["../outside.txt" ],
308+ [_file ( "../+pypi_a/site-packages/ outside.txt" ) ],
304309 ),
305310 # A second, conflicting, entry is added to force merging of the known
306311 # files. Without this, there's no conflict, so files is never
307312 # considered.
308313 _entry (
309314 "a" ,
310315 "+pypi_b/site-packages/a" ,
311- ["../outside.txt" ],
316+ [_file ( "../+pypi_b/site-packages/ outside.txt" ) ],
312317 ),
313318 ]
314319
@@ -328,11 +333,21 @@ _tests.append(_test_complex_namespace_packages)
328333
329334def _test_complex_namespace_packages_impl (env , _ ):
330335 entries = [
331- _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , ["b.txt" ]),
332- _entry ("a/c" , "+pypi_a_c/site-packages/a/c" , ["c.txt" ]),
333- _entry ("x/y/z" , "+pypi_x_y_z/site-packages/x/y/z" , ["z.txt" ]),
334- _entry ("foo" , "+pypi_foo/site-packages/foo" , ["foo.txt" ]),
335- _entry ("foobar" , "+pypi_foobar/site-packages/foobar" , ["foobar.txt" ]),
336+ _entry ("a/b" , "+pypi_a_b/site-packages/a/b" , [
337+ _file ("../+pypi_a_b/site-packages/a/b/b.txt" ),
338+ ]),
339+ _entry ("a/c" , "+pypi_a_c/site-packages/a/c" , [
340+ _file ("../+pypi_a_c/site-packages/a/cc.txt" ),
341+ ]),
342+ _entry ("x/y/z" , "+pypi_x_y_z/site-packages/x/y/z" , [
343+ _file ("../+pypi_x_y_z/site-packages/x/y/z/z.txt" ),
344+ ]),
345+ _entry ("foo" , "+pypi_foo/site-packages/foo" , [
346+ _file ("../+pypi_foo/site-packages/foo/foo.txt" ),
347+ ]),
348+ _entry ("foobar" , "+pypi_foobar/site-packages/foobar" , [
349+ _file ("../+pypi_foobar/site-packages/foobar/foobar.txt" ),
350+ ]),
336351 ]
337352
338353 actual = build_link_map (_ctx (), entries )
@@ -380,19 +395,19 @@ def _test_multiple_venv_symlink_kinds_impl(env, _):
380395 _entry (
381396 "libfile" ,
382397 "+pypi_lib/site-packages/libfile" ,
383- [" lib.txt" ],
398+ [_file ( "../+pypi_lib/site-packages/libfile/ lib.txt") ],
384399 kind = VenvSymlinkKind .LIB ,
385400 ),
386401 _entry (
387402 "binfile" ,
388403 "+pypi_bin/bin/binfile" ,
389- [" bin.txt" ],
404+ [_file ( "../+pypi_bin/ bin/binfile/bin .txt") ],
390405 kind = VenvSymlinkKind .BIN ,
391406 ),
392407 _entry (
393408 "includefile" ,
394409 "+pypi_include/include/includefile" ,
395- [" include.h" ],
410+ [_file ( "../+pypi_include/ include/includefile/include .h") ],
396411 kind =
397412 VenvSymlinkKind .INCLUDE ,
398413 ),
0 commit comments