diff --git a/.bazelrc b/.bazelrc index 4e6f2fa187..c4a5b54d7b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -4,8 +4,8 @@ # (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it) # To update these lines, execute # `bazel run @rules_bazel_integration_test//tools:update_deleted_packages` -build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma -query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma +build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/platform_specific_deps,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma +query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/platform_specific_deps,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma test --test_output=errors diff --git a/examples/platform_specific_deps/.gitignore b/examples/platform_specific_deps/.gitignore new file mode 100644 index 0000000000..ac51a054d2 --- /dev/null +++ b/examples/platform_specific_deps/.gitignore @@ -0,0 +1 @@ +bazel-* diff --git a/examples/platform_specific_deps/BUILD.bazel b/examples/platform_specific_deps/BUILD.bazel new file mode 100644 index 0000000000..fc5ac9db88 --- /dev/null +++ b/examples/platform_specific_deps/BUILD.bazel @@ -0,0 +1,27 @@ +load("@pip//:requirements.bzl", "requirement") +load("@rules_python//python:defs.bzl", "py_test") +load("@rules_uv//uv:pip.bzl", "pip_compile") + +pip_compile( + name = "generate_requirements", + extra_args = [ + "--universal", + "--no-generate-hashes", # Just to reduce noise + ], + py3_runtime = "@python_3_9//:py3_runtime", + requirements_in = "requirements.in", + requirements_txt = "requirements.txt", +) + +py_test( + name = "test", + srcs = [ + "pytest_main.py", + "test_load.py", + ], + main = "pytest_main.py", + deps = [ + requirement("pytest"), + requirement("pytest-xdist"), + ], +) diff --git a/examples/platform_specific_deps/MODULE.bazel b/examples/platform_specific_deps/MODULE.bazel new file mode 100644 index 0000000000..1a5b264b49 --- /dev/null +++ b/examples/platform_specific_deps/MODULE.bazel @@ -0,0 +1,33 @@ +module( + name = "platform_specific_deps", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_python", version = "0.0.0") + +# TODO: Replace with builtin uv support if it supports platform specific requirements output +bazel_dep(name = "rules_uv", version = "0.65.0") + +local_path_override( + module_name = "rules_python", + path = "../..", +) + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + python_version = "3.11", +) +python.toolchain( + python_version = "3.9", +) +use_repo(python, "python_3_9") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "pip", + python_version = "3.11", + requirements_lock = "requirements.txt", +) +use_repo(pip, "pip") diff --git a/examples/platform_specific_deps/pytest_main.py b/examples/platform_specific_deps/pytest_main.py new file mode 100644 index 0000000000..ccfac5430a --- /dev/null +++ b/examples/platform_specific_deps/pytest_main.py @@ -0,0 +1,5 @@ +import sys +import pytest + +if __name__ == "__main__": + sys.exit(pytest.main(sys.argv[1:])) diff --git a/examples/platform_specific_deps/requirements.in b/examples/platform_specific_deps/requirements.in new file mode 100644 index 0000000000..9cda381d0c --- /dev/null +++ b/examples/platform_specific_deps/requirements.in @@ -0,0 +1,2 @@ +pytest +pytest-xdist diff --git a/examples/platform_specific_deps/requirements.txt b/examples/platform_specific_deps/requirements.txt new file mode 100644 index 0000000000..de79f8cb97 --- /dev/null +++ b/examples/platform_specific_deps/requirements.txt @@ -0,0 +1,24 @@ +# This file was autogenerated by uv via the following command: +# bazel run @@//:generate_requirements +--index-url https://pypi.org/simple + +colorama==0.4.6 ; sys_platform == 'win32' + # via pytest +exceptiongroup==1.2.2 ; python_full_version < '3.11' + # via pytest +execnet==2.1.1 + # via pytest-xdist +iniconfig==2.1.0 + # via pytest +packaging==25.0 + # via pytest +pluggy==1.5.0 + # via pytest +pytest==8.3.5 + # via + # -r requirements.in + # pytest-xdist +pytest-xdist==3.6.1 + # via -r requirements.in +tomli==2.2.1 ; python_full_version < '3.11' + # via pytest diff --git a/examples/platform_specific_deps/test_load.py b/examples/platform_specific_deps/test_load.py new file mode 100644 index 0000000000..418f0245d8 --- /dev/null +++ b/examples/platform_specific_deps/test_load.py @@ -0,0 +1,5 @@ +import pytest + +def test_something(): + print("worked") + assert True