From f4644578e0167d1c962d3a31dd01b3108c21c394 Mon Sep 17 00:00:00 2001 From: Andrew Bradshaw Date: Thu, 5 Mar 2026 17:16:22 -0800 Subject: [PATCH] SERVER-120217 Update to using rules python (#48943) GitOrigin-RevId: 4684e8f134d1fff534747129566fed89a4f96528 --- .bazelrc | 5 + BUILD.bazel | 7 +- MODULE.bazel | 11 +- MODULE.bazel.lock | 276 +++++++++++++++++- bazel/BUILD.bazel | 1 + bazel/config/BUILD.bazel | 10 +- bazel/config/generate_config_header.bzl | 15 +- bazel/config/python_genrule.bzl | 38 +-- bazel/config/render_template.bzl | 77 +++-- bazel/coverity/BUILD.bazel | 2 + bazel/format/BUILD.bazel | 1 + bazel/format/rules_lint_format_wrapper.py | 4 + bazel/install_rules/install_rules.bzl | 4 +- bazel/install_rules/msi.bzl | 4 +- bazel/install_rules/pretty_printer_tests.bzl | 4 +- bazel/mongo_script_rules.bzl | 4 +- bazel/mongo_src_rules.bzl | 4 +- .../mongot_extension_signing_key.bzl | 8 +- bazel/platforms/BUILD.bazel | 2 + bazel/resmoke/BUILD.bazel | 1 + bazel/resmoke/resmoke.bzl | 7 +- bazel/signing.bzl | 4 +- bazel/symbol_checker/symbol_checker.bzl | 4 +- bazel/toolchains/cc/mongo_linux/BUILD.bazel | 2 + .../python/python_toolchain.BUILD.tmpl | 4 +- bazel/toolchains/python/python_toolchain.bzl | 4 +- bazel/wrapper_hook/BUILD.bazel | 2 + .../bazel_rules_mongo/codeowners/BUILD.bazel | 1 + .../engflow_auth/BUILD.bazel | 1 + .../bazel_rules_mongo/utils/BUILD.bazel | 1 + buildscripts/bazel_testbuilds/BUILD.bazel | 1 + buildscripts/ciconfig/BUILD.bazel | 1 + buildscripts/client/BUILD.bazel | 2 + buildscripts/cost_model/BUILD.bazel | 2 + buildscripts/gdb/BUILD.bazel | 2 + buildscripts/idl/BUILD.bazel | 1 + buildscripts/idl/tests/BUILD.bazel | 2 + buildscripts/libdeps/BUILD.bazel | 2 + buildscripts/linter/BUILD.bazel | 1 + buildscripts/lldb/BUILD.bazel | 2 + buildscripts/monitor_build_status/BUILD.bazel | 2 + buildscripts/patch_builds/BUILD.bazel | 1 + buildscripts/poetry_lock_check.py | 18 +- buildscripts/pyrightlint.py | 19 +- buildscripts/resmoke_proxy/BUILD.bazel | 2 + buildscripts/resmokelib/BUILD.bazel | 1 + buildscripts/resmokelib/core/BUILD.bazel | 1 + buildscripts/resmokelib/discovery/BUILD.bazel | 1 + .../resmokelib/extensions/BUILD.bazel | 2 + .../generate_fcv_constants/BUILD.bazel | 2 + .../generate_fuzz_config/BUILD.bazel | 2 + .../resmokelib/hang_analyzer/BUILD.bazel | 1 + buildscripts/resmokelib/logging/BUILD.bazel | 2 + .../resmokelib/multiversion/BUILD.bazel | 1 + .../resmokelib/powercycle/BUILD.bazel | 1 + buildscripts/resmokelib/run/BUILD.bazel | 1 + .../resmokelib/setup_multiversion/BUILD.bazel | 1 + .../resmokelib/symbolizer/BUILD.bazel | 2 + buildscripts/resmokelib/testing/BUILD.bazel | 2 + buildscripts/resmokelib/utils/BUILD.bazel | 1 + buildscripts/s3_binary/BUILD.bazel | 1 + buildscripts/smoke_tests/BUILD.bazel | 2 + buildscripts/testmatrix/BUILD.bazel | 2 + buildscripts/tests/BUILD.bazel | 1 + buildscripts/tests/burn_in/BUILD.bazel | 2 + buildscripts/tests/ciconfig/BUILD.bazel | 2 + .../tests/monitor_build_status/BUILD.bazel | 2 + buildscripts/tests/patch_builds/BUILD.bazel | 2 + .../tests/resmoke_end2end/BUILD.bazel | 2 + .../resmoke_end2end/failtestfiles/BUILD.bazel | 2 + .../resmoke_end2end/fixtures/BUILD.bazel | 2 + .../tests/resmoke_end2end/hooks/BUILD.bazel | 2 + buildscripts/tests/resmoke_proxy/BUILD.bazel | 2 + .../tests/resmoke_validation/BUILD.bazel | 1 + .../resmoke_validation/tests/BUILD.bazel | 2 + buildscripts/tests/resmokelib/BUILD.bazel | 2 + .../tests/resmokelib/core/BUILD.bazel | 2 + .../tests/resmokelib/discovery/BUILD.bazel | 2 + .../resmokelib/hang_analyzer/BUILD.bazel | 1 + .../tests/resmokelib/logging/BUILD.bazel | 2 + .../tests/resmokelib/multiversion/BUILD.bazel | 2 + .../tests/resmokelib/powercycle/BUILD.bazel | 2 + buildscripts/tests/resmokelib/run/BUILD.bazel | 2 + .../resmokelib/setup_multiversion/BUILD.bazel | 2 + .../tests/resmokelib/testing/BUILD.bazel | 2 + .../resmokelib/testing/fixtures/BUILD.bazel | 2 + .../resmokelib/testing/hooks/BUILD.bazel | 2 + .../resmokelib/testing/testcases/BUILD.bazel | 2 + .../testing/testcases/testfiles/BUILD.bazel | 2 + .../tests/resmokelib/utils/BUILD.bazel | 2 + buildscripts/tests/sbom_linter/BUILD.bazel | 2 + buildscripts/tests/timeouts/BUILD.bazel | 2 + buildscripts/tests/util/BUILD.bazel | 2 + buildscripts/timeouts/BUILD.bazel | 1 + buildscripts/tracing_profiler/BUILD.bazel | 2 + buildscripts/util/BUILD.bazel | 1 + buildscripts/yamllinters.py | 36 +-- evergreen/BUILD.bazel | 1 + evergreen/functions/BUILD.bazel | 2 + .../security_reporting_scripts/BUILD.bazel | 2 + evergreen/spawnhost/BUILD.bazel | 2 + modules_poc/BUILD.bazel | 1 + src/mongo/base/BUILD.bazel | 6 +- src/mongo/db/BUILD.bazel | 3 +- src/mongo/db/auth/BUILD.bazel | 3 +- src/mongo/db/extension/extensions/BUILD.bazel | 3 +- .../extensions/download_external_extension.py | 2 +- .../db/extension/test_examples/BUILD.bazel | 3 +- src/mongo/db/fts/BUILD.bazel | 5 +- src/mongo/db/fts/unicode/BUILD.bazel | 21 +- .../benchmark/data_generator/BUILD.bazel | 2 + .../data_generator/datagen/BUILD.bazel | 2 + .../data_generator/specs/BUILD.bazel | 2 + .../db/query/query_tester/scripts/BUILD.bazel | 2 + .../db/query/query_tester/tests/BUILD.bazel | 2 + .../query_tester/tests/scripts/BUILD.bazel | 2 + .../query_tester/tests/selfTests/BUILD.bazel | 2 + .../tests/selfTests/testlib/BUILD.bazel | 2 + .../query/stage_builder/sbe/abt/BUILD.bazel | 1 + .../db/shard_role/lock_manager/BUILD.bazel | 1 + src/mongo/scripting/mozjs/shell/BUILD.bazel | 3 +- src/mongo/shell/BUILD.bazel | 15 +- src/mongo/shell/debugger/BUILD.bazel | 6 +- .../tools/mongo_tidy_checks/tests/BUILD.bazel | 1 + .../tools/workload_simulation/BUILD.bazel | 1 + src/mongo/util/BUILD.bazel | 7 +- src/mongo/util/version/BUILD.bazel | 3 +- tools/flag_sync/BUILD.bazel | 1 + x509/generate_certificates.bzl | 4 +- 129 files changed, 618 insertions(+), 184 deletions(-) diff --git a/.bazelrc b/.bazelrc index 187e9924f94..89e2ae52ac7 100644 --- a/.bazelrc +++ b/.bazelrc @@ -590,6 +590,11 @@ common:public-release --stamp common --@rules_rust//rust/toolchain/channel=nightly common --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols=true +common --@rules_python//python/config_settings:bootstrap_impl=script +# https://github.com/bazel-contrib/rules_python/issues/2864 +common --@rules_python//python/config_settings:venvs_site_packages=no +common --@rules_python//python/config_settings:venvs_use_declare_symlink=no + # Experimental flag to collect system network usage metrics during build common --experimental_collect_system_network_usage diff --git a/BUILD.bazel b/BUILD.bazel index e5d2e9bdb10..0f31e59117e 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -5,6 +5,7 @@ load("@npm//:eslint/package_json.bzl", eslint_bin = "bin") load("@npm//:prettier/package_json.bzl", prettier = "bin") load("@poetry//:dependencies.bzl", "dependency") load("@rules_pkg//:pkg.bzl", "pkg_tar") +load("@rules_python//python:defs.bzl", "py_binary") load("//bazel:mongo_js_rules.bzl", "mongo_js_library") load("//bazel/config:render_template.bzl", "render_template") load("//bazel/install_rules:bolt.bzl", "bolt_instrument", "bolt_optimize") @@ -100,29 +101,27 @@ render_template( name = "clang_tidy_config", srcs = [ ".clang-tidy.in", - "//buildscripts:clang_tidy_config_gen.py", ], cmd = [ - "$(location //buildscripts:clang_tidy_config_gen.py)", "--input=$(location .clang-tidy.in)", "--output=$(location .clang-tidy)", ], output = ".clang-tidy", + python_file = "//buildscripts:clang_tidy_config_gen.py", ) render_template( name = "clang_tidy_config_strict", srcs = [ ".clang-tidy.in", - "//buildscripts:clang_tidy_config_gen.py", ], cmd = [ - "$(location //buildscripts:clang_tidy_config_gen.py)", "--input=$(location .clang-tidy.in)", "--output=$(location .clang-tidy.strict)", "--warnings-as-errors", ], output = ".clang-tidy.strict", + python_file = "//buildscripts:clang_tidy_config_gen.py", ) genrule( diff --git a/MODULE.bazel b/MODULE.bazel index 2499e3bf5c4..03062e606fa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -126,12 +126,7 @@ git_override( # ## We need skylib to be able to use config_setting_group in rule_poetry below ## https://github.com/bazelbuild/bazel-skylib/blob/main/docs/selects_doc.md#selectsconfig_setting_group -bazel_dep(name = "bazel_skylib", version = "1.7.1") -single_version_override( - module_name = "bazel_skylib", - version = "1.7.1", -) - +bazel_dep(name = "bazel_skylib", version = "1.9.0") bazel_dep(name = "rules_pkg", version = "1.2.0") bazel_dep(name = "abseil-cpp", version = "20250512.1", repo_name = "com_google_absl") local_path_override( @@ -189,9 +184,7 @@ local_path_override( path = "src/third_party/fuzztest/dist", ) -# This is just here because 1.5.1 has a bug in it and our current version of re2 will pull in 1.5.1 -# If re2 is ever upgraded past 2025-08-12 this can be unpinned -bazel_dep(name = "rules_python", version = "1.5.2") +bazel_dep(name = "rules_python", version = "1.8.5") bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) single_version_override( diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 7dd6bac744c..7a46b04e10e 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -34,8 +34,20 @@ "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", "https://bcr.bazel.build/modules/bazel_features/1.9.0/MODULE.bazel": "885151d58d90d8d9c811eb75e3288c11f850e1d6b481a8c9f766adee4712358b", "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.2/MODULE.bazel": "3bd40978e7a1fac911d5989e6b09d8f64921865a45822d8b09e815eaa726a651", + "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", - "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.1/MODULE.bazel": "88ade7293becda963e0e3ea33e7d54d3425127e0a326e0d17da085a5f1f03ff6", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.2/MODULE.bazel": "69ad6927098316848b34a9142bcc975e018ba27f08c4ff403f50c1b6e646ca67", + "https://bcr.bazel.build/modules/bazel_skylib/1.9.0/MODULE.bazel": "72997b29dfd95c3fa0d0c48322d05590418edef451f8db8db5509c57875fb4b7", + "https://bcr.bazel.build/modules/bazel_skylib/1.9.0/source.json": "7ad77c1e8c1b84222d9b3f3cae016a76639435744c19330b0b37c0a3c9da7dc0", "https://bcr.bazel.build/modules/brotli/1.1.0/MODULE.bazel": "3b5b90488995183419c4b5c9b063a164f6c0bc4d0d6b40550a612a5e860cc0fe", "https://bcr.bazel.build/modules/brotli/1.1.0/source.json": "098a4fd315527166e8dfe1fd1537c96a737a83764be38fc43f4da231d600f3d0", "https://bcr.bazel.build/modules/buildifier_prebuilt/6.4.0/MODULE.bazel": "37389c6b5a40c59410b4226d3bb54b08637f393d66e2fa57925c6fcf68e64bf4", @@ -125,6 +137,7 @@ "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", "https://bcr.bazel.build/modules/rules_cc/0.1.4/MODULE.bazel": "bb03a452a7527ac25a7518fb86a946ef63df860b9657d8323a0c50f8504fb0b9", + "https://bcr.bazel.build/modules/rules_cc/0.1.5/MODULE.bazel": "88dfc9361e8b5ae1008ac38f7cdfd45ad738e4fa676a3ad67d19204f045a1fd8", "https://bcr.bazel.build/modules/rules_cc/0.2.10/MODULE.bazel": "76e71013ff06010b5a6682751f85b60ee7b9fd89eec0dca97583919dd8c6f44e", "https://bcr.bazel.build/modules/rules_cc/0.2.10/source.json": "e517ec6451617032750803d6f9028e849eaf0d08878d23f9e66e8415d241b4f8", "https://bcr.bazel.build/modules/rules_cc/0.2.4/MODULE.bazel": "1ff1223dfd24f3ecf8f028446d4a27608aa43c3f41e346d22838a4223980b8cc", @@ -204,8 +217,8 @@ "https://bcr.bazel.build/modules/rules_python/1.0.0/MODULE.bazel": "898a3d999c22caa585eb062b600f88654bf92efb204fa346fb55f6f8edffca43", "https://bcr.bazel.build/modules/rules_python/1.2.0/MODULE.bazel": "5aeeb48b2a6c19d668b48adf2b8a2b209a6310c230db0ce77450f148a89846e4", "https://bcr.bazel.build/modules/rules_python/1.5.1/MODULE.bazel": "acfe65880942d44a69129d4c5c3122d57baaf3edf58ae5a6bd4edea114906bf5", - "https://bcr.bazel.build/modules/rules_python/1.5.2/MODULE.bazel": "5e4bbe842ffdb54dfb6ddd78de3d28151a4cc3417a685cee30c8fe4d1dc655a2", - "https://bcr.bazel.build/modules/rules_python/1.5.2/source.json": "687aa52b6da283ee45cb702bc292386fd9c717264c38c0277b4957eeafbe1904", + "https://bcr.bazel.build/modules/rules_python/1.8.5/MODULE.bazel": "28b2d79ed8368d7d45b34bacc220e3c0b99cbcd9392641961b849e4c3f55dd30", + "https://bcr.bazel.build/modules/rules_python/1.8.5/source.json": "e261b03c8804f2582c9536013f987e1ea105a2b38c238aa2ac8f98fc34c8b18a", "https://bcr.bazel.build/modules/rules_rust/0.68.1/MODULE.bazel": "8d3332ef4079673385eb81f8bd68b012decc04ac00c9d5a01a40eff90301732c", "https://bcr.bazel.build/modules/rules_rust/0.68.1/source.json": "3378e746f81b62457fdfd37391244fa8ff075ba85c05931ee4f3a20ac1efe963", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", @@ -237,7 +250,7 @@ "moduleExtensions": { "//bazel:bzlmod.bzl%setup_mongo_python_toolchains": { "general": { - "bzlTransitiveDigest": "idv0XYvsT1OQdB9a7uhWyDT9+BJ+bHIqCuxGgcyyLUg=", + "bzlTransitiveDigest": "haX1p8/zzNyOuJ0HhUV2PcV9W2RcHiQiqq8XfYZU1vY=", "usagesDigest": "bUxjq9n+hj2YwYT/lcSP4lHyQ2GVy5JpFgSmddUqUZg=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -994,10 +1007,261 @@ "recordedRepoMappingEntries": [] } }, + "@@rules_python~//python/extensions:config.bzl%config": { + "general": { + "bzlTransitiveDigest": "9SmjaE1bQpi4boSnT3zl6a9czyENO/gaJA8KoOYGT3A=", + "usagesDigest": "lUc0b3wUkbI1EVyzvJLtzddJg6yHYGzR3FWAr0x31KM=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "rules_python_internal": { + "bzlFile": "@@rules_python~//python/private:internal_config_repo.bzl", + "ruleClassName": "internal_config_repo", + "attributes": { + "transition_setting_generators": {}, + "transition_settings": [] + } + }, + "pypi__build": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/e2/03/f3c8ba0a6b6e30d7d18c40faab90807c9bb5e9a1e3b2fe2008af624a9c97/build-1.2.1-py3-none-any.whl", + "sha256": "75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__click": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl", + "sha256": "ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__colorama": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", + "sha256": "4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__importlib_metadata": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/2d/0a/679461c511447ffaf176567d5c496d1de27cbe34a87df6677d7171b2fbd4/importlib_metadata-7.1.0-py3-none-any.whl", + "sha256": "30962b96c0c223483ed6cc7280e7f0199feb01a0e40cfae4d4450fc6fab1f570", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__installer": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/e5/ca/1172b6638d52f2d6caa2dd262ec4c811ba59eee96d54a7701930726bce18/installer-0.7.0-py3-none-any.whl", + "sha256": "05d1933f0a5ba7d8d6296bb6d5018e7c94fa473ceb10cf198a92ccea19c27b53", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__more_itertools": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/50/e2/8e10e465ee3987bb7c9ab69efb91d867d93959095f4807db102d07995d94/more_itertools-10.2.0-py3-none-any.whl", + "sha256": "686b06abe565edfab151cb8fd385a05651e1fdf8f0a14191e4439283421f8684", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__packaging": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/49/df/1fceb2f8900f8639e278b056416d49134fb8d84c5942ffaa01ad34782422/packaging-24.0-py3-none-any.whl", + "sha256": "2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__pep517": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/25/6e/ca4a5434eb0e502210f591b97537d322546e4833dcb4d470a48c375c5540/pep517-0.13.1-py3-none-any.whl", + "sha256": "31b206f67165b3536dd577c5c3f1518e8fbaf38cbc57efff8369a392feff1721", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__pip": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/8a/6a/19e9fe04fca059ccf770861c7d5721ab4c2aebc539889e97c7977528a53b/pip-24.0-py3-none-any.whl", + "sha256": "ba0d021a166865d2265246961bec0152ff124de910c5cc39f1156ce3fa7c69dc", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__pip_tools": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/0d/dc/38f4ce065e92c66f058ea7a368a9c5de4e702272b479c0992059f7693941/pip_tools-7.4.1-py3-none-any.whl", + "sha256": "4c690e5fbae2f21e87843e89c26191f0d9454f362d8acdbd695716493ec8b3a9", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__pyproject_hooks": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/ae/f3/431b9d5fe7d14af7a32340792ef43b8a714e7726f1d7b69cc4e8e7a3f1d7/pyproject_hooks-1.1.0-py3-none-any.whl", + "sha256": "7ceeefe9aec63a1064c18d939bdc3adf2d8aa1988a510afec15151578b232aa2", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__setuptools": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/90/99/158ad0609729111163fc1f674a5a42f2605371a4cf036d0441070e2f7455/setuptools-78.1.1-py3-none-any.whl", + "sha256": "c3a9c4211ff4c309edb8b8c4f1cbfa7ae324c4ba9f91ff254e3d305b9fd54561", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__tomli": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", + "sha256": "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__wheel": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/7d/cd/d7460c9a869b16c3dd4e1e403cce337df165368c71d6af229a74699622ce/wheel-0.43.0-py3-none-any.whl", + "sha256": "55c570405f142630c6b9f72fe09d9b67cf1477fcf543ae5b8dcb1f5b7377da81", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + }, + "pypi__zipp": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "url": "https://files.pythonhosted.org/packages/da/55/a03fd7240714916507e1fcf7ae355bd9d9ed2e6db492595f1a67f61681be/zipp-3.18.2-py3-none-any.whl", + "sha256": "dce197b859eb796242b0622af1b8beb0a722d52aa2f57133ead08edd5bf5374e", + "type": "zip", + "build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n" + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_python~", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_python~", + "pypi__build", + "rules_python~~config~pypi__build" + ], + [ + "rules_python~", + "pypi__click", + "rules_python~~config~pypi__click" + ], + [ + "rules_python~", + "pypi__colorama", + "rules_python~~config~pypi__colorama" + ], + [ + "rules_python~", + "pypi__importlib_metadata", + "rules_python~~config~pypi__importlib_metadata" + ], + [ + "rules_python~", + "pypi__installer", + "rules_python~~config~pypi__installer" + ], + [ + "rules_python~", + "pypi__more_itertools", + "rules_python~~config~pypi__more_itertools" + ], + [ + "rules_python~", + "pypi__packaging", + "rules_python~~config~pypi__packaging" + ], + [ + "rules_python~", + "pypi__pep517", + "rules_python~~config~pypi__pep517" + ], + [ + "rules_python~", + "pypi__pip", + "rules_python~~config~pypi__pip" + ], + [ + "rules_python~", + "pypi__pip_tools", + "rules_python~~config~pypi__pip_tools" + ], + [ + "rules_python~", + "pypi__pyproject_hooks", + "rules_python~~config~pypi__pyproject_hooks" + ], + [ + "rules_python~", + "pypi__setuptools", + "rules_python~~config~pypi__setuptools" + ], + [ + "rules_python~", + "pypi__tomli", + "rules_python~~config~pypi__tomli" + ], + [ + "rules_python~", + "pypi__wheel", + "rules_python~~config~pypi__wheel" + ], + [ + "rules_python~", + "pypi__zipp", + "rules_python~~config~pypi__zipp" + ] + ] + } + }, "@@rules_python~//python/uv:uv.bzl%uv": { "general": { - "bzlTransitiveDigest": "mxPY/VBQrSC9LvYeRrlxD+0IkDTQ4+36NGMnGWlN/Vw=", - "usagesDigest": "+IhE0HT6ocmsX1GBdBt9hMRX4CPhV1tICoPAw2jfuJE=", + "bzlTransitiveDigest": "K6zoA/u57+d21o50BApale3BrKDIB1vWM6q455k772s=", + "usagesDigest": "WBglFllfLEiRiR3B9XpMdsZ6iL3talW/IXK9+mt2r7E=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index 126b14ae0f9..a28bc50bdef 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary") package(default_visibility = ["//visibility:public"]) diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index a9798921cd3..64d3f0d9845 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_skylib//lib:selects.bzl", "selects") +load("@rules_python//python:defs.bzl", "py_binary") load( "@bazel_skylib//rules:common_settings.bzl", "bool_flag", @@ -82,10 +83,11 @@ config_setting( ], ) -# Expose script for external usage through bazel. -exports_files([ - "generate_config_header.py", -]) +py_binary( + name = "generate_config_header", + srcs = ["generate_config_header.py"], + main = "generate_config_header.py", +) # -------------------------------------- # Compiler types diff --git a/bazel/config/generate_config_header.bzl b/bazel/config/generate_config_header.bzl index 6cc865bcbe4..1807c66dd1c 100644 --- a/bazel/config/generate_config_header.bzl +++ b/bazel/config/generate_config_header.bzl @@ -61,9 +61,6 @@ def generate_config_header_impl(ctx): "cpp_defines": " ".join(ctx.attr.cpp_defines), } - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime - generator_script = ctx.attr.generator_script.files.to_list()[0].path - additional_inputs = [] additional_inputs_depsets = [] for additional_input in ctx.attr.additional_inputs: @@ -74,18 +71,15 @@ def generate_config_header_impl(ctx): additional_inputs.append(file.path) ctx.actions.run( - executable = python.interpreter.path, + executable = ctx.executable.generator_script, outputs = [ctx.outputs.output, ctx.outputs.logfile], mnemonic = "ConfigHeaderGen", inputs = depset(transitive = [ cc_toolchain.all_files, - python.files, - ctx.attr.generator_script.files, ctx.attr.template.files, ctx.attr.checks.files, ] + additional_inputs_depsets), arguments = [ - generator_script, # bazel/config/mongo_config_header.py "--output-path", ctx.outputs.output.path, "--template-path", @@ -148,14 +142,15 @@ generate_config_header_rule = rule( ), "generator_script": attr.label( doc = "The python generator script to use.", - default = "//bazel/config:generate_config_header.py", - allow_single_file = True, + default = "//bazel/config:generate_config_header", + executable = True, + cfg = "exec", ), "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), "_sdkroot": attr.label(default = "//bazel/config:sdkroot"), }, fragments = ["cpp"], - toolchains = ["@bazel_tools//tools/cpp:toolchain_type", "@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@bazel_tools//tools/cpp:toolchain_type", "@rules_python//python:toolchain_type"], output_to_genfiles = True, ) diff --git a/bazel/config/python_genrule.bzl b/bazel/config/python_genrule.bzl index c0f8ba2efa7..d6bf90025b9 100644 --- a/bazel/config/python_genrule.bzl +++ b/bazel/config/python_genrule.bzl @@ -1,26 +1,22 @@ load("//bazel:utils.bzl", "write_target") +load("@rules_python//python:defs.bzl", "py_binary") def python_genrule_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime - python_libs = [py_dep[PyInfo].transitive_sources for py_dep in ctx.attr.python_libs] - - python_path = [] - for py_dep in ctx.attr.python_libs: - for path in py_dep[PyInfo].imports.to_list(): - if path not in python_path: - python_path.append(ctx.expand_make_variables("python_library_imports", "$(BINDIR)/external/" + path, ctx.var)) - expanded_args = [ ctx.expand_make_variables("render_template_expand", ctx.expand_location(arg, ctx.attr.srcs), ctx.var) for arg in ctx.attr.cmd ] + # Add runfiles package dir to PYTHONPATH so scripts can import python_libs (e.g. gen_helper). + runfiles_package_dir = ctx.executable.python_binary.path + ".runfiles/" + ctx.workspace_name + "/" + ctx.label.package + env = {"PYTHONPATH": runfiles_package_dir} + ctx.actions.run( - executable = python.interpreter.path, + executable = ctx.executable.python_binary, outputs = ctx.outputs.outputs, - inputs = depset(transitive = [python.files, depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])] + python_libs), + inputs = depset(transitive = [depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])]), arguments = expanded_args, - env = {"PYTHONPATH": ctx.configuration.host_path_separator.join(python_path)}, + env = env, mnemonic = "TemplateRenderer", ) @@ -40,18 +36,26 @@ python_genrule_rule = rule( "cmd": attr.string_list( doc = "The command line arguments to pass to python", ), - "python_libs": attr.label_list( - providers = [PyInfo], - default = [], + "python_binary": attr.label( + executable = True, + cfg = "exec", ), }, - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], output_to_genfiles = True, ) -def python_genrule(name, tags = [], **kwargs): +def python_genrule(name, python_file, python_libs = [], tags = [], **kwargs): + py_binary( + name = name + "_python", + srcs = [python_file], + main = python_file, + tags = tags + ["gen_source"], + deps = python_libs, + ) python_genrule_rule( name = name, tags = tags + ["gen_source"], + python_binary = name + "_python", **kwargs ) diff --git a/bazel/config/render_template.bzl b/bazel/config/render_template.bzl index b2b4f2d6e01..093fdf17171 100644 --- a/bazel/config/render_template.bzl +++ b/bazel/config/render_template.bzl @@ -1,26 +1,22 @@ load("//bazel:utils.bzl", "write_target") +load("@rules_python//python:defs.bzl", "py_binary") def render_template_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime - python_libs = [py_dep[PyInfo].transitive_sources for py_dep in ctx.attr.python_libs] - - python_path = [] - for py_dep in ctx.attr.python_libs: - for path in py_dep[PyInfo].imports.to_list(): - if path not in python_path: - python_path.append(ctx.expand_make_variables("python_library_imports", "$(BINDIR)/external/" + path, ctx.var)) - expanded_args = [ ctx.expand_make_variables("render_template_expand", ctx.expand_location(arg, ctx.attr.srcs), ctx.var) for arg in ctx.attr.cmd ] + # Add runfiles package dir to PYTHONPATH so scripts can import python_libs (e.g. gen_helper). + runfiles_package_dir = ctx.executable.python_binary.path + ".runfiles/" + ctx.workspace_name + "/" + ctx.label.package + env = {"PYTHONPATH": runfiles_package_dir} + ctx.actions.run( - executable = python.interpreter.path, + executable = ctx.executable.python_binary, outputs = [ctx.outputs.output], - inputs = depset(transitive = [python.files, depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])] + python_libs), + inputs = depset(transitive = [depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])]), arguments = expanded_args, - env = {"PYTHONPATH": ctx.configuration.host_path_separator.join(python_path)}, + env = env, mnemonic = "TemplateRenderer", ) @@ -40,43 +36,49 @@ render_template_rule = rule( "cmd": attr.string_list( doc = "The command line arguments to pass to python", ), - "python_libs": attr.label_list( - providers = [PyInfo], - default = [], + "python_binary": attr.label( + executable = True, + cfg = "exec", ), }, toolchains = ["@bazel_tools//tools/python:toolchain_type"], output_to_genfiles = True, ) -def render_template(name, tags = [], **kwargs): +def render_template(name, srcs, cmd, output, python_file, python_libs = [], tags = [], **kwargs): + py_binary( + name = name + "_python", + srcs = [python_file], + main = python_file, + tags = tags + ["gen_source"], + deps = python_libs, + ) render_template_rule( name = name, + srcs = srcs, + cmd = cmd, + output = output, + python_binary = name + "_python", tags = tags + ["gen_source"], **kwargs ) def render_templates_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime - python_libs = [py_dep[PyInfo].transitive_sources for py_dep in ctx.attr.python_libs] - - python_path = [] - for py_dep in ctx.attr.python_libs: - for path in py_dep[PyInfo].imports.to_list(): - if path not in python_path: - python_path.append(ctx.expand_make_variables("python_library_imports", "$(BINDIR)/external/" + path, ctx.var)) - expanded_args = [ ctx.expand_make_variables("render_template_expand", ctx.expand_location(arg, ctx.attr.srcs), ctx.var) for arg in ctx.attr.cmd ] + # Add runfiles package dir to PYTHONPATH so scripts can import python_libs (e.g. gen_helper). + runfiles_package_dir = ctx.executable.python_binary.path + ".runfiles/" + ctx.workspace_name + "/" + ctx.label.package + env = {"PYTHONPATH": runfiles_package_dir} + ctx.actions.run( - executable = python.interpreter.path, + executable = ctx.executable.python_binary, outputs = ctx.outputs.outputs, - inputs = depset(transitive = [python.files, depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])] + python_libs), + inputs = depset(transitive = [depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])]), arguments = expanded_args, - env = {"PYTHONPATH": ctx.configuration.host_path_separator.join(python_path)}, + env = env, mnemonic = "TemplateRenderer", ) @@ -96,18 +98,29 @@ render_templates_rule = rule( "cmd": attr.string_list( doc = "The command line arguments to pass to python", ), - "python_libs": attr.label_list( - providers = [PyInfo], - default = [], + "python_binary": attr.label( + executable = True, + cfg = "exec", ), }, toolchains = ["@bazel_tools//tools/python:toolchain_type"], output_to_genfiles = True, ) -def render_templates(name, tags = [], **kwargs): +def render_templates(name, srcs, cmd, outputs, python_file, python_libs = [], tags = [], **kwargs): + py_binary( + name = name + "_python", + srcs = [python_file], + main = python_file, + tags = tags + ["gen_source"], + deps = python_libs, + ) render_templates_rule( name = name, + srcs = srcs, + cmd = cmd, + outputs = outputs, + python_binary = name + "_python", tags = tags + ["gen_source"], **kwargs ) diff --git a/bazel/coverity/BUILD.bazel b/bazel/coverity/BUILD.bazel index 9758e98376e..65099377ee5 100644 --- a/bazel/coverity/BUILD.bazel +++ b/bazel/coverity/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "generate_coverity_targets", srcs = ["generate_coverity_targets.py"], diff --git a/bazel/format/BUILD.bazel b/bazel/format/BUILD.bazel index acdb3be79ad..a54ef1a9a15 100644 --- a/bazel/format/BUILD.bazel +++ b/bazel/format/BUILD.bazel @@ -1,5 +1,6 @@ load("@aspect_rules_lint//format:defs.bzl", "format_multirun", "format_test") load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary") py_binary( name = "rules_lint_format_wrapper", diff --git a/bazel/format/rules_lint_format_wrapper.py b/bazel/format/rules_lint_format_wrapper.py index c40acfbecb5..0deba4be1da 100644 --- a/bazel/format/rules_lint_format_wrapper.py +++ b/bazel/format/rules_lint_format_wrapper.py @@ -158,6 +158,10 @@ def main() -> int: print("python buildscripts/install_bazel.py") return 1 + # aspect_rules_js js_binary launcher expects RUNFILES and Bazel on Linux sets RUNFILES_DIR. + if "RUNFILES_DIR" in os.environ and "RUNFILES" not in os.environ: + os.environ["RUNFILES"] = os.environ["RUNFILES_DIR"] + parser = argparse.ArgumentParser( prog="Format", description="This script formats code in mongodb" ) diff --git a/bazel/install_rules/install_rules.bzl b/bazel/install_rules/install_rules.bzl index 463c4ff4f85..cd5a5df227d 100644 --- a/bazel/install_rules/install_rules.bzl +++ b/bazel/install_rules/install_rules.bzl @@ -211,7 +211,7 @@ def mongo_install_rule_impl(ctx): DefaultInfo: with dep files and output file PackageFilesInfo: with a mapping for creating the archive """ - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime file_map = { "binaries": {}, @@ -432,7 +432,7 @@ mongo_install_rule = rule( "_windows_constraint": attr.label(default = "@platforms//os:windows"), }, doc = "Install targets", - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], ) def mongo_install( diff --git a/bazel/install_rules/msi.bzl b/bazel/install_rules/msi.bzl index 75b4080e969..86ff1dc12a6 100644 --- a/bazel/install_rules/msi.bzl +++ b/bazel/install_rules/msi.bzl @@ -75,7 +75,7 @@ def mongo_msi_impl(ctx): candle_arguments.append("-out") candle_arguments.append(output_directory + "/") - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime ctx.actions.run( outputs = candle_out, inputs = depset(transitive = [depset(candle_in), ctx.attr._candle_wrapper_script.files, python.files, ctx.attr._candle.files]), @@ -165,5 +165,5 @@ mongo_msi = rule( ), }, doc = "Create a msi using wix toolset", - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], ) diff --git a/bazel/install_rules/pretty_printer_tests.bzl b/bazel/install_rules/pretty_printer_tests.bzl index 23e0a3aaaec..6ade3dafb02 100644 --- a/bazel/install_rules/pretty_printer_tests.bzl +++ b/bazel/install_rules/pretty_printer_tests.bzl @@ -23,7 +23,7 @@ def mongo_pretty_printer_test_impl(ctx): script_output = ctx.actions.declare_file(pretty_printer_directory + short_name + ".py") launcher_output = ctx.actions.declare_file(pretty_printer_directory + "pretty_printer_test_launcher_" + short_name + ".py") - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime inputs = depset(transitive = [ ctx.attr._pretty_printer_creation_script.files, @@ -71,7 +71,7 @@ mongo_pretty_printer_test = rule( "_pretty_printer_launcher_infile": attr.label(allow_single_file = True, default = "//src/mongo/util:pretty_printer_test_launcher.py.in"), }, doc = "Create pretty printer tests", - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], executable = True, test = True, ) diff --git a/bazel/mongo_script_rules.bzl b/bazel/mongo_script_rules.bzl index f4ed32b0fb7..2eb6d05d8a9 100644 --- a/bazel/mongo_script_rules.bzl +++ b/bazel/mongo_script_rules.bzl @@ -14,7 +14,7 @@ def _py_cxx_wrapper(*, python_path, toolchain_path, python_interpreter, main_py) ]) def _py_cxx_test_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime python_path = [] for dep in ctx.attr.deps: @@ -73,7 +73,7 @@ py_cxx_test = rule( "data": attr.label_list(), "toolchain_path": attr.string(mandatory = True), }, - toolchains = ["@bazel_tools//tools/cpp:toolchain_type", "@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@bazel_tools//tools/cpp:toolchain_type", "@rules_python//python:toolchain_type"], executable = True, test = True, ) diff --git a/bazel/mongo_src_rules.bzl b/bazel/mongo_src_rules.bzl index a437756fbba..889f2b6e75d 100644 --- a/bazel/mongo_src_rules.bzl +++ b/bazel/mongo_src_rules.bzl @@ -966,7 +966,7 @@ def idl_generator_impl(ctx): gen_source = ctx.actions.declare_file(base + "_gen.cpp") gen_header = ctx.actions.declare_file(base + "_gen.h") - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime dep_depsets = [dep[IdlInfo].idl_deps for dep in ctx.attr.deps] # Transitive headers from deps + explicit hdrs attr @@ -1084,7 +1084,7 @@ idl_generator_rule = rule( "gen_src": "%{name}.cpp", }, doc = "Generates header/source files from IDL files.", - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], fragments = ["py"], ) diff --git a/bazel/mongot_extension_signing_key/mongot_extension_signing_key.bzl b/bazel/mongot_extension_signing_key/mongot_extension_signing_key.bzl index 9c84376570a..cc9af2dadfa 100644 --- a/bazel/mongot_extension_signing_key/mongot_extension_signing_key.bzl +++ b/bazel/mongot_extension_signing_key/mongot_extension_signing_key.bzl @@ -19,7 +19,7 @@ def mongot_extension_signing_key(): mongot_extension_signing_key_repo(name = "mongot_extension_signing_key") def _gpg_export_armored_key_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime key = ctx.file.key armored_key_output_file = ctx.outputs.armored_key_output_file @@ -91,12 +91,12 @@ gpg_export_armored_key = rule( default = Label("@gpg//:gpg_libs"), ), }, - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], fragments = ["py"], ) def _generate_embedded_public_key_header_impl(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime script = ctx.file.script public_key_path = ctx.file.public_key_path @@ -130,6 +130,6 @@ generate_embedded_public_key_header = rule( allow_single_file = True, ), }, - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], fragments = ["py"], ) diff --git a/bazel/platforms/BUILD.bazel b/bazel/platforms/BUILD.bazel index 1a59b813f99..f76c78abedd 100644 --- a/bazel/platforms/BUILD.bazel +++ b/bazel/platforms/BUILD.bazel @@ -158,6 +158,8 @@ platform( ], ) +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "remote_execution_containers_generator", srcs = ["remote_execution_containers_generator.py"], diff --git a/bazel/resmoke/BUILD.bazel b/bazel/resmoke/BUILD.bazel index dcb8b6c3748..0c738e4aed1 100644 --- a/bazel/resmoke/BUILD.bazel +++ b/bazel/resmoke/BUILD.bazel @@ -1,5 +1,6 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "int_flag") load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") genrule( name = "resmoke_mongo_version", diff --git a/bazel/resmoke/resmoke.bzl b/bazel/resmoke/resmoke.bzl index 5d26c40282a..ae2a88854ec 100644 --- a/bazel/resmoke/resmoke.bzl +++ b/bazel/resmoke/resmoke.bzl @@ -1,4 +1,5 @@ load("//bazel:test_exec_properties.bzl", "test_exec_properties") +load("@rules_python//python:defs.bzl", "py_test") def resmoke_config_impl(ctx): base_name = ctx.label.name.removesuffix("_config") @@ -6,7 +7,7 @@ def resmoke_config_impl(ctx): generated_config_file = ctx.actions.declare_file(base_name + ".yml") base_config_file = ctx.files.base_config[0] - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime python_path = [] for path in ctx.attr.generator[PyInfo].imports.to_list(): if path not in python_path: @@ -68,7 +69,7 @@ resmoke_config = rule( ), }, doc = "Generates a resmoke config YAML", - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], ) def resmoke_suite_test( @@ -123,7 +124,7 @@ def resmoke_suite_test( deps_path = ":".join(["$(location %s)" % dep for dep in deps]) - native.py_test( + py_test( name = name, # To a user of resmoke_suite_test, the `srcs` is the list of tests to select. However, to the py_test rule, # the `srcs` are expected to be Python files only. diff --git a/bazel/signing.bzl b/bazel/signing.bzl index ae324225894..54b56debbbb 100644 --- a/bazel/signing.bzl +++ b/bazel/signing.bzl @@ -5,7 +5,7 @@ load("//bazel:mongo_src_rules.bzl", "mongo_cc_extension_shared_library") def _gpg_sign_impl(ctx): outs = [] - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime for src in ctx.files.srcs: out = ctx.actions.declare_file(src.basename + ".sig") @@ -84,7 +84,7 @@ gpg_sign = rule( default = Label("//bazel:gpg_signer.py"), ), }, - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], fragments = ["py"], ) diff --git a/bazel/symbol_checker/symbol_checker.bzl b/bazel/symbol_checker/symbol_checker.bzl index e66972bf8e5..8db7158813f 100644 --- a/bazel/symbol_checker/symbol_checker.bzl +++ b/bazel/symbol_checker/symbol_checker.bzl @@ -65,7 +65,7 @@ def symbol_checker_aspect_impl(target, ctx): OutputGroupInfo(symbol_checker = depset()), ] - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime cc_toolchain = find_cpp_toolchain(ctx) nm_bin = cc_toolchain.nm_executable @@ -154,7 +154,7 @@ symbol_checker_aspect = aspect( ), }, toolchains = [ - "@bazel_tools//tools/python:toolchain_type", + "@rules_python//python:toolchain_type", "@bazel_tools//tools/cpp:toolchain_type", ], attr_aspects = ["deps", "binary_with_debug"], diff --git a/bazel/toolchains/cc/mongo_linux/BUILD.bazel b/bazel/toolchains/cc/mongo_linux/BUILD.bazel index 359b4670069..2e3ddcba169 100644 --- a/bazel/toolchains/cc/mongo_linux/BUILD.bazel +++ b/bazel/toolchains/cc/mongo_linux/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "mongo_toolchain_version_generator", srcs = ["mongo_toolchain_version_generator.py"], diff --git a/bazel/toolchains/python/python_toolchain.BUILD.tmpl b/bazel/toolchains/python/python_toolchain.BUILD.tmpl index fa9e1a5e4d5..1fd4d31f128 100644 --- a/bazel/toolchains/python/python_toolchain.BUILD.tmpl +++ b/bazel/toolchains/python/python_toolchain.BUILD.tmpl @@ -1,4 +1,4 @@ -load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") +load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair") filegroup( name = "files", @@ -37,5 +37,5 @@ toolchain( exec_compatible_with = [{constraints}], target_compatible_with = [{constraints}], toolchain = ":py_runtime_pair", - toolchain_type = "@bazel_tools//tools/python:toolchain_type", + toolchain_type = "@rules_python//python:toolchain_type", ) \ No newline at end of file diff --git a/bazel/toolchains/python/python_toolchain.bzl b/bazel/toolchains/python/python_toolchain.bzl index 3e0892896a0..101d0907ec3 100644 --- a/bazel/toolchains/python/python_toolchain.bzl +++ b/bazel/toolchains/python/python_toolchain.bzl @@ -90,7 +90,7 @@ def _py_download(ctx): ctx.file("BUILD.bazel", """ # Stub toolchain - platform doesn't match host, not downloaded -load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") +load("@rules_python//python:defs.bzl", "py_runtime_pair") py_runtime_pair( name = "runtime_pair", @@ -100,7 +100,7 @@ py_runtime_pair( toolchain( name = "python_toolchain", - toolchain_type = "@bazel_tools//tools/python:toolchain_type", + toolchain_type = "@rules_python//python:toolchain_type", toolchain = ":runtime_pair", exec_compatible_with = [ {constraints} diff --git a/bazel/wrapper_hook/BUILD.bazel b/bazel/wrapper_hook/BUILD.bazel index 77727357004..061a32017ee 100644 --- a/bazel/wrapper_hook/BUILD.bazel +++ b/bazel/wrapper_hook/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_library") + package(default_visibility = ["//visibility:public"]) py_library( diff --git a/buildscripts/bazel_rules_mongo/codeowners/BUILD.bazel b/buildscripts/bazel_rules_mongo/codeowners/BUILD.bazel index 25ed9d497ee..f67dcd50233 100644 --- a/buildscripts/bazel_rules_mongo/codeowners/BUILD.bazel +++ b/buildscripts/bazel_rules_mongo/codeowners/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary") py_binary( name = "codeowners", diff --git a/buildscripts/bazel_rules_mongo/engflow_auth/BUILD.bazel b/buildscripts/bazel_rules_mongo/engflow_auth/BUILD.bazel index a4ebe652069..eedf99f7b57 100644 --- a/buildscripts/bazel_rules_mongo/engflow_auth/BUILD.bazel +++ b/buildscripts/bazel_rules_mongo/engflow_auth/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary") py_binary( name = "engflow_auth", diff --git a/buildscripts/bazel_rules_mongo/utils/BUILD.bazel b/buildscripts/bazel_rules_mongo/utils/BUILD.bazel index b4b84012f20..3eb4591b98d 100644 --- a/buildscripts/bazel_rules_mongo/utils/BUILD.bazel +++ b/buildscripts/bazel_rules_mongo/utils/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") exports_files(["evergreen_git.py"]) diff --git a/buildscripts/bazel_testbuilds/BUILD.bazel b/buildscripts/bazel_testbuilds/BUILD.bazel index e2cc5f1d37e..23ade080f32 100644 --- a/buildscripts/bazel_testbuilds/BUILD.bazel +++ b/buildscripts/bazel_testbuilds/BUILD.bazel @@ -2,6 +2,7 @@ load("//bazel:mongo_src_rules.bzl", "mongo_cc_binary", "mongo_cc_unit_test") load("//bazel/resmoke:resmoke.bzl", "resmoke_suite_test") +load("@rules_python//python:defs.bzl", "py_test") package(default_visibility = ["//visibility:public"]) diff --git a/buildscripts/ciconfig/BUILD.bazel b/buildscripts/ciconfig/BUILD.bazel index 7488fb682e1..b8e38f24815 100644 --- a/buildscripts/ciconfig/BUILD.bazel +++ b/buildscripts/ciconfig/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "ciconfig", diff --git a/buildscripts/client/BUILD.bazel b/buildscripts/client/BUILD.bazel index fa7edff1bc5..c19ca6f62f6 100644 --- a/buildscripts/client/BUILD.bazel +++ b/buildscripts/client/BUILD.bazel @@ -1,4 +1,6 @@ # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets +load("@rules_python//python:defs.bzl", "py_library") + py_library( name = "all_python_files", srcs = glob(["*.py"]), diff --git a/buildscripts/cost_model/BUILD.bazel b/buildscripts/cost_model/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/cost_model/BUILD.bazel +++ b/buildscripts/cost_model/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/gdb/BUILD.bazel b/buildscripts/gdb/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/gdb/BUILD.bazel +++ b/buildscripts/gdb/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/idl/BUILD.bazel b/buildscripts/idl/BUILD.bazel index 3c2d497e4e7..96d61768706 100644 --- a/buildscripts/idl/BUILD.bazel +++ b/buildscripts/idl/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") filegroup( name = "idlc", diff --git a/buildscripts/idl/tests/BUILD.bazel b/buildscripts/idl/tests/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/idl/tests/BUILD.bazel +++ b/buildscripts/idl/tests/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/libdeps/BUILD.bazel b/buildscripts/libdeps/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/libdeps/BUILD.bazel +++ b/buildscripts/libdeps/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/linter/BUILD.bazel b/buildscripts/linter/BUILD.bazel index 45917effe92..86f36729c98 100644 --- a/buildscripts/linter/BUILD.bazel +++ b/buildscripts/linter/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "linter", diff --git a/buildscripts/lldb/BUILD.bazel b/buildscripts/lldb/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/lldb/BUILD.bazel +++ b/buildscripts/lldb/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/monitor_build_status/BUILD.bazel b/buildscripts/monitor_build_status/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/monitor_build_status/BUILD.bazel +++ b/buildscripts/monitor_build_status/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/patch_builds/BUILD.bazel b/buildscripts/patch_builds/BUILD.bazel index b7ffdb94442..a81082c2cef 100644 --- a/buildscripts/patch_builds/BUILD.bazel +++ b/buildscripts/patch_builds/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "patch_builds", diff --git a/buildscripts/poetry_lock_check.py b/buildscripts/poetry_lock_check.py index 7ec1fa4d7d0..39e5c576515 100644 --- a/buildscripts/poetry_lock_check.py +++ b/buildscripts/poetry_lock_check.py @@ -6,16 +6,26 @@ Returns nonzero if poetry.lock and pyproject.toml are not synced """ import os -import subprocess +import runpy +import sys POETRY_LOCK_V200 = ( """# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand.""" ) - REPO_ROOT = os.environ.get("BUILD_WORKSPACE_DIRECTORY", ".") -# This has a great error message as part of the failure case -subprocess.run(["python", "-m", "poetry", "check", "--lock"], check=True, cwd=REPO_ROOT) +old_argv = sys.argv +old_cwd = os.getcwd() +try: + sys.argv = ["poetry", "check", "--lock"] + os.chdir(REPO_ROOT) + runpy.run_module("poetry", run_name="__main__") +except SystemExit as e: + if e.code not in (None, 0): + raise +finally: + sys.argv = old_argv + os.chdir(old_cwd) # Check if the poetry lock file was generated with poetry 2.0.0 with open(f"{REPO_ROOT}/poetry.lock", "r") as poetry_lock: diff --git a/buildscripts/pyrightlint.py b/buildscripts/pyrightlint.py index 1e488120cb5..9cbc98858d8 100755 --- a/buildscripts/pyrightlint.py +++ b/buildscripts/pyrightlint.py @@ -4,6 +4,7 @@ import argparse import logging import os +import runpy import subprocess import sys @@ -29,12 +30,18 @@ def is_interesting_file(filename: str) -> bool: def lint(paths: list[str]): """Lint specified paths (files or directories) using Pyright.""" if "BUILD_WORKSPACE_DIRECTORY" in os.environ: - subprocess.run( - ["python", "-m", "pyright", "-p", "pyproject.toml"] + paths, - env=os.environ, - check=True, - cwd=REPO_ROOT, - ) + old_argv = sys.argv + old_cwd = os.getcwd() + try: + sys.argv = ["pyright", "-p", "pyproject.toml"] + paths + os.chdir(REPO_ROOT) + runpy.run_module("pyright", run_name="__main__") + except SystemExit as e: + if e.code not in (None, 0): + raise + finally: + sys.argv = old_argv + os.chdir(old_cwd) return lint_runner = runner.LintRunner() diff --git a/buildscripts/resmoke_proxy/BUILD.bazel b/buildscripts/resmoke_proxy/BUILD.bazel index 8c4d3bbd00b..48ce6cb22c2 100644 --- a/buildscripts/resmoke_proxy/BUILD.bazel +++ b/buildscripts/resmoke_proxy/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "resmoke_proxy", srcs = [ diff --git a/buildscripts/resmokelib/BUILD.bazel b/buildscripts/resmokelib/BUILD.bazel index 6e97431a4c3..918c1eef639 100644 --- a/buildscripts/resmokelib/BUILD.bazel +++ b/buildscripts/resmokelib/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "resmokelib", diff --git a/buildscripts/resmokelib/core/BUILD.bazel b/buildscripts/resmokelib/core/BUILD.bazel index ed9af2213f2..c5f5e2bb246 100644 --- a/buildscripts/resmokelib/core/BUILD.bazel +++ b/buildscripts/resmokelib/core/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "core", diff --git a/buildscripts/resmokelib/discovery/BUILD.bazel b/buildscripts/resmokelib/discovery/BUILD.bazel index 238b1106a4a..75c80beda1f 100644 --- a/buildscripts/resmokelib/discovery/BUILD.bazel +++ b/buildscripts/resmokelib/discovery/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "discovery", diff --git a/buildscripts/resmokelib/extensions/BUILD.bazel b/buildscripts/resmokelib/extensions/BUILD.bazel index 501189a8f55..c34567777e0 100644 --- a/buildscripts/resmokelib/extensions/BUILD.bazel +++ b/buildscripts/resmokelib/extensions/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "extensions", srcs = [ diff --git a/buildscripts/resmokelib/generate_fcv_constants/BUILD.bazel b/buildscripts/resmokelib/generate_fcv_constants/BUILD.bazel index 031123e174f..05469401dbc 100644 --- a/buildscripts/resmokelib/generate_fcv_constants/BUILD.bazel +++ b/buildscripts/resmokelib/generate_fcv_constants/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "generate_fcv_constants", srcs = [ diff --git a/buildscripts/resmokelib/generate_fuzz_config/BUILD.bazel b/buildscripts/resmokelib/generate_fuzz_config/BUILD.bazel index e981cc11d95..82c9e68362f 100644 --- a/buildscripts/resmokelib/generate_fuzz_config/BUILD.bazel +++ b/buildscripts/resmokelib/generate_fuzz_config/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "generate_fuzz_config", srcs = [ diff --git a/buildscripts/resmokelib/hang_analyzer/BUILD.bazel b/buildscripts/resmokelib/hang_analyzer/BUILD.bazel index ae1858942d2..7d5740fe563 100644 --- a/buildscripts/resmokelib/hang_analyzer/BUILD.bazel +++ b/buildscripts/resmokelib/hang_analyzer/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") py_library( name = "hang_analyzer", diff --git a/buildscripts/resmokelib/logging/BUILD.bazel b/buildscripts/resmokelib/logging/BUILD.bazel index ed567ab0ced..60e2841d8be 100644 --- a/buildscripts/resmokelib/logging/BUILD.bazel +++ b/buildscripts/resmokelib/logging/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "logging", srcs = [ diff --git a/buildscripts/resmokelib/multiversion/BUILD.bazel b/buildscripts/resmokelib/multiversion/BUILD.bazel index f1763b93a40..9072c0d02f8 100644 --- a/buildscripts/resmokelib/multiversion/BUILD.bazel +++ b/buildscripts/resmokelib/multiversion/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "multiversion", diff --git a/buildscripts/resmokelib/powercycle/BUILD.bazel b/buildscripts/resmokelib/powercycle/BUILD.bazel index 294962e155f..4131d1390ff 100644 --- a/buildscripts/resmokelib/powercycle/BUILD.bazel +++ b/buildscripts/resmokelib/powercycle/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "powercycle", diff --git a/buildscripts/resmokelib/run/BUILD.bazel b/buildscripts/resmokelib/run/BUILD.bazel index d8997c86065..a08f60084f4 100644 --- a/buildscripts/resmokelib/run/BUILD.bazel +++ b/buildscripts/resmokelib/run/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "run", diff --git a/buildscripts/resmokelib/setup_multiversion/BUILD.bazel b/buildscripts/resmokelib/setup_multiversion/BUILD.bazel index 464b5b5b9d7..ac63cdb69d7 100644 --- a/buildscripts/resmokelib/setup_multiversion/BUILD.bazel +++ b/buildscripts/resmokelib/setup_multiversion/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "setup_multiversion", diff --git a/buildscripts/resmokelib/symbolizer/BUILD.bazel b/buildscripts/resmokelib/symbolizer/BUILD.bazel index 936ad7ad280..4356867159b 100644 --- a/buildscripts/resmokelib/symbolizer/BUILD.bazel +++ b/buildscripts/resmokelib/symbolizer/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "symbolizer", srcs = [ diff --git a/buildscripts/resmokelib/testing/BUILD.bazel b/buildscripts/resmokelib/testing/BUILD.bazel index fb92d95a6ff..facd1f35edc 100644 --- a/buildscripts/resmokelib/testing/BUILD.bazel +++ b/buildscripts/resmokelib/testing/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "testing", srcs = glob(["**/*.py"]), # TODO: narrow this down diff --git a/buildscripts/resmokelib/utils/BUILD.bazel b/buildscripts/resmokelib/utils/BUILD.bazel index 25004cd8f11..e23fddaa8a0 100644 --- a/buildscripts/resmokelib/utils/BUILD.bazel +++ b/buildscripts/resmokelib/utils/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "utils", diff --git a/buildscripts/s3_binary/BUILD.bazel b/buildscripts/s3_binary/BUILD.bazel index 5f6b682a9de..e740d6981e9 100644 --- a/buildscripts/s3_binary/BUILD.bazel +++ b/buildscripts/s3_binary/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") py_library( name = "hashes", diff --git a/buildscripts/smoke_tests/BUILD.bazel b/buildscripts/smoke_tests/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/smoke_tests/BUILD.bazel +++ b/buildscripts/smoke_tests/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/testmatrix/BUILD.bazel b/buildscripts/testmatrix/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/testmatrix/BUILD.bazel +++ b/buildscripts/testmatrix/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/BUILD.bazel b/buildscripts/tests/BUILD.bazel index 6556cc516ef..d65b84b28c6 100644 --- a/buildscripts/tests/BUILD.bazel +++ b/buildscripts/tests/BUILD.bazel @@ -1,5 +1,6 @@ load("@poetry//:dependencies.bzl", "dependency") load("//bazel:mongo_script_rules.bzl", "mongo_toolchain_py_cxx_test") +load("@rules_python//python:defs.bzl", "py_library") mongo_toolchain_py_cxx_test( name = "test_clang_tidy", diff --git a/buildscripts/tests/burn_in/BUILD.bazel b/buildscripts/tests/burn_in/BUILD.bazel index 1f6f82dbe7f..d676f3548a5 100644 --- a/buildscripts/tests/burn_in/BUILD.bazel +++ b/buildscripts/tests/burn_in/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + py_library( name = "all_python_files", srcs = glob(["*.py"]), diff --git a/buildscripts/tests/ciconfig/BUILD.bazel b/buildscripts/tests/ciconfig/BUILD.bazel index 38d24f5675b..ae60cee7ffa 100644 --- a/buildscripts/tests/ciconfig/BUILD.bazel +++ b/buildscripts/tests/ciconfig/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_test( name = "test_evergreen", srcs = [ diff --git a/buildscripts/tests/monitor_build_status/BUILD.bazel b/buildscripts/tests/monitor_build_status/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/monitor_build_status/BUILD.bazel +++ b/buildscripts/tests/monitor_build_status/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/patch_builds/BUILD.bazel b/buildscripts/tests/patch_builds/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/patch_builds/BUILD.bazel +++ b/buildscripts/tests/patch_builds/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_end2end/BUILD.bazel b/buildscripts/tests/resmoke_end2end/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmoke_end2end/BUILD.bazel +++ b/buildscripts/tests/resmoke_end2end/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_end2end/failtestfiles/BUILD.bazel b/buildscripts/tests/resmoke_end2end/failtestfiles/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmoke_end2end/failtestfiles/BUILD.bazel +++ b/buildscripts/tests/resmoke_end2end/failtestfiles/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_end2end/fixtures/BUILD.bazel b/buildscripts/tests/resmoke_end2end/fixtures/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmoke_end2end/fixtures/BUILD.bazel +++ b/buildscripts/tests/resmoke_end2end/fixtures/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_end2end/hooks/BUILD.bazel b/buildscripts/tests/resmoke_end2end/hooks/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmoke_end2end/hooks/BUILD.bazel +++ b/buildscripts/tests/resmoke_end2end/hooks/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_proxy/BUILD.bazel b/buildscripts/tests/resmoke_proxy/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmoke_proxy/BUILD.bazel +++ b/buildscripts/tests/resmoke_proxy/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmoke_validation/BUILD.bazel b/buildscripts/tests/resmoke_validation/BUILD.bazel index f7155ba367b..4c58736eac6 100644 --- a/buildscripts/tests/resmoke_validation/BUILD.bazel +++ b/buildscripts/tests/resmoke_validation/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_test") py_test( name = "test_suites_configurations", diff --git a/buildscripts/tests/resmoke_validation/tests/BUILD.bazel b/buildscripts/tests/resmoke_validation/tests/BUILD.bazel index 9aa6b9d9951..9a6b11007b2 100644 --- a/buildscripts/tests/resmoke_validation/tests/BUILD.bazel +++ b/buildscripts/tests/resmoke_validation/tests/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_test( name = "python_test", srcs = ["python_test.py"], diff --git a/buildscripts/tests/resmokelib/BUILD.bazel b/buildscripts/tests/resmokelib/BUILD.bazel index 10f61122a13..763d2f037e0 100644 --- a/buildscripts/tests/resmokelib/BUILD.bazel +++ b/buildscripts/tests/resmokelib/BUILD.bazel @@ -1,4 +1,6 @@ # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets +load("@rules_python//python:defs.bzl", "py_library", "py_test") + py_library( name = "all_python_files", srcs = glob(["*.py"]), diff --git a/buildscripts/tests/resmokelib/core/BUILD.bazel b/buildscripts/tests/resmokelib/core/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/core/BUILD.bazel +++ b/buildscripts/tests/resmokelib/core/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/discovery/BUILD.bazel b/buildscripts/tests/resmokelib/discovery/BUILD.bazel index 826a77194d3..4341f552f2d 100644 --- a/buildscripts/tests/resmokelib/discovery/BUILD.bazel +++ b/buildscripts/tests/resmokelib/discovery/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_test( name = "test_discovery", srcs = [ diff --git a/buildscripts/tests/resmokelib/hang_analyzer/BUILD.bazel b/buildscripts/tests/resmokelib/hang_analyzer/BUILD.bazel index b6d4ba573be..923fc676660 100644 --- a/buildscripts/tests/resmokelib/hang_analyzer/BUILD.bazel +++ b/buildscripts/tests/resmokelib/hang_analyzer/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_test( name = "test_dumper", diff --git a/buildscripts/tests/resmokelib/logging/BUILD.bazel b/buildscripts/tests/resmokelib/logging/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/logging/BUILD.bazel +++ b/buildscripts/tests/resmokelib/logging/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/multiversion/BUILD.bazel b/buildscripts/tests/resmokelib/multiversion/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/multiversion/BUILD.bazel +++ b/buildscripts/tests/resmokelib/multiversion/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/powercycle/BUILD.bazel b/buildscripts/tests/resmokelib/powercycle/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/powercycle/BUILD.bazel +++ b/buildscripts/tests/resmokelib/powercycle/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/run/BUILD.bazel b/buildscripts/tests/resmokelib/run/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/run/BUILD.bazel +++ b/buildscripts/tests/resmokelib/run/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/setup_multiversion/BUILD.bazel b/buildscripts/tests/resmokelib/setup_multiversion/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/setup_multiversion/BUILD.bazel +++ b/buildscripts/tests/resmokelib/setup_multiversion/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/testing/BUILD.bazel b/buildscripts/tests/resmokelib/testing/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/testing/BUILD.bazel +++ b/buildscripts/tests/resmokelib/testing/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/testing/fixtures/BUILD.bazel b/buildscripts/tests/resmokelib/testing/fixtures/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/testing/fixtures/BUILD.bazel +++ b/buildscripts/tests/resmokelib/testing/fixtures/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/testing/hooks/BUILD.bazel b/buildscripts/tests/resmokelib/testing/hooks/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/testing/hooks/BUILD.bazel +++ b/buildscripts/tests/resmokelib/testing/hooks/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/testing/testcases/BUILD.bazel b/buildscripts/tests/resmokelib/testing/testcases/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/testing/testcases/BUILD.bazel +++ b/buildscripts/tests/resmokelib/testing/testcases/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/resmokelib/testing/testcases/testfiles/BUILD.bazel b/buildscripts/tests/resmokelib/testing/testcases/testfiles/BUILD.bazel index daf40cead1b..59f27baa654 100644 --- a/buildscripts/tests/resmokelib/testing/testcases/testfiles/BUILD.bazel +++ b/buildscripts/tests/resmokelib/testing/testcases/testfiles/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_library( name = "all_python_files", srcs = glob(["*.py"]), diff --git a/buildscripts/tests/resmokelib/utils/BUILD.bazel b/buildscripts/tests/resmokelib/utils/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/resmokelib/utils/BUILD.bazel +++ b/buildscripts/tests/resmokelib/utils/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/sbom_linter/BUILD.bazel b/buildscripts/tests/sbom_linter/BUILD.bazel index 2f3acd8479c..02a1792f0d1 100644 --- a/buildscripts/tests/sbom_linter/BUILD.bazel +++ b/buildscripts/tests/sbom_linter/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "test_sbom", srcs = ["test_sbom.py"], diff --git a/buildscripts/tests/timeouts/BUILD.bazel b/buildscripts/tests/timeouts/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/timeouts/BUILD.bazel +++ b/buildscripts/tests/timeouts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/tests/util/BUILD.bazel b/buildscripts/tests/util/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tests/util/BUILD.bazel +++ b/buildscripts/tests/util/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/timeouts/BUILD.bazel b/buildscripts/timeouts/BUILD.bazel index 80f0e442788..c7c0b5b5f21 100644 --- a/buildscripts/timeouts/BUILD.bazel +++ b/buildscripts/timeouts/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "timeout", diff --git a/buildscripts/tracing_profiler/BUILD.bazel b/buildscripts/tracing_profiler/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/buildscripts/tracing_profiler/BUILD.bazel +++ b/buildscripts/tracing_profiler/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/buildscripts/util/BUILD.bazel b/buildscripts/util/BUILD.bazel index 461206c60a7..4eb231893ec 100644 --- a/buildscripts/util/BUILD.bazel +++ b/buildscripts/util/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_library") py_library( name = "util", diff --git a/buildscripts/yamllinters.py b/buildscripts/yamllinters.py index a856330ce20..e3c4b88fbae 100644 --- a/buildscripts/yamllinters.py +++ b/buildscripts/yamllinters.py @@ -2,6 +2,7 @@ """YAML linters wrapper script for Bazel.""" import os +import runpy import subprocess import sys @@ -13,6 +14,20 @@ def run_command(cmd, **kwargs): sys.exit(result.returncode) +def run_module(module_name, args): + old_argv = sys.argv + old_cwd = os.getcwd() + try: + sys.argv = [module_name] + args + runpy.run_module(module_name, run_name="__main__") + except SystemExit as e: + if e.code not in (None, 0): + sys.exit(e.code) + finally: + sys.argv = old_argv + os.chdir(old_cwd) + + def main(): # Change to workspace root if running under Bazel if "BUILD_WORKING_DIRECTORY" in os.environ: @@ -22,19 +37,9 @@ def main(): script_dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(os.path.join(script_dir, "..")) - # Run yamllint as a Python module - run_command( - [ - sys.executable, - "-m", - "yamllint", - "-c", - "etc/yamllint_config.yml", - "buildscripts", - "etc", - "jstests", - ], - shell=False, + run_module( + "yamllint", + ["-c", "etc/yamllint_config.yml", "buildscripts", "etc", "jstests"], ) # Evaluate evergreen configs @@ -81,10 +86,7 @@ def main(): ) # Run evergreen-lint using module invocation - run_command( - [sys.executable, "-m", "evergreen_lint", "-c", "./etc/evergreen_lint.yml", "lint"], - shell=False, - ) + run_module("evergreen_lint", ["-c", "./etc/evergreen_lint.yml", "lint"]) print("YAML linting completed successfully!") diff --git a/evergreen/BUILD.bazel b/evergreen/BUILD.bazel index df9c23b545f..08892e35c9d 100644 --- a/evergreen/BUILD.bazel +++ b/evergreen/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") package(default_visibility = ["//visibility:public"]) diff --git a/evergreen/functions/BUILD.bazel b/evergreen/functions/BUILD.bazel index e45ebbe81fd..a3a7f425552 100644 --- a/evergreen/functions/BUILD.bazel +++ b/evergreen/functions/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) sh_binary( diff --git a/evergreen/functions/security_reporting_scripts/BUILD.bazel b/evergreen/functions/security_reporting_scripts/BUILD.bazel index 9ca1bc981ff..9e7c2fc8ae5 100644 --- a/evergreen/functions/security_reporting_scripts/BUILD.bazel +++ b/evergreen/functions/security_reporting_scripts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) sh_binary( diff --git a/evergreen/spawnhost/BUILD.bazel b/evergreen/spawnhost/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/evergreen/spawnhost/BUILD.bazel +++ b/evergreen/spawnhost/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/modules_poc/BUILD.bazel b/modules_poc/BUILD.bazel index 72822ed73e0..3c263b235fb 100644 --- a/modules_poc/BUILD.bazel +++ b/modules_poc/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary") py_binary( name = "mod_scanner", diff --git a/src/mongo/base/BUILD.bazel b/src/mongo/base/BUILD.bazel index f74f0c73b38..35e77c5494b 100644 --- a/src/mongo/base/BUILD.bazel +++ b/src/mongo/base/BUILD.bazel @@ -19,15 +19,14 @@ render_template( srcs = [ "error_codes.tpl.cpp", "error_codes.yml", - "generate_error_codes.py", ], cmd = [ - "$(location generate_error_codes.py)", "$(location error_codes.yml)", "$(location error_codes.tpl.cpp)", "$(location error_codes.cpp)", ], output = "error_codes.cpp", + python_file = "generate_error_codes.py", python_libs = [ dependency( "ct3", @@ -45,15 +44,14 @@ render_template( srcs = [ "error_codes.tpl.h", "error_codes.yml", - "generate_error_codes.py", ], cmd = [ - "$(location generate_error_codes.py)", "$(location error_codes.yml)", "$(location error_codes.tpl.h)", "$(location error_codes.h)", ], output = "error_codes.h", + python_file = "generate_error_codes.py", python_libs = [ dependency( "ct3", diff --git a/src/mongo/db/BUILD.bazel b/src/mongo/db/BUILD.bazel index 394b4257aed..0ddaaecb3bf 100644 --- a/src/mongo/db/BUILD.bazel +++ b/src/mongo/db/BUILD.bazel @@ -52,11 +52,9 @@ render_template( name = "feature_flag_test_tpl", srcs = [ "feature_flag_test.idl.tpl", - "//buildscripts:cheetah_source_generator.py", "//src/mongo/util/version:releases.yml", ], cmd = [ - "$(location //buildscripts:cheetah_source_generator.py)", "-o", "$(location feature_flag_test.idl)", "$(location feature_flag_test.idl.tpl)", @@ -64,6 +62,7 @@ render_template( "$(MONGO_VERSION)", ], output = "feature_flag_test.idl", + python_file = "//buildscripts:cheetah_source_generator.py", python_libs = [ dependency( "ct3", diff --git a/src/mongo/db/auth/BUILD.bazel b/src/mongo/db/auth/BUILD.bazel index 5634e3bcf19..712a61ba272 100644 --- a/src/mongo/db/auth/BUILD.bazel +++ b/src/mongo/db/auth/BUILD.bazel @@ -361,15 +361,14 @@ render_template( srcs = [ "builtin_roles.tpl.cpp", "builtin_roles.yml", - "builtin_roles_gen.py", ], cmd = [ - "$(location builtin_roles_gen.py)", "$(location builtin_roles.yml)", "$(location builtin_roles.tpl.cpp)", "$(location builtin_roles.cpp)", ], output = "builtin_roles.cpp", + python_file = "builtin_roles_gen.py", python_libs = [ dependency( "ct3", diff --git a/src/mongo/db/extension/extensions/BUILD.bazel b/src/mongo/db/extension/extensions/BUILD.bazel index fe556f2f91e..695ebed6de0 100644 --- a/src/mongo/db/extension/extensions/BUILD.bazel +++ b/src/mongo/db/extension/extensions/BUILD.bazel @@ -10,11 +10,9 @@ package(default_visibility = ["//visibility:public"]) python_genrule( name = "download_" + extension_name + "_" + variant, srcs = [ - ":download_external_extension.py", "//etc:extensions.yml", ], cmd = [ - "$(location :download_external_extension.py)", "--extension-name", extension_name, "--conf-file", @@ -32,6 +30,7 @@ package(default_visibility = ["//visibility:public"]) extension_name + "_" + variant + ".so", extension_name + "_" + variant + ".so.sig", ], + python_file = "download_external_extension.py", python_libs = [ dependency( "pyyaml", diff --git a/src/mongo/db/extension/extensions/download_external_extension.py b/src/mongo/db/extension/extensions/download_external_extension.py index 80ad1726129..cfe088b641c 100644 --- a/src/mongo/db/extension/extensions/download_external_extension.py +++ b/src/mongo/db/extension/extensions/download_external_extension.py @@ -7,8 +7,8 @@ import sys import tarfile import requests -from retry import retry import yaml +from retry import retry def get_extension_conf(file_path, extension_name): diff --git a/src/mongo/db/extension/test_examples/BUILD.bazel b/src/mongo/db/extension/test_examples/BUILD.bazel index 9acd1d8a51c..23925c944aa 100644 --- a/src/mongo/db/extension/test_examples/BUILD.bazel +++ b/src/mongo/db/extension/test_examples/BUILD.bazel @@ -153,15 +153,14 @@ pkg_name = "//" + package_name() + "/" name = extension_name + "_conf", srcs = [ "configurations.yml", - ":gen_conf.py", ], cmd = [ - "$(location :gen_conf.py)", "$(location " + extension_name + ".conf)", "$(location configurations.yml)", extension_name, ], output = extension_name + ".conf", + python_file = ":gen_conf.py", python_libs = [ dependency( "pyyaml", diff --git a/src/mongo/db/fts/BUILD.bazel b/src/mongo/db/fts/BUILD.bazel index fb3d623b71b..75c70206a6e 100644 --- a/src/mongo/db/fts/BUILD.bazel +++ b/src/mongo/db/fts/BUILD.bazel @@ -41,18 +41,15 @@ render_template( srcs = [ "stop_words_{}.txt".format(lang) for lang in STOP_WORD_LANGUAGES - ] + [ - "generate_stop_words.py", ], cmd = [ - "$(location generate_stop_words.py)", - ] + [ "$(location stop_words_{}.txt)".format(lang) for lang in STOP_WORD_LANGUAGES ] + [ "$(location stop_words_list.cpp)", ], output = "stop_words_list.cpp", + python_file = "generate_stop_words.py", ) mongo_cc_library( diff --git a/src/mongo/db/fts/unicode/BUILD.bazel b/src/mongo/db/fts/unicode/BUILD.bazel index c0d2cd6da4d..5cb08643d7e 100644 --- a/src/mongo/db/fts/unicode/BUILD.bazel +++ b/src/mongo/db/fts/unicode/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "mongo_cc_library", "mongo_cc_unit_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") load("//bazel/config:render_template.bzl", "render_template") package(default_visibility = ["//visibility:public"]) @@ -13,46 +14,43 @@ exports_files( render_template( name = "codepoints_casefold_gen", srcs = [ - "gen_casefold_map.py", - "gen_helper.py", "//src/third_party/unicode-8.0.0:CaseFolding.txt", ], cmd = [ - "$(location gen_casefold_map.py)", "$(location //src/third_party/unicode-8.0.0:CaseFolding.txt)", "$(location codepoints_casefold.cpp)", ], output = "codepoints_casefold.cpp", + python_file = "gen_casefold_map.py", + python_libs = [":gen_helper"], ) render_template( name = "codepoints_delimiter_list_gen", srcs = [ - "gen_delimiter_list.py", - "gen_helper.py", "//src/third_party/unicode-8.0.0:PropList.txt", ], cmd = [ - "$(location gen_delimiter_list.py)", "$(location //src/third_party/unicode-8.0.0:PropList.txt)", "$(location codepoints_delimiter_list.cpp)", ], output = "codepoints_delimiter_list.cpp", + python_file = "gen_delimiter_list.py", + python_libs = [":gen_helper"], ) render_template( name = "codepoints_diacritic_list_gen", srcs = [ - "gen_diacritic_list.py", - "gen_helper.py", "//src/third_party/unicode-8.0.0:PropList.txt", ], cmd = [ - "$(location gen_diacritic_list.py)", "$(location //src/third_party/unicode-8.0.0:PropList.txt)", "$(location codepoints_diacritic_list.cpp)", ], output = "codepoints_diacritic_list.cpp", + python_file = "gen_diacritic_list.py", + python_libs = [":gen_helper"], ) mongo_cc_library( @@ -83,6 +81,11 @@ mongo_cc_unit_test( ], ) +py_library( + name = "gen_helper", + srcs = ["gen_helper.py"], +) + py_binary( name = "gen_diacritic_map", srcs = ["gen_diacritic_map.py"], diff --git a/src/mongo/db/query/benchmark/data_generator/BUILD.bazel b/src/mongo/db/query/benchmark/data_generator/BUILD.bazel index 092393c4bc0..b28af3927bb 100644 --- a/src/mongo/db/query/benchmark/data_generator/BUILD.bazel +++ b/src/mongo/db/query/benchmark/data_generator/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) py_library( diff --git a/src/mongo/db/query/benchmark/data_generator/datagen/BUILD.bazel b/src/mongo/db/query/benchmark/data_generator/datagen/BUILD.bazel index 84363c6e2cf..7b0ef19cfd5 100644 --- a/src/mongo/db/query/benchmark/data_generator/datagen/BUILD.bazel +++ b/src/mongo/db/query/benchmark/data_generator/datagen/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) py_library( diff --git a/src/mongo/db/query/benchmark/data_generator/specs/BUILD.bazel b/src/mongo/db/query/benchmark/data_generator/specs/BUILD.bazel index e3daad6f121..dfd4156a5f2 100644 --- a/src/mongo/db/query/benchmark/data_generator/specs/BUILD.bazel +++ b/src/mongo/db/query/benchmark/data_generator/specs/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) py_library( diff --git a/src/mongo/db/query/query_tester/scripts/BUILD.bazel b/src/mongo/db/query/query_tester/scripts/BUILD.bazel index d708920f051..0b6aa30aa6e 100644 --- a/src/mongo/db/query/query_tester/scripts/BUILD.bazel +++ b/src/mongo/db/query/query_tester/scripts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + package(default_visibility = ["//visibility:public"]) py_library( diff --git a/src/mongo/db/query/query_tester/tests/BUILD.bazel b/src/mongo/db/query/query_tester/tests/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/src/mongo/db/query/query_tester/tests/BUILD.bazel +++ b/src/mongo/db/query/query_tester/tests/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/src/mongo/db/query/query_tester/tests/scripts/BUILD.bazel b/src/mongo/db/query/query_tester/tests/scripts/BUILD.bazel index 8d13dd79a6d..1d8b2eb2322 100644 --- a/src/mongo/db/query/query_tester/tests/scripts/BUILD.bazel +++ b/src/mongo/db/query/query_tester/tests/scripts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + py_binary( name = "overwrite_results", srcs = [ diff --git a/src/mongo/db/query/query_tester/tests/selfTests/BUILD.bazel b/src/mongo/db/query/query_tester/tests/selfTests/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/src/mongo/db/query/query_tester/tests/selfTests/BUILD.bazel +++ b/src/mongo/db/query/query_tester/tests/selfTests/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/src/mongo/db/query/query_tester/tests/selfTests/testlib/BUILD.bazel b/src/mongo/db/query/query_tester/tests/selfTests/testlib/BUILD.bazel index fa7edff1bc5..e0d1a0e26a7 100644 --- a/src/mongo/db/query/query_tester/tests/selfTests/testlib/BUILD.bazel +++ b/src/mongo/db/query/query_tester/tests/selfTests/testlib/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/src/mongo/db/query/stage_builder/sbe/abt/BUILD.bazel b/src/mongo/db/query/stage_builder/sbe/abt/BUILD.bazel index b0708d3446b..c3b9c681dc5 100644 --- a/src/mongo/db/query/stage_builder/sbe/abt/BUILD.bazel +++ b/src/mongo/db/query/stage_builder/sbe/abt/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "mongo_cc_binary", "mongo_cc_library", "mongo_cc_unit_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") package(default_visibility = ["//visibility:public"]) diff --git a/src/mongo/db/shard_role/lock_manager/BUILD.bazel b/src/mongo/db/shard_role/lock_manager/BUILD.bazel index d16984562a8..c56670388b9 100644 --- a/src/mongo/db/shard_role/lock_manager/BUILD.bazel +++ b/src/mongo/db/shard_role/lock_manager/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") package(default_visibility = ["//visibility:public"]) diff --git a/src/mongo/scripting/mozjs/shell/BUILD.bazel b/src/mongo/scripting/mozjs/shell/BUILD.bazel index 1ec0ec23b07..2a5e66e6f2c 100644 --- a/src/mongo/scripting/mozjs/shell/BUILD.bazel +++ b/src/mongo/scripting/mozjs/shell/BUILD.bazel @@ -33,14 +33,13 @@ render_template( name = "mongohelpers_js_cpp", srcs = [ "mongohelpers.js", - "//buildscripts:jstoh.py", ], cmd = [ - "$(location //buildscripts:jstoh.py)", "$(location mongohelpers_js.cpp)", "$(location mongohelpers.js)", ], output = "mongohelpers_js.cpp", + python_file = "//buildscripts:jstoh.py", ) mongo_js_library( diff --git a/src/mongo/shell/BUILD.bazel b/src/mongo/shell/BUILD.bazel index 6326b493e53..299c86ce458 100644 --- a/src/mongo/shell/BUILD.bazel +++ b/src/mongo/shell/BUILD.bazel @@ -235,15 +235,14 @@ render_template( srcs = [ "error_codes.tpl.js", "//src/mongo/base:error_codes.yml", - "//src/mongo/base:generate_error_codes.py", ], cmd = [ - "$(location //src/mongo/base:generate_error_codes.py)", "$(location //src/mongo/base:error_codes.yml)", "$(location error_codes.tpl.js)", "$(location error_codes.js)", ], output = "error_codes.js", + python_file = "//src/mongo/base:generate_error_codes.py", python_libs = [ dependency( "ct3", @@ -294,17 +293,15 @@ MONGOJS_CPP_JSFILES = [ # into the native binary via bytecode upon startup. render_template( name = "mongojs_cpp", - srcs = [ - "//buildscripts:jstoh.py", - ] + MONGOJS_CPP_JSFILES, + srcs = MONGOJS_CPP_JSFILES, cmd = [ - "$(location //buildscripts:jstoh.py)", "$(location mongojs.cpp)", ] + [ "$(location {})".format(file) for file in MONGOJS_CPP_JSFILES ], output = "mongojs.cpp", + python_file = "//buildscripts:jstoh.py", ) MONGO_SERVER_CPP_JS_FILES = [ @@ -323,17 +320,15 @@ MONGO_SERVER_CPP_JS_FILES = [ render_template( name = "mongo_server_cpp", - srcs = [ - "//buildscripts:jstoh.py", - ] + MONGO_SERVER_CPP_JS_FILES, + srcs = MONGO_SERVER_CPP_JS_FILES, cmd = [ - "$(location //buildscripts:jstoh.py)", "$(location mongo-server.cpp)", ] + [ "$(location {})".format(file) for file in MONGO_SERVER_CPP_JS_FILES ], output = "mongo-server.cpp", + python_file = "//buildscripts:jstoh.py", ) mongo_cc_library( diff --git a/src/mongo/shell/debugger/BUILD.bazel b/src/mongo/shell/debugger/BUILD.bazel index 761ace02757..d0864ad6c94 100644 --- a/src/mongo/shell/debugger/BUILD.bazel +++ b/src/mongo/shell/debugger/BUILD.bazel @@ -50,17 +50,15 @@ JSFILES_TO_PRECOMPILE = [ render_template( name = "render_js_compiled_code", - srcs = [ - "//buildscripts:jstoh.py", - ] + JSFILES_TO_PRECOMPILE, + srcs = JSFILES_TO_PRECOMPILE, cmd = [ "$(location {})".format(file) for file in [ - "//buildscripts:jstoh.py", "js_compiled_code.cpp", ] + JSFILES_TO_PRECOMPILE ], output = "js_compiled_code.cpp", + python_file = "//buildscripts:jstoh.py", ) mongo_cc_library( diff --git a/src/mongo/tools/mongo_tidy_checks/tests/BUILD.bazel b/src/mongo/tools/mongo_tidy_checks/tests/BUILD.bazel index cebb0764b78..17dac99b9b4 100644 --- a/src/mongo/tools/mongo_tidy_checks/tests/BUILD.bazel +++ b/src/mongo/tools/mongo_tidy_checks/tests/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "mongo_cc_binary", "mongo_cc_library") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") package(default_visibility = ["//visibility:public"]) diff --git a/src/mongo/tools/workload_simulation/BUILD.bazel b/src/mongo/tools/workload_simulation/BUILD.bazel index 61c004aae91..3a85b06defd 100644 --- a/src/mongo/tools/workload_simulation/BUILD.bazel +++ b/src/mongo/tools/workload_simulation/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") package(default_visibility = ["//visibility:public"]) diff --git a/src/mongo/util/BUILD.bazel b/src/mongo/util/BUILD.bazel index fe386baf0d5..2314a44ec2e 100644 --- a/src/mongo/util/BUILD.bazel +++ b/src/mongo/util/BUILD.bazel @@ -1,4 +1,5 @@ load("//bazel:mongo_src_rules.bzl", "TCMALLOC_DEPS", "idl_generator", "mongo_cc_benchmark", "mongo_cc_binary", "mongo_cc_library", "mongo_cc_unit_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") load("//bazel/config:generate_config_header.bzl", "generate_config_header") load("//bazel/config:render_template.bzl", "render_template") load("//bazel/toolchains/cc:mongo_compiler_flags.bzl", "MONGO_GLOBAL_COPTS", "MONGO_GLOBAL_LINKFLAGS") @@ -206,14 +207,11 @@ mongo_cc_library( render_template( name = "icu_init_cpp", - srcs = [ - "generate_icu_init_cpp.py", - ] + select({ + srcs = select({ "@platforms//cpu:s390x": ["//src/third_party/icu4c-57.1/source:mongo_sources/icudt57b.dat"], "//conditions:default": ["//src/third_party/icu4c-57.1/source:mongo_sources/icudt57l.dat"], }), cmd = [ - "$(location generate_icu_init_cpp.py)", "-o", "$(location icu_init.cpp)", "-i", @@ -222,6 +220,7 @@ render_template( "//conditions:default": ["$(location //src/third_party/icu4c-57.1/source:mongo_sources/icudt57l.dat)"], }), output = "icu_init.cpp", + python_file = "generate_icu_init_cpp.py", ) # When using ICU from third_party, icu_init.cpp will load a subset of diff --git a/src/mongo/util/version/BUILD.bazel b/src/mongo/util/version/BUILD.bazel index 90989fa31ee..8e66bdae095 100644 --- a/src/mongo/util/version/BUILD.bazel +++ b/src/mongo/util/version/BUILD.bazel @@ -8,10 +8,8 @@ render_template( srcs = [ "releases.tpl.h", "releases.yml", - "//buildscripts:cheetah_source_generator.py", ], cmd = [ - "$(location //buildscripts:cheetah_source_generator.py)", "-o", "$(location releases.h)", "$(location releases.tpl.h)", @@ -19,6 +17,7 @@ render_template( "$(MONGO_VERSION)", ], output = "releases.h", + python_file = "//buildscripts:cheetah_source_generator.py", python_libs = [ dependency( "ct3", diff --git a/tools/flag_sync/BUILD.bazel b/tools/flag_sync/BUILD.bazel index f0badca26ed..1edb8c86735 100644 --- a/tools/flag_sync/BUILD.bazel +++ b/tools/flag_sync/BUILD.bazel @@ -1,4 +1,5 @@ load("@poetry//:dependencies.bzl", "dependency") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") py_binary( name = "client", diff --git a/x509/generate_certificates.bzl b/x509/generate_certificates.bzl index df19377a54b..08f63677f66 100644 --- a/x509/generate_certificates.bzl +++ b/x509/generate_certificates.bzl @@ -2,7 +2,7 @@ load("@poetry//:dependencies.bzl", "dependency") load("//bazel/config:render_template.bzl", "render_template") def _generate_certificates(ctx): - python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime + python = ctx.toolchains["@rules_python//python:toolchain_type"].py3_runtime python_libs = [py_dep[PyInfo].transitive_sources for py_dep in ctx.attr.py_libs] python_path = [] @@ -107,5 +107,5 @@ generate_certificates = rule( ], ), }, - toolchains = ["@bazel_tools//tools/python:toolchain_type"], + toolchains = ["@rules_python//python:toolchain_type"], )