load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@rules_cc//cc:cc_import.bzl", "cc_import") load("@rules_cc//cc:cc_test.bzl", "cc_test") load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("//python:pip.bzl", "whl_filegroup") load("//python:py_binary.bzl", "py_binary") load("//python:py_library.bzl", "py_library") load("//python:py_test.bzl", "py_test") load("//python/private/pypi:py_sdist_wheel.bzl", "py_sdist_wheel") # buildifier: disable=bzl-visibility load( "//python/private/pypi:py_wheel_extract_files.bzl", "py_wheel_extract_files", "wheel_glob", ) # buildifier: disable=bzl-visibility load("//python/private/pypi:py_wheel_headers.bzl", "py_wheel_headers") # buildifier: disable=bzl-visibility load("//python/private/pypi:py_wheel_library.bzl", "py_wheel_library") # buildifier: disable=bzl-visibility load("//python/private/pypi:py_wheel_transform.bzl", "py_wheel_transform") # buildifier: disable=bzl-visibility load("//tests/pypi/py_wheel_library/spoke_pkg:wheel_files.bzl", spoke_wheel_glob = "wheel_glob") load("//tests/support:py_reconfig.bzl", "py_reconfig_test") load(":py_wheel_library_bzl_tests.bzl", "py_wheel_library_bzl_test_suite") py_test( name = "wheel_layout_and_installer_test", srcs = ["wheel_layout_and_installer_test.py"], deps = ["//python/private/pypi:wheel_installer_lib"], ) py_wheel_library_bzl_test_suite( name = "py_wheel_library_bzl_tests", ) py_binary( name = "make_test_wheel", srcs = ["make_test_wheel.py"], main = "make_test_wheel.py", ) genrule( name = "gen_demo_whl", outs = ["demo_pkg-1.2.3-py3-none-any.whl"], cmd = "$(execpath :make_test_wheel) $@", tools = [":make_test_wheel"], visibility = ["//visibility:public"], ) sh_binary( name = "sh_transform", srcs = ["sh_transform.sh"], ) py_binary( name = "transform_wheel", srcs = ["transform_wheel.py"], main = "transform_wheel.py", ) py_wheel_transform( name = "step1_transformed_demo_whl", env = {"EXPECTED_SH_ENV": "from_transform"}, transform = ":sh_transform", wheel = ":gen_demo_whl", ) py_wheel_transform( name = "transformed_demo_whl", data = ["marker.txt"], env = {"DATA_MARKER_FILE": "$(execpath marker.txt)"}, transform = ":transform_wheel", wheel = ":step1_transformed_demo_whl", ) _DEMO_EXTRACTED_FILES = [ "site-packages/bad_top_mod.py", "site-packages/demo_pkg-1.2.3.dist-info/METADATA", "site-packages/demo_pkg/__init__.py", "site-packages/demo_pkg/include/demo_header.h", "site-packages/demo_pkg/lib/libdemo.so", ] py_wheel_library( name = "demo_wheel_lib", extracted_files = _DEMO_EXTRACTED_FILES, post_install_patch_strip = 1, post_install_patches = ["post_install.patch"], wheel = ":transformed_demo_whl", ) py_wheel_library( name = "demo_wheel_lib_venv", experimental_venvs_site_packages = "//python/config_settings:venvs_site_packages", extracted_files = _DEMO_EXTRACTED_FILES, post_install_patch_strip = 1, post_install_patches = ["post_install.patch"], tags = [ "pypi_name=demo-pkg", "pypi_version=1.2.3", ], wheel = ":transformed_demo_whl", ) py_wheel_headers( name = "demo_headers", include_dirs = ["site-packages/demo_pkg/include"], wheel_library = ":demo_wheel_lib", ) py_wheel_headers( name = "demo_headers_root_default", wheel_library = ":demo_wheel_lib", ) py_wheel_extract_files( name = "extracted_patched_init", paths = ["site-packages/demo_pkg/__init__.py"], wheel_library = ":demo_wheel_lib", ) copy_file( name = "copied_patched_init_copy", src = ":extracted_patched_init", out = "copied_patched_init.py", ) py_wheel_extract_files( name = "extracted_exec_script", is_executable = True, paths = ["site-packages/demo_pkg/__init__.py"], wheel_library = ":demo_wheel_lib", ) copy_file( name = "copied_exec_script_copy", src = ":extracted_exec_script", out = "copied_exec_script.py", is_executable = True, ) py_wheel_extract_files( name = "extracted_fg_files", paths = [ "site-packages/demo_pkg/__init__.py", "site-packages/demo_pkg/include/demo_header.h", ], wheel_library = ":demo_wheel_lib", ) _LIBDEMO_MATCHES = wheel_glob( [ "site-packages/demo_pkg/lib/libdemo.so", "site-packages/demo_pkg/lib/libdemo.dylib", ], files = _DEMO_EXTRACTED_FILES, wheel_library = ":demo_wheel_lib", ) cc_import( name = "demo_shared_lib", shared_library = _LIBDEMO_MATCHES[0] if len(_LIBDEMO_MATCHES) == 1 else fail("Expected 1 match"), ) # Second wheel_glob call in the same package with overlapping match (libdemo.so) # to verify package-level de-duplication across calls. _OVERLAPPING_GLOB_MATCHES = wheel_glob( [ "site-packages/demo_pkg/lib/libdemo.*", "site-packages/demo_pkg/include/*.h", ], files = _DEMO_EXTRACTED_FILES, wheel_library = ":demo_wheel_lib", ) # Cross-package wheel_files.bzl call using default wheel_library = Label("//...:_wheel_install"). _CROSS_PKG_METADATA = spoke_wheel_glob([ "site-packages/demo_pkg-1.2.3.dist-info/METADATA", ]) filegroup( name = "custom_extracted_fg", srcs = [":extracted_fg_files"] + _OVERLAPPING_GLOB_MATCHES + _CROSS_PKG_METADATA, ) cc_test( name = "headers_test", srcs = ["headers_test.cc"], data = [":demo_shared_lib"], deps = [ ":demo_headers", ":demo_headers_root_default", ], ) py_binary( name = "make_test_sdist", srcs = ["make_test_sdist.py"], main = "make_test_sdist.py", ) genrule( name = "gen_demo_sdist", outs = ["sdist_demo-main.tar.gz"], cmd = "$(execpath :make_test_sdist) $@", tools = [":make_test_sdist"], ) string_flag( name = "always_venvs_site_packages", build_setting_default = "yes", values = [ "yes", "no", ], ) py_library( name = "classic_bdep", srcs = ["classic_bdep/site-packages/classic_bdep/__init__.py"], data = ["classic_bdep/site-packages/classic_bdep-1.0.dist-info/METADATA"], experimental_venvs_site_packages = ":always_venvs_site_packages", imports = ["classic_bdep/site-packages"], tags = [ "pypi_name=classic_bdep", "pypi_version=1.0", ], ) py_library( name = "custom_build_helper", srcs = ["custom_build_helper/helper_mod.py"], data = ["custom_build_helper/helper_data.txt"], imports = ["custom_build_helper"], ) py_library( name = "custom_shadow_dep", srcs = ["custom_shadow_dep/packaging/__init__.py"], imports = ["custom_shadow_dep"], ) py_sdist_wheel( name = "sdist_demo-0.5.0.whldir", build_deps = [ ":classic_bdep", ":custom_build_helper", ":custom_shadow_dep", ":demo_wheel_lib_venv", ], config_settings_list = { "--global-option": [ "--quiet", "--verbose", ], }, distribution = "sdist-demo", pre_build_patch_strips = [1], pre_build_patches = ["pre_build.patch"], sdist = ":gen_demo_sdist", version = "0.5.0", ) # Verify two bare-named py_sdist_wheel targets building the same sdist in one # package do not collide on declared output filenames. py_sdist_wheel( name = "sdist_demo_bare_a", build_deps = [ ":classic_bdep", ":custom_build_helper", ":custom_shadow_dep", ":demo_wheel_lib", ], distribution = "sdist-demo", pre_build_patch_strips = [1], pre_build_patches = ["pre_build.patch"], sdist = ":gen_demo_sdist", version = "0.5.0", ) py_sdist_wheel( name = "sdist_demo_bare_b", build_deps = [ ":classic_bdep", ":custom_build_helper", ":custom_shadow_dep", ":demo_wheel_lib", ], distribution = "sdist-demo", pre_build_patch_strips = [1], pre_build_patches = ["pre_build.patch"], sdist = ":gen_demo_sdist", version = "0.5.0", ) filegroup( name = "sdist_demo_whldir_fg", srcs = [":sdist_demo-0.5.0.whldir"], output_group = "whldir", ) whl_filegroup( name = "sdist_demo_whl_fg", pattern = "sdist_demo/__init__.py", runfiles = True, whl = ":sdist_demo-0.5.0.whldir", ) py_wheel_transform( name = "transformed_sdist_demo_whl", env = {"EXPECTED_SH_ENV": "from_transform"}, transform = ":sh_transform", wheel = ":sdist_demo-0.5.0.whldir", ) py_wheel_library( name = "sdist_demo_wheel_lib", site_paths = ["sdist_demo"], wheel = ":transformed_sdist_demo_whl", ) py_wheel_library( name = "sdist_demo_wheel_lib_venv", experimental_venvs_site_packages = "//python/config_settings:venvs_site_packages", site_paths = ["sdist_demo"], wheel = ":sdist_demo-0.5.0.whldir", ) genrule( name = "gen_cext_sdist", outs = ["sdist_cext-0.1.0.tar.gz"], cmd = "$(execpath :make_test_sdist) --c-ext $@", tools = [":make_test_sdist"], ) py_sdist_wheel( name = "sdist_cext_a.whldir", sdist = ":gen_cext_sdist", target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), ) filegroup( name = "sdist_cext_a_whldir_fg", srcs = [":sdist_cext_a.whldir"], output_group = "whldir", ) py_sdist_wheel( name = "sdist_cext_b.whldir", sdist = ":gen_cext_sdist", target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), ) filegroup( name = "sdist_cext_b_whldir_fg", srcs = [":sdist_cext_b.whldir"], output_group = "whldir", ) py_wheel_library( name = "sdist_cext_wheel_lib", site_paths = [ "cext_demo", "sdist_cext", ], target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), wheel = ":sdist_cext_a.whldir", ) py_test( name = "sdist_cext_test", srcs = ["sdist_cext_test.py"], data = [ ":sdist_cext_a.whldir", ":sdist_cext_a_whldir_fg", ":sdist_cext_b.whldir", ":sdist_cext_b_whldir_fg", ], target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), deps = [ ":sdist_cext_wheel_lib", "//python/runfiles", ], ) py_test( name = "sdist_wheel_builder_test", srcs = [ "make_test_sdist.py", "sdist_wheel_builder_test.py", ], data = [ ":sdist_demo-0.5.0.whldir", ":sdist_demo_bare_a", ":sdist_demo_bare_b", ":sdist_demo_whl_fg", ":sdist_demo_whldir_fg", ], main = "sdist_wheel_builder_test.py", deps = [ "//python/private/pypi:sdist_wheel_builder_lib", "//python/runfiles", ], ) py_test( name = "py_wheel_library_test", srcs = ["py_wheel_library_test.py"], data = [ "copied_exec_script.py", "copied_patched_init.py", ":custom_extracted_fg", ], env = { "COPIED_EXEC_SCRIPT": "$(rootpath copied_exec_script.py)", "COPIED_PATCHED_INIT": "$(rootpath copied_patched_init.py)", "EXPECT_PRECOMPILE": "0", }, deps = [ ":demo_wheel_lib", ":sdist_demo_wheel_lib", ], ) py_reconfig_test( name = "py_wheel_library_venv_test", srcs = ["py_wheel_library_test.py"], bootstrap_impl = "script", data = [ "copied_exec_script.py", "copied_patched_init.py", ":custom_extracted_fg", ], env = { "COPIED_EXEC_SCRIPT": "$(rootpath copied_exec_script.py)", "COPIED_PATCHED_INIT": "$(rootpath copied_patched_init.py)", "EXPECT_PRECOMPILE": "0", "EXPECT_VENV_SITE_PACKAGES": "1", }, main = "py_wheel_library_test.py", venvs_site_packages = "yes", deps = [ ":demo_wheel_lib_venv", ":sdist_demo_wheel_lib_venv", ], ) py_reconfig_test( name = "py_wheel_library_precompile_enabled_test", srcs = ["py_wheel_library_test.py"], data = [ "copied_exec_script.py", "copied_patched_init.py", ":custom_extracted_fg", ], env = { "COPIED_EXEC_SCRIPT": "$(rootpath copied_exec_script.py)", "COPIED_PATCHED_INIT": "$(rootpath copied_patched_init.py)", "EXPECT_PRECOMPILE": "1", }, main = "py_wheel_library_test.py", precompile_flag = "enabled", deps = [ ":demo_wheel_lib", ":sdist_demo_wheel_lib", ], ) py_reconfig_test( name = "py_wheel_library_venv_precompile_test", srcs = ["py_wheel_library_test.py"], bootstrap_impl = "script", data = [ "copied_exec_script.py", "copied_patched_init.py", ":custom_extracted_fg", ], env = { "COPIED_EXEC_SCRIPT": "$(rootpath copied_exec_script.py)", "COPIED_PATCHED_INIT": "$(rootpath copied_patched_init.py)", "EXPECT_PRECOMPILE": "1", "EXPECT_VENV_SITE_PACKAGES": "1", }, main = "py_wheel_library_test.py", precompile_flag = "enabled", venvs_site_packages = "yes", deps = [ ":demo_wheel_lib_venv", ":sdist_demo_wheel_lib_venv", ], ) py_wheel_library( name = "demo_wheel_lib_inner_nopc", experimental_venvs_site_packages = "//python/config_settings:venvs_site_packages", extracted_files = _DEMO_EXTRACTED_FILES, precompile = "disabled", tags = [ "pypi_name=demo-pkg", "pypi_version=1.2.3", ], wheel = ":transformed_demo_whl", ) py_wheel_library( name = "demo_wheel_lib_reuse_omit", experimental_venvs_site_packages = "//python/config_settings:venvs_site_packages", extracted_files = _DEMO_EXTRACTED_FILES, precompile_source_retention = "omit_source", tags = [ "pypi_name=demo-pkg", "pypi_version=1.2.3", ], wheel = ":demo_wheel_lib_inner_nopc", ) py_wheel_extract_files( name = "extracted_from_omit_source", paths = ["site-packages/demo_pkg/__init__.py"], wheel_library = ":demo_wheel_lib_reuse_omit", ) py_reconfig_test( name = "py_wheel_library_venv_reuse_omit_test", srcs = ["py_wheel_library_test.py"], bootstrap_impl = "script", data = [ "copied_exec_script.py", "copied_patched_init.py", ":custom_extracted_fg", ":extracted_from_omit_source", ], env = { "COPIED_EXEC_SCRIPT": "$(rootpath copied_exec_script.py)", "COPIED_PATCHED_INIT": "$(rootpath copied_patched_init.py)", "EXPECT_OMIT_SOURCE": "1", "EXPECT_VENV_SITE_PACKAGES": "1", }, main = "py_wheel_library_test.py", precompile_flag = "enabled", venvs_site_packages = "yes", deps = [ ":demo_wheel_lib_reuse_omit", ":sdist_demo_wheel_lib_venv", ], ) py_test( name = "inspect_sdist_test", srcs = ["inspect_sdist_test.py"], data = [":gen_demo_sdist"], deps = [ "//python/private/pypi:wheel_installer_lib", "//python/runfiles", ], )