Skip to content

Commit c1abbeb

Browse files
committed
start cleanup
1 parent cdd6105 commit c1abbeb

File tree

7 files changed

+12
-80
lines changed

7 files changed

+12
-80
lines changed

python/private/common.bzl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -369,29 +369,6 @@ def collect_runfiles(ctx, files = depset()):
369369
collect_default = True,
370370
)
371371

372-
def _third_party_first(targets):
373-
"""Sort targets to allow for deterministic depset merging.
374-
375-
First return the third party deps so that the depsets get merged in a way to allow
376-
traversal so that the first dependency that is met during traversing will be a third party
377-
dep.
378-
379-
This is because the DAG is going from first-party deps to third-party deps and usually
380-
no third-party deps include first-party deps.
381-
"""
382-
383-
# this ensures that within the 2 groups of packages the order is maintained
384-
pypi_targets = []
385-
nonpypi_targets = []
386-
387-
for target in targets:
388-
if PyInfo in target and target[PyInfo].package:
389-
pypi_targets.append(target)
390-
else:
391-
nonpypi_targets.append(target)
392-
393-
return pypi_targets + nonpypi_targets
394-
395372
def create_py_info(
396373
ctx,
397374
*,
@@ -401,7 +378,6 @@ def create_py_info(
401378
implicit_pyc_files,
402379
implicit_pyc_source_files,
403380
imports,
404-
package = None,
405381
venv_symlinks = []):
406382
"""Create PyInfo provider.
407383
@@ -420,7 +396,6 @@ def create_py_info(
420396
implicit_pyc_files: {type}`depset[File]` Implicitly generated pyc files
421397
that a binary can choose to include.
422398
imports: depset of strings; the import path values to propagate.
423-
package: TODO
424399
venv_symlinks: {type}`list[VenvSymlinkEntry]` instances for
425400
symlinks to create in the consuming binary's venv.
426401
@@ -442,9 +417,8 @@ def create_py_info(
442417
py_info.imports.add(imports)
443418
py_info.merge_has_py2_only_sources(ctx.attr.srcs_version in ("PY2", "PY2ONLY"))
444419
py_info.merge_has_py3_only_sources(ctx.attr.srcs_version in ("PY3", "PY3ONLY"))
445-
py_info.set_package(package)
446420

447-
for target in _third_party_first(ctx.attr.deps):
421+
for target in ctx.attr.deps:
448422
# PyInfo may not be present e.g. cc_library rules.
449423
if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target):
450424
py_info.merge(_get_py_info(target))
@@ -456,7 +430,7 @@ def create_py_info(
456430
if f.extension == "py":
457431
py_info.transitive_sources.add(f)
458432
py_info.merge_uses_shared_libraries(cc_helper.is_valid_shared_library_artifact(f))
459-
for target in _third_party_first(ctx.attr.pyi_deps):
433+
for target in ctx.attr.pyi_deps:
460434
# PyInfo may not be present e.g. cc_library rules.
461435
if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target):
462436
py_info.merge(_get_py_info(target))

python/private/py_executable.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,10 @@ def _build_link_map(entries):
687687
kind_map = link_map.setdefault(entry.kind, {})
688688

689689
if version_by_pkg.setdefault(entry.package, entry.version) != entry.version:
690-
# We ignore duplicates by design. The dependency closer to the
691-
# binary gets precedence due to how we merge the third_party dependencies
692-
# first.
690+
# We ignore duplicates by design.
693691
continue
694692
elif entry.venv_path in kind_map:
695-
# NOTE @aignas 2025-06-05: This branch should be hit only for first party
696-
# packages, maybe we should error here?
693+
# We ignore duplicates by design.
697694
continue
698695
else:
699696
kind_map[entry.venv_path] = entry.link_to_path

python/private/py_info.bzl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def _PyInfo_init(
107107
has_py2_only_sources = False,
108108
has_py3_only_sources = False,
109109
direct_pyc_files = depset(),
110-
package = None,
111110
transitive_pyc_files = depset(),
112111
transitive_implicit_pyc_files = depset(),
113112
transitive_implicit_pyc_source_files = depset(),
@@ -143,7 +142,6 @@ def _PyInfo_init(
143142
"has_py2_only_sources": has_py2_only_sources,
144143
"has_py3_only_sources": has_py2_only_sources,
145144
"imports": imports,
146-
"package": package,
147145
"transitive_implicit_pyc_files": transitive_implicit_pyc_files,
148146
"transitive_implicit_pyc_source_files": transitive_implicit_pyc_source_files,
149147
"transitive_original_sources": transitive_original_sources,
@@ -219,15 +217,6 @@ A depset of import path strings to be added to the `PYTHONPATH` of executable
219217
Python targets. These are accumulated from the transitive `deps`.
220218
The order of the depset is not guaranteed and may be changed in the future. It
221219
is recommended to use `default` order (the default).
222-
""",
223-
"package": """
224-
:type: str
225-
226-
The source third-party dependency name, which is normalized to PEP440 schema with
227-
`-` replaced with `_`.
228-
229-
::::{versionadded} VERSION_NEXT_FEATURE
230-
::::
231220
""",
232221
"transitive_implicit_pyc_files": """
233222
:type: depset[File]
@@ -402,7 +391,6 @@ def _PyInfoBuilder_new():
402391
_has_py2_only_sources = [False],
403392
_has_py3_only_sources = [False],
404393
_uses_shared_libraries = [False],
405-
_package = [None],
406394
build = lambda *a, **k: _PyInfoBuilder_build(self, *a, **k),
407395
build_builtin_py_info = lambda *a, **k: _PyInfoBuilder_build_builtin_py_info(self, *a, **k),
408396
direct_original_sources = builders.DepsetBuilder(),
@@ -422,7 +410,6 @@ def _PyInfoBuilder_new():
422410
set_has_py2_only_sources = lambda *a, **k: _PyInfoBuilder_set_has_py2_only_sources(self, *a, **k),
423411
set_has_py3_only_sources = lambda *a, **k: _PyInfoBuilder_set_has_py3_only_sources(self, *a, **k),
424412
set_uses_shared_libraries = lambda *a, **k: _PyInfoBuilder_set_uses_shared_libraries(self, *a, **k),
425-
set_package = lambda *a, **k: _PyInfoBuilder_set_package(self, *a, **k),
426413
transitive_implicit_pyc_files = builders.DepsetBuilder(),
427414
transitive_implicit_pyc_source_files = builders.DepsetBuilder(),
428415
transitive_original_sources = builders.DepsetBuilder(),
@@ -547,19 +534,6 @@ def _PyInfoBuilder_set_uses_shared_libraries(self, value):
547534
self._uses_shared_libraries[0] = value
548535
return self
549536

550-
def _PyInfoBuilder_set_package(self, value):
551-
"""Sets `uses_shared_libraries` to `value`.
552-
553-
Args:
554-
self: implicitly added.
555-
value: {type}`str` The value to set.
556-
557-
Returns:
558-
{type}`PyInfoBuilder` self
559-
"""
560-
self._package[0] = value
561-
return self
562-
563537
def _PyInfoBuilder_merge(self, *infos, direct = []):
564538
"""Merge other PyInfos into this PyInfo.
565539
@@ -662,7 +636,6 @@ def _PyInfoBuilder_build(self):
662636
direct_original_sources = self.direct_original_sources.build(),
663637
direct_pyc_files = self.direct_pyc_files.build(),
664638
direct_pyi_files = self.direct_pyi_files.build(),
665-
package = self._package[0],
666639
transitive_implicit_pyc_files = self.transitive_implicit_pyc_files.build(),
667640
transitive_implicit_pyc_source_files = self.transitive_implicit_pyc_source_files.build(),
668641
transitive_original_sources = self.transitive_original_sources.build(),
@@ -723,5 +696,4 @@ PyInfoBuilder = struct(
723696
set_has_py2_only_sources = _PyInfoBuilder_set_has_py2_only_sources,
724697
set_has_py3_only_sources = _PyInfoBuilder_set_has_py3_only_sources,
725698
set_uses_shared_libraries = _PyInfoBuilder_set_uses_shared_libraries,
726-
set_package = _PyInfoBuilder_set_package,
727699
)

python/private/py_library.bzl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ under the binary's venv site-packages directory that should be made available (i
8686
namespace packages](
8787
https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages).
8888
However, the *content* of the files cannot be taken into account, merely their
89-
presence or absense. Stated another way: [pkgutil-style namespace packages](
89+
presence or absence. Stated another way: [pkgutil-style namespace packages](
9090
https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages)
9191
won't be understood as namespace packages; they'll be seen as regular packages. This will
9292
likely lead to conflicts with other targets that contribute to the namespace.
@@ -100,9 +100,9 @@ more information.
100100
:::{versionadded} 1.4.0
101101
:::
102102
:::{versionchanged} VERSION_NEXT_FEATURE
103-
The topological order has been reverted and instead we merge the depsets for all of the
104-
targets in the {attr}`py_library.deps` in a particular way - first merging depsets
105-
of the third-party PyPI dependencies and then merging the first-party dependencies.
103+
The topological order has been removed and if 2 different versions of the same PyPI
104+
package are observed, the behaviour has no guarantees except that it is deterministic
105+
and that only one package version will be included.
106106
:::
107107
""",
108108
),
@@ -174,7 +174,6 @@ def py_library_impl(ctx, *, semantics):
174174
required_pyc_files = required_pyc_files,
175175
implicit_pyc_files = implicit_pyc_files,
176176
implicit_pyc_source_files = implicit_pyc_source_files,
177-
package = package,
178177
imports = imports,
179178
venv_symlinks = venv_symlinks,
180179
)

tests/modules/other/simple_v1/site-packages/simple_v1_extras/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/modules/other/simple_v1/site-packages/simple_v1_extras/data.txt

Whitespace-only changes.

tests/venv_site_packages_libs/bin.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ def test_imported_from_venv(self):
2929
self.assert_imported_from_venv("single_file")
3030
self.assert_imported_from_venv("simple")
3131

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-
4132
def test_data_is_included(self):
4233
self.assert_imported_from_venv("simple")
4334
module = importlib.import_module("simple")
@@ -47,13 +38,13 @@ def test_data_is_included(self):
4738

4839
# Ensure that packages from simple v1 are not present
4940
files = [p.name for p in site_packages.glob("*")]
50-
self.assertIn("simple.libs", files)
41+
self.assertIn("simple_v1_extras", files)
5142

5243
def test_override_pkg(self):
5344
self.assert_imported_from_venv("simple")
5445
module = importlib.import_module("simple")
5546
self.assertEqual(
56-
"2.0.0",
47+
"1.0.0",
5748
module.__version__,
5849
)
5950

@@ -65,13 +56,13 @@ def test_dirs_from_replaced_package_are_not_present(self):
6556
site_packages = module_path.parent.parent
6657
dist_info_dirs = [p.name for p in site_packages.glob("*.dist-info")]
6758
self.assertEqual(
68-
["simple-2.0.0.dist-info"],
59+
["simple-1.0.0.dist-info"],
6960
dist_info_dirs,
7061
)
7162

7263
# Ensure that packages from simple v1 are not present
7364
files = [p.name for p in site_packages.glob("*")]
74-
self.assertNotIn("simple_v1_extras", files)
65+
self.assertNotIn("simple.libs", files)
7566

7667
def test_data_from_another_pkg_is_included_via_copy_file(self):
7768
self.assert_imported_from_venv("simple")

0 commit comments

Comments
 (0)