Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to identify backends not part of the pants distribution. #20548

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions build-support/bin/check_orphaned_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import annotations

import json
import subprocess
from typing import cast

NOT_DISTRIBUTED_BACKENDS = {
"internal_plugins.releases",
"internal_plugins.test_lockfile_fixtures",
"pants_explorer.server",
}


def main() -> None:
discovered_backends = get_backends()
distributed_backends = get_pants_binary_plugins()
orphaned_backends = discovered_backends - distributed_backends
if orphaned_backends:
print(
"These are discovered backends, which are not included in the pantsbuild.pants distribution:\n * "
+ "\n * ".join(
f" ({be} - intentionally excluded)" if be in NOT_DISTRIBUTED_BACKENDS else be
for be in sorted(orphaned_backends)
)
)


def get_pants_binary_plugins() -> set[str]:
return {
plugin_path_to_backend(plugin)
for plugin in run_pants("peek", "src/python/pants/bin:plugins")[0]["dependencies_raw"]
}


def plugin_path_to_backend(plugin: str) -> str:
return plugin.replace("src/python/", "").replace("/", ".")


def get_backends() -> set[str]:
return set(get_help_info()["name_to_backend_help_info"])


def get_help_info() -> dict:
return run_pants("help-all")


def run_pants(*args: str) -> dict:
return cast(
"dict",
json.loads(
subprocess.run(
["pants", *args],
stdout=subprocess.PIPE,
check=True,
).stdout.decode()
),
)


if __name__ == "__main__":
main()
Loading