diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3c3f7fa..1df4b19 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -91,6 +91,9 @@ jobs: - name: Run Tests run: | bazel test //... + - name: Run Tests (WORKSPACE.bazel) + run: | + bazel test //... --noenable_bzlmod - name: Perform compilation run: | bazel run //3rdparty:requirements_compiler "--" --upgrade diff --git a/.gitignore b/.gitignore index 27c1a3b..2efc21d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dist /bazel-* user.bazelrc /.github/ci.bazelrc +/private/examples/multiplatform_py_test/bazel-* diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 743ad21..c7019a4 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -1 +1,32 @@ -# Use MODULE.bazel instead. +workspace(name = "rules_req_compile") + +load("//:repositories.bzl", "req_compile_dependencies") + +req_compile_dependencies() + +load("//:repositories_transitive.bzl", "req_compile_transitive_dependencies") + +req_compile_transitive_dependencies() + +load("@rules_python//python:repositories.bzl", "python_register_toolchains") + +python_register_toolchains( + name = "python311", + python_version = "3.11", +) + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +load("//private/tests:test_repositories_1.bzl", "test_dependencies_1") + +test_dependencies_1() + +load("//private/tests:test_repositories_2.bzl", "test_dependencies_2") + +test_dependencies_2() + +load("//private/tests:test_repositories_3.bzl", "test_dependencies_3") + +test_dependencies_3() diff --git a/private/tests/annotations/annotations_test_deps.bzl b/private/tests/annotations/annotations_test_deps.bzl new file mode 100644 index 0000000..ba08126 --- /dev/null +++ b/private/tests/annotations/annotations_test_deps.bzl @@ -0,0 +1,78 @@ +"""Test dependencies for the annotations integration test""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load( + "//:defs.bzl", + "py_requirements_repository", + package_annotation = "py_package_annotation", +) + +_NUMPY_LIBRARY_TARGET = """\ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_req_compile//:defs.bzl", "py_package_annotation_target") + +_INCLUDE_DIR = "site-packages/numpy/core/include" + +cc_library( + name = "headers", + hdrs = glob(["{}/**/*.h".format(_INCLUDE_DIR)]), + includes = [_INCLUDE_DIR], +) + +py_package_annotation_target( + name = "pkg.headers", + target = ":headers", +) +""" + +def req_compile_test_annotations_deps(): + maybe( + py_requirements_repository, + name = "req_compile_test_annotations", + requirements_locks = { + Label("//private/tests/annotations:requirements.linux.txt"): "@platforms//os:linux", + Label("//private/tests/annotations:requirements.macos.txt"): "@platforms//os:macos", + Label("//private/tests/annotations:requirements.windows.txt"): "@platforms//os:windows", + }, + annotations = { + "numpy": package_annotation( + additive_build_file_content = _NUMPY_LIBRARY_TARGET, + data = [":pkg.headers"], + copy_srcs = { + "site-packages/numpy/conftest.py": "site-packages/numpy/conftest.copy.py", + }, + copy_files = { + "site-packages/numpy-1.26.4.dist-info/entry_points.txt": "site-packages/numpy-1.26.4.dist-info/entry_points.copy.txt", + }, + copy_executables = { + "site-packages/numpy/testing/setup.py": "site-packages/numpy/testing/setup.copy.py", + }, + patches = [ + Label("//private/tests/annotations:numpy.patch"), + ], + deps = [ + # Show that label dependencies can be added. + Label("@rules_python//python/runfiles"), + ], + ), + # Sphinx is known to have a circular dependency. The annotations here solve for that. + "sphinxcontrib-applehelp": package_annotation( + deps = ["-sphinx"], + ), + "sphinxcontrib-devhelp": package_annotation( + deps = ["-sphinx"], + ), + "sphinxcontrib-htmlhelp": package_annotation( + deps = ["-sphinx"], + ), + "sphinxcontrib-jsmath": package_annotation( + deps_excludes = ["sphinx"], + ), + "sphinxcontrib-qthelp": package_annotation( + deps_excludes = ["sphinx"], + ), + "sphinxcontrib-serializinghtml": package_annotation( + deps_excludes = ["sphinx"], + ), + }, + ) diff --git a/private/tests/pip_parse_compat/pip_parse_compat_test_deps.bzl b/private/tests/pip_parse_compat/pip_parse_compat_test_deps.bzl new file mode 100644 index 0000000..8b7e5e8 --- /dev/null +++ b/private/tests/pip_parse_compat/pip_parse_compat_test_deps.bzl @@ -0,0 +1,21 @@ +"""Test dependencies for `pip_parse` compatibility tests""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("//:defs.bzl", "py_requirements_repository") + +def pip_parse_compat_test_deps(): + maybe( + py_requirements_repository, + name = "req_compile_test_pip_parse_compat_single_plat", + requirements_lock = Label("//private/tests/pip_parse_compat:requirements.txt"), + ) + + maybe( + py_requirements_repository, + name = "req_compile_test_pip_parse_compat_multi_plat", + requirements_locks = { + Label("//private/tests/pip_parse_compat:requirements.linux.txt"): "@platforms//os:linux", + Label("//private/tests/pip_parse_compat:requirements.macos.txt"): "@platforms//os:macos", + Label("//private/tests/pip_parse_compat:requirements.windows.txt"): "@platforms//os:windows", + }, + ) diff --git a/private/tests/pip_parse_compat/pip_parse_compat_test_deps_install.bzl b/private/tests/pip_parse_compat/pip_parse_compat_test_deps_install.bzl new file mode 100644 index 0000000..36b0082 --- /dev/null +++ b/private/tests/pip_parse_compat/pip_parse_compat_test_deps_install.bzl @@ -0,0 +1,14 @@ +"""Test dependencies for `pip_parse` compatibility tests""" + +load( + "@req_compile_test_pip_parse_compat_multi_plat//:requirements.bzl", + pip_parse_compat_multi_plat_repositories = "install_deps", +) +load( + "@req_compile_test_pip_parse_compat_single_plat//:requirements.bzl", + pip_parse_compat_single_plat_repositories = "install_deps", +) + +def pip_parse_compat_test_deps_install(): + pip_parse_compat_multi_plat_repositories() + pip_parse_compat_single_plat_repositories() diff --git a/private/tests/test_repositories_1.bzl b/private/tests/test_repositories_1.bzl new file mode 100644 index 0000000..c7223ec --- /dev/null +++ b/private/tests/test_repositories_1.bzl @@ -0,0 +1,56 @@ +"""req-compile Bazel integration test dependencies""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@python311//:defs.bzl", "interpreter") +load("//:defs.bzl", "py_requirements_repository") +load("//private/tests/annotations:annotations_test_deps.bzl", "req_compile_test_annotations_deps") +load("//private/tests/find_links:find_links_test_repo.bzl", "find_links_test_repository") +load("//private/tests/pip_parse_compat:pip_parse_compat_test_deps.bzl", "pip_parse_compat_test_deps") + +def test_dependencies_1(): + """req-compile Bazel integration test dependencies""" + + maybe( + py_requirements_repository, + name = "req_compile_test_sdist", + # Required to compile sdists + interpreter = interpreter, + requirements_lock = Label("//private/tests/sdist:requirements.txt"), + ) + + maybe( + py_requirements_repository, + name = "req_compile_test_simple", + requirements_lock = Label("//private/tests/simple:requirements.txt"), + ) + + maybe( + py_requirements_repository, + name = "req_compile_test_platlib", + requirements_locks = { + Label("//private/tests/platlib:requirements.linux.txt"): "@platforms//os:linux", + Label("//private/tests/platlib:requirements.macos.txt"): "@platforms//os:macos", + Label("//private/tests/platlib:requirements.windows.txt"): "@platforms//os:windows", + }, + ) + + maybe( + py_requirements_repository, + name = "req_compile_test_transitive_ins", + requirements_lock = Label("//private/tests/transitive_ins:requirements.txt"), + ) + + maybe( + find_links_test_repository, + name = "req_compile_find_links_test", + pyspark_wheel_data = Label("@req_compile_test_sdist__pyspark__sdist//:whl.json"), + build_file = Label("//private/tests/find_links:BUILD.find_links.bazel"), + # Needs to match `--find-links` in `//private/tests/find_links:requirements.in` + wheeldir = "wheeldir", + requirements_in = Label("//private/tests/find_links:requirements.in"), + requirements_txt = Label("//private/tests/find_links:requirements.txt"), + ) + + pip_parse_compat_test_deps() + + req_compile_test_annotations_deps() diff --git a/private/tests/test_repositories_2.bzl b/private/tests/test_repositories_2.bzl new file mode 100644 index 0000000..171b639 --- /dev/null +++ b/private/tests/test_repositories_2.bzl @@ -0,0 +1,29 @@ +"""req-compile Bazel integration test transitive dependencies""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@req_compile_test_annotations//:defs.bzl", annotations_repositories = "repositories") +load("@req_compile_test_platlib//:defs.bzl", platlib_repositories = "repositories") +load("@req_compile_test_sdist//:defs.bzl", sdist_repositories = "repositories") +load("@req_compile_test_simple//:defs.bzl", simple_repositories = "repositories") +load("@req_compile_test_transitive_ins//:defs.bzl", transitive_ins_repositories = "repositories") +load("//:defs.bzl", "py_requirements_repository") +load( + "//private/tests/pip_parse_compat:pip_parse_compat_test_deps_install.bzl", + "pip_parse_compat_test_deps_install", +) + +def test_dependencies_2(): + """req-compile Bazel integration test transitive dependencies""" + + annotations_repositories() + pip_parse_compat_test_deps_install() + platlib_repositories() + sdist_repositories() + simple_repositories() + transitive_ins_repositories() + + maybe( + py_requirements_repository, + name = "req_compile_test_find_links", + requirements_lock = Label("@req_compile_find_links_test//:requirements.txt"), + ) diff --git a/private/tests/test_repositories_3.bzl b/private/tests/test_repositories_3.bzl new file mode 100644 index 0000000..e486f41 --- /dev/null +++ b/private/tests/test_repositories_3.bzl @@ -0,0 +1,7 @@ +"""req-compile Bazel integration test transitive dependencies""" + +load("@req_compile_test_find_links//:defs.bzl", find_links_repositories = "repositories") + +def test_dependencies_3(): + """req-compile Bazel integration test transitive dependencies""" + find_links_repositories()